Module: RSpec::Matchers

Defined in:
lib/rspec-collection/all_be.rb

Defined Under Namespace

Modules: AllBe Classes: AllBeOperatorMatcher

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Handle all_be_XXX predicates. If it doesn’t match the all_be_XXX pattern, delegate to the existing method missing handler.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rspec-collection/all_be.rb', line 95

def method_missing(sym, *args, &block)
  if sym.to_s =~ /^all_be_(\w+)$/
    pred = $1
    pred_method = "#{pred}?"
    pred_string = AllBe.format_predicate(pred, *args)
    AllBe.make_matcher(pred_string) { |element|
      element.send(pred_method, *args, &block)
    }
  else
    method_missing_without_all_be(sym, *args, &block)
  end
end

Instance Method Details

#all_be(matcher = nil, &block) ⇒ Object

Return a matcher appropriate for matching across elements of a collection.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rspec-collection/all_be.rb', line 110

def all_be(matcher=nil, &block)
  if matcher
    AllBe.make_matcher("pass") { |element, messages|
      if matcher.matches?(element)
        true
      else
        messages << matcher.failure_message_for_should
        false
      end
    }
  elsif block_given?
    AllBe.make_matcher("satisfy the block", &block)
  else
    AllBeOperatorMatcher.new
  end
end

#method_missing_without_all_beObject



90
# File 'lib/rspec-collection/all_be.rb', line 90

alias method_missing_without_all_be method_missing