ruby on rails - For newbie : Test with rspec in a model using a method -


i have ownership model, has start_date , end_date , in model, have following code :

def current?   self.start_date.present? && self.end_date.nil? end 

now want test ownership.current?

how going ? here tried, using expect...

describe "when owning , giving date nil"   before     @ownership.agreed = true     @ownership.save     @ownership.update_attributes(start_date: nil, end_date: nil)   end   { should be_valid }   expect(@ownership.current?).to be_false    describe "then product owned"     before { @ownership.update_attributes(start_date: 1.day.ago) }      { should be_valid }     expect(@ownership.current?).to be_true      describe "then product given"       before { @ownership.update_attributes(end_date: 1.hour.ago) }        { should be_valid }       expect(@ownership.current?).to be_false     end   end end 

... didn't worked. tried replace expect(@ownership.current?).to be_false @ownership.current? { should be_false }, didn't worked out either.

do have idea how ?

i'd test 2 outcomes current?

describe ownership   "#current? returns false"     ownership.current?.should be_false   end    context "when started , not yet ended"     "#current? returns true"       ownership.start_date = date.today       ownership.end_date = nil       ownership.current?.should be_true     end   end end 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -