Sha256: 40dda899e244d738dd021beac3d8f674fa62994dc1c7a190eb2db2c5975c6bc3

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Spec
  module Matchers
    
    # 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
    
    # 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' 
      sym.to_s.gsub(/#{be_word}/, 'be').to_sym
    end
    alias :to_english :be_to_english
  
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-i18n-1.2.1 lib/spec-i18n/matchers/method_missing.rb
rspec-i18n-1.2.0 lib/spec-i18n/matchers/method_missing.rb