Class: BeComputedByMatcher
- Defined in:
- lib/extensions/mspec/mspec/matchers/be_computed_by.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(sym, *args) ⇒ BeComputedByMatcher
constructor
A new instance of BeComputedByMatcher.
- #matches?(array) ⇒ Boolean
- #method_call ⇒ Object
Constructor Details
#initialize(sym, *args) ⇒ BeComputedByMatcher
Returns a new instance of BeComputedByMatcher.
2 3 4 5 |
# File 'lib/extensions/mspec/mspec/matchers/be_computed_by.rb', line 2 def initialize(sym, *args) @method = sym @args = args end |
Instance Method Details
#failure_message ⇒ Object
27 28 29 |
# File 'lib/extensions/mspec/mspec/matchers/be_computed_by.rb', line 27 def ["Expected #{@value.inspect}", "to be computed by #{method_call}"] end |
#matches?(array) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/extensions/mspec/mspec/matchers/be_computed_by.rb', line 7 def matches?(array) array.each do |line| @receiver = line.shift @value = line.pop @arguments = line @arguments += @args return false unless @receiver.send(@method, *@arguments) == @value end return true end |
#method_call ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/extensions/mspec/mspec/matchers/be_computed_by.rb', line 19 def method_call method_call = "#{@receiver.inspect}.#{@method}" unless @arguments.empty? method_call << " from #{@arguments.map { |x| x.inspect }.join(", ")}" end method_call end |