Module: Spec::Example::BeforeAndAfterHooks
- Defined in:
- lib/spec-i18n/example/before_and_after_hooks.rb
Instance Method Summary collapse
-
#after_parts(scope) ⇒ Object
OverWriting a methor for rspec to work with hooks parameters.
-
#before_parts(scope) ⇒ Object
OverWriting a methor for rspec to work with hooks parameters.
-
#grep_language_and_scope(scope) ⇒ Object
Grep the tranlated scope.
-
#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
Translate hooks(before and after) keywords.
Instance Method Details
#after_parts(scope) ⇒ Object
OverWriting a methor for rspec to work with hooks parameters
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 28 def after_parts(scope) scope = grep_language_and_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
OverWriting a methor for rspec to work with hooks parameters
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 15 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
Grep the tranlated scope
pt:
hooks:
each: cada
grep_language_and_scope(:cada) # => :each
grep_language_and_scope(:each) # => :each
48 49 50 51 52 53 54 55 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 48 def grep_language_and_scope(scope) if SpecI18n.spec_language hooks = natural_language.hooks_params_keywords scope = grep_the_scope(scope, hooks) else scope 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
grep_the_scope(:cada, { ‘each’ => [ ‘cada’ ] }) # => :each
63 64 65 66 67 68 69 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 63 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
Translate hooks(before and after) keywords
7 8 9 10 11 |
# File 'lib/spec-i18n/example/before_and_after_hooks.rb', line 7 def register_hooks natural_language.before_and_after_keywords.each do |key, values| values.collect { |value| alias_method value, key } end end |