I'm having trouble with one of my rspecs and it's coming down to the tests being confused about what the subject is. Here's an example spec and the corresponding test failures I get:describe "HashBug" dobefore do@test_hash = {"foobar" => ["a", "b", "c"]}enddescribe "Test fails" doit do@test_hash["foobar"].size should be 1endenddescribe "Test passes" doit do@test_hash["foobar"][0].should eq "a"endendendFailures:1) HashBug Test failsFailure/Error: @test_hash["foobar"].size should be 1expected #<Fixnum:3> => 1got #<String:70131453842100> => "Test fails"Compared using equal?, which compares object identity,but expected and actual are not the same object. Use'actual.should eq(expected)' if you don't care aboutobject identity in this example.# ./spec/requests/test_hash_bug_spec.rb:7:in `block (3 levels) in <top (required)>'Finished in 0.00215 seconds2 examples, 1 failureFailed examples:rspec ./spec/requests/test_hash_bug_spec.rb:6 # HashBug Test failsI'm not clear on why the match fails with one level of using [] but passes with two levels.I'm using the command:bundle exec rspec spec/requests/test_hash_bug_spec.rbI'm using the following rspec gems:rspec (2.11.0)rspec-core (2.11.1)rspec-expectations (2.11.3)rspec-mocks (2.11.3)rspec-rails (2.11.0)And I can provide my full gem list if needed.Kwasi
@test_hash["foobar"].size should be 1
This syntax should work
@test_hash["foobar"].size.should eq(1)
But @test_hash["foobar"] evaluates to ["a","b","c"], so its size is actually 3.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
Vighnesh