Sha256: d28ca172ae9e50b0df82b07179b993330e1069ab18ecf789b927e79195b8ad3d

Contents?: true

Size: 1.87 KB

Versions: 108

Compression:

Stored size: 1.87 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

108 entries across 108 versions & 1 rubygems

Version Path
fossil-0.4.15 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.14 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.13 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.12 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.10 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.9 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.8 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.7 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.6 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.5 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.3 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.2 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.1 spec/be_model_with_values_matcher_spec.rb
fossil-0.4.0 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.49 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.48 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.47 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.46 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.45 spec/be_model_with_values_matcher_spec.rb
fossil-0.3.44 spec/be_model_with_values_matcher_spec.rb