ruby on rails - Lost trying to make the rspec test pass -
i have class:
class zombie < activerecord::base attr_accessible :iq validates :name, presence: true def genius? iq >= 3 end def self.genius where("iq >= ?", 3) end end and making rspec test:
describe zombie context "with high iq" let!(:zombie) { zombie.new(iq: 3, name: 'anna') } subject { zombie } "should returned genius" zombie.genius.should include(zombie) end "should have genius count of 1" zombie.genius.count.should == 1 end end end i having error message:
failures: 1) zombie high iq should have genius count of 1 failure/error: zombie.genius.count.should == 1 expected: 1 got: 0 (using ==) # zombie_spec.rb:11:in `block (3 levels) ' finished in 0.2138 seconds 2 examples, 1 failure failed examples: rspec zombie_spec.rb:10 # zombie high iq should have genius count of 1 i using syntax: let!(:zombie){...} telling got 0 when expected 1. idea? maybe have passed lot of time looking code , don't see problem.
you need zombie.create instead of zombie.new.
also, should syntax deprecated:
specify ".genius returns array of zombies" expect(zombie.genius).to include(zombie) end
Comments
Post a Comment