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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -