Sha256: 632f154f1a495efd709808fee8288634e1ae94d7da4e5e545db386cd5c140845

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'
require 'mspec/matchers'

describe BeComputedByMatcher do
  it "matches when all entries in the Array compute" do
    array = [ [65, "A"],
              [90, "Z"] ]
    BeComputedByMatcher.new(:chr).matches?(array).should be_true
  end

  it "matches when all entries in the Array with arguments compute" do
    array = [ [1, 2, 3],
              [2, 4, 6] ]
    BeComputedByMatcher.new(:+).matches?(array).should be_true
  end

  it "does not match when any entry in the Array does not compute" do
    array = [ [65, "A" ],
              [91, "Z" ] ]
    BeComputedByMatcher.new(:chr).matches?(array).should be_false
  end

  it "accepts an argument list to apply to each method call" do
    array = [ [65, "1000001" ],
              [90, "1011010" ] ]
    BeComputedByMatcher.new(:to_s, 2).matches?(array).should be_true
  end

  it "does not match when any entry in the Array with arguments does not compute" do
    array = [ [1, 2, 3],
              [2, 4, 7] ]
    BeComputedByMatcher.new(:+).matches?(array).should be_false
  end

  it "provides a useful failure message" do
    array = [ [65, "A" ],
              [91, "Z" ] ]
    matcher = BeComputedByMatcher.new(:chr)
    matcher.matches?(array)
    matcher.failure_message.should == ["Expected \"Z\"", "to be computed by 91.chr (computed \"[\" instead)"]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mspec-1.8.0 spec/matchers/be_computed_by_spec.rb
mspec-1.7.0 spec/matchers/be_computed_by_spec.rb
mspec-1.6.0 spec/matchers/be_computed_by_spec.rb
mspec-1.5.21 spec/matchers/be_computed_by_spec.rb
mspec-1.5.20 spec/matchers/be_computed_by_spec.rb
mspec-1.5.19 spec/matchers/be_computed_by_spec.rb
mspec-1.5.18 spec/matchers/be_computed_by_spec.rb