Class: BeComputedByMatcher
- Defined in:
- lib/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/mspec/matchers/be_computed_by.rb', line 2 def initialize(sym, *args) @method = sym @args = args end |
Instance Method Details
#failure_message ⇒ Object
28 29 30 |
# File 'lib/mspec/matchers/be_computed_by.rb', line 28 def ["Expected #{@value.inspect}", "to be computed by #{method_call} (computed #{@actual.inspect} instead)"] end |
#matches?(array) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/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 @actual = @receiver.send(@method, *@arguments) return false unless @actual == @value end return true end |
#method_call ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mspec/matchers/be_computed_by.rb', line 20 def method_call method_call = "#{@receiver.inspect}.#{@method}" unless @arguments.empty? method_call << " from #{@arguments.map { |x| x.inspect }.join(", ")}" end method_call end |