Class: BeComputedByMatcher

Inherits:
Object show all
Defined in:
lib/extensions/mspec/mspec/matchers/be_computed_by.rb

Instance Method Summary collapse

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_messageObject



27
28
29
# File 'lib/extensions/mspec/mspec/matchers/be_computed_by.rb', line 27

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

#matches?(array) ⇒ Boolean

Returns:

  • (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_callObject



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