Module: Spec::Example::BeforeAndAfterHooks
- Defined in:
- lib/spec-i18n/example/before_and_after_hooks.rb
Instance Method Summary collapse
- #after_parts(scope) ⇒ Object
- #before_parts(scope) ⇒ Object
- #grep_language_and_scope(scope) ⇒ Object
-
#grep_the_scope(scope, hooks) ⇒ Object
Receive a String Scope and return the scope in english for the rspec run the right method.
- #register_hooks ⇒ Object
Instance Method Details
#after_parts(scope) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 25 def after_parts(scope) scope = grep_language_and_scope(scope) || scope case scope when :each; after_each_parts when :all; after_all_parts when :suite; after_suite_parts end end |
#before_parts(scope) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 14 def before_parts(scope) scope = grep_language_and_scope(scope) || scope case scope when :each; before_each_parts when :all; before_all_parts when :suite; before_suite_parts end end |
#grep_language_and_scope(scope) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 36 def grep_language_and_scope(scope) if SpecI18n.spec_language language = SpecI18n.natural_language scope = grep_the_scope(scope, language.hooks_params_keywords) end end |
#grep_the_scope(scope, hooks) ⇒ Object
Receive a String Scope and return the scope in english for the rspec run the right method
45 46 47 48 49 50 51 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 45 def grep_the_scope(scope, hooks) scopes = [:each, :all, :suite] return scope if scopes.include?(scope) hooks.each do |scope_in_english, language_hooks| return scope_in_english.to_sym if language_hooks.include?(scope.to_s) end end |
#register_hooks ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 5 def register_hooks language = SpecI18n.natural_language language.before_and_after_keywords.each do |key, values| values.map do |value| alias_method value, key end end end |