Class: BeComputedByFunctionMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mspec/matchers/be_computed_by_function.rb

Instance Method Summary collapse

Constructor Details

#initialize(sym, *args) ⇒ BeComputedByFunctionMatcher

Returns a new instance of BeComputedByFunctionMatcher


2
3
4
5
# File 'lib/mspec/matchers/be_computed_by_function.rb', line 2

def initialize(sym, *args)
  @function = sym
  @args = args
end

Instance Method Details

#failure_messageObject


26
27
28
# File 'lib/mspec/matchers/be_computed_by_function.rb', line 26

def failure_message
  ["Expected #{@value.inspect}", "to be computed by #{function_call}"]
end

#function_callObject


18
19
20
21
22
23
24
# File 'lib/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

Returns:

  • (Boolean)

7
8
9
10
11
12
13
14
15
16
# File 'lib/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