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