Sha256: c8332e4906aaa7f6038b4ccfd2ca8a7878f125a69e5ed5df4feaa1a1c147443d

Contents?: true

Size: 820 Bytes

Versions: 9

Compression:

Stored size: 820 Bytes

Contents

class BeComputedByMatcher
  def initialize(sym, *args)
    @method = sym
    @args = args
  end

  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

  def method_call
    method_call = "#{@receiver.inspect}.#{@method}"
    unless @arguments.empty?
      method_call << " from #{@arguments.map { |x| x.inspect }.join(", ")}"
    end
    method_call
  end

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

class Object
  def be_computed_by(sym, *args)
    BeComputedByMatcher.new(sym, *args)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mspec-1.9.1 lib/mspec/matchers/be_computed_by.rb
mspec-1.9.0 lib/mspec/matchers/be_computed_by.rb
mspec-1.8.0 lib/mspec/matchers/be_computed_by.rb
mspec-1.7.0 lib/mspec/matchers/be_computed_by.rb
mspec-1.6.0 lib/mspec/matchers/be_computed_by.rb
mspec-1.5.21 lib/mspec/matchers/be_computed_by.rb
mspec-1.5.20 lib/mspec/matchers/be_computed_by.rb
mspec-1.5.19 lib/mspec/matchers/be_computed_by.rb
mspec-1.5.18 lib/mspec/matchers/be_computed_by.rb