Sha256: 61960e1a3612b4bc02286569a9271366db7ab1ffb9edd7f66821656b1574c193

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'
 
describe "spec matchers" do

  describe "be_model_with_values matcher" do

    it "should match a models values if they are all in the expected hash" do
      dude = MockModel.new({:kid_date=>1, :kid_time=>2})
      dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
    end

    it "should match a models values if they are all in the expected hash even if values hash has symbol keys" do
      dude = MockModel.new({:kid_date=>1, :kid_time=>2})
      dude.should be_model_with_values( {'kid_date'=>1, 'kid_time'=>2} )
    end

    it "should match (as strings) a models values if they are all in the expected hash" do
      dude = MockModel.new({:kid_date=>"1", :kid_time=>"2"})
      dude.should be_model_with_values_as_strings( {:kid_date=>1, :kid_time=>2} )
    end

    it "should fail match for models values if they are in the expected hash but of wrong type" do
      dude = MockModel.new({:kid_date=>1, :kid_time=>"2"})
      begin
        dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
      rescue => e
        e.message.should match("unequal values: \nexpected: \\{:kid_time=>2\\} \n but got:\n\\{:kid_time=>\"2\"\\}")
      end
    end

    it "should fail if model does not have all the keys as expected hash" do
      dude = MockModel.new({:kid_date=>1})
      begin
        dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
      rescue => e
        e.message.should match("missing keys: \\[:kid_time\\]")
      end
    end

    it "should fail if one of the values does not match" do
      dude = MockModel.new( {:kid_date=>1, :kid_time=>3} )
      begin
        dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
      rescue => e
        e.message.should match("unequal values: \nexpected: \\{:kid_time=>2\\} \n but got:\n\\{:kid_time=>3\\}")
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fossil-0.3.15 spec/be_model_with_values_matcher_spec.rb