I cannot understand why the block of code below is not passing even though the puts value is showing the value I am checking for:
let(:new_on_each_example) { MovieList.new }
it "can use method defined by 'let'" do
new_on_each_example.should_not be_nil
# the object is memoized, so
new_on_each_example.should == new_on_each_example
puts new_on_each_example.class
new_on_each_example.class.should == "MovieList"
end
The console shows:
MovieList
expected: "MovieList" got: MovieList(id: integer, title: string, created_at: datetime, updated_at: datetime, track_number: integer) (using ==)
Puts displays the value that I'm looking for but the test fails. Why is this?
new_on_each_example.should be_instance_of(MovieList)
更多信息在rspec matchers doc中
You are passing to RSpec "MovieList"
. It's a string, not the constant for your class. So you should do something like:
new_on_each_example.class.should == MovieList
but using RSpec you can do something more elegant too:
new_on_each_example.class.should be_a(MovieList)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.