Sha256: 7d22297044af8dd67f4d5ee3cc53dcbd7ebbb7a49ed3ad6dbc4dab23fd607650

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'
require 'mspec/matchers'

describe BeComputedByFunctionMatcher do
  it "matches when all entries in the Array compute" do
    array = [ ["%2d",  65, "65"],
              ["%04d", 90, "0090"] ]
    BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_truthy
  end

  it "matches when all entries in the Array with arguments compute" do
    array = [ ["%2d",  "65"],
              ["%04d", "0065"] ]
    BeComputedByFunctionMatcher.new(:sprintf, 65).matches?(array).should be_truthy
  end

  it "does not match when any entry in the Array does not compute" do
    array = [ ["%2d",  65, "65"],
              ["%04d", 90, "00090"] ]
    BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_falsey
  end

  it "does not match when any entry in the Array with arguments does not compute" do
    array = [ ["%2d",  "65"],
              ["%04d", "0065"] ]
    BeComputedByFunctionMatcher.new(:sprintf, 91).matches?(array).should be_falsey
  end

  it "provides a useful failure message" do
    array = [ ["%2d",  90, "65"],
              ["%04d", 90, "00090"] ]
    matcher = BeComputedByFunctionMatcher.new(:sprintf)
    matcher.matches?(array)
    matcher.failure_message.should == ["Expected \"65\"", "to be computed by sprintf(\"%2d\", 90)"]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/matchers/be_computed_by_function_spec.rb
mspec-1.9.0 spec/matchers/be_computed_by_function_spec.rb