I was wrong. This also works: ``` it do @test_hash["foobar"].size.should be 3 end ```
Looks like the error was due to the missing dot between size and should. This test: ``` it do should be 3 end ``` gives the same error: ``` 1) HashBug Test fails Failure/Error: should be 3 expected #<Fixnum:7> => 3 got #<String:70269524470620> => "Test fails" Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # ./eg_rspec.rb:7:in `block (3 levels) in <top (required)>' ``` It seems to indicate that if `should` is not called on an object, it takes the test description as the expected value - not entirely sure about this. Will have to read the docs to confirm. Vighnesh On Thu, May 2, 2013 at 3:29 PM, Vighnesh Rege <vighnesh1...@gmail.com>wrote: > > On Thu, May 2, 2013 at 3:01 PM, Kwasi Mensah <kwasi.men...@gmail.com>wrote: > >> @test_hash["foobar"].size should be 1 >> > > Shouldn't there be a dot between size and should? > Also, shouldn't the expected value be 3? > > Even after making these changes: > ``` > @test_hash["foobar"].should be 3 > ``` > the test fails for a reason that I'm not aware of. Personally, I'm more > comfortable with the expect syntax[ > https://github.com/rspec/rspec-expectations]. I changed the first test to: > > ``` > it do > expect(@test_hash["foobar"].size).to eq 3 > end > ``` > > And it now works. > > > Vighnesh > >
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users