lib/spec-i18n/matchers/method_missing.rb in rspec-i18n-1.1.0 vs lib/spec-i18n/matchers/method_missing.rb in rspec-i18n-1.2.0
- old
+ new
@@ -1,25 +1,41 @@
module Spec
module Matchers
- def method_missing(sym, *args, &block) # :nodoc:
-
- begin
- language = SpecI18n.natural_language
- be_word = language.keywords['matchers']['be']
- sym = be_to_english(sym, be_word)
- end
-
- return Matchers::BePredicate.new(sym, *args, &block) if sym.to_s =~ /^be_/
- return Matchers::Has.new(sym, *args, &block) if sym.to_s =~ /^have_/
-
- super
+
+ # Method Missing that returns Predicate for the respective sym word
+ # Search the translate be word in the languages.yml for the rspec-i18n try
+ # to comunicate with the Rspec
+ #
+ def method_missing(sym, *args, &block) # :nodoc:\
+ matchers = natural_language.keywords['matchers']
+ be_word = matchers['be'] if matchers
+ sym = be_to_english(sym, be_word)
+ return Matchers::BePredicate.new(sym, *args, &block) if be_predicate?(sym)
+ return Matchers::Has.new(sym, *args, &block) if have_predicate?(sym)
end
- # :ser_matcher == :be_matcher
- # :be_true == :be_true
+ # Return something true(equivalent) for Be Predicate
+ #
+ def be_predicate?(sym)
+ sym.to_s =~ /^be_/
+ end
+
+ # Return something true(equivalent) for Have predicate
+ #
+ def have_predicate?(sym)
+ sym.to_s =~ /^have_/
+ end
+
+ # Transform the word in be for rspec work properly
+ #
+ # be_to_english(:ser_feliz, :ser) # => :be_feliz
+ # be_to_english(:estar_incluso, :estar) # => :be_incluso
+ # be_to_english(:ser_feliz, 'ser|estar') # => :be_feliz
+ #
def be_to_english(sym, be_word)
- be_word = be_word || 'be'
-
+ be_word = be_word || 'be'
sym.to_s.gsub(/#{be_word}/, 'be').to_sym
end
- end
+ alias :to_english :be_to_english
+
+ end
end