Rails: Rspec and console output differ -


i'm having issue specs. i'm trying run spec creates , destroys associated object, none of specs creating or destroying object. weird thing is, can literally copy , paste every line of code (except .should) out of each test console , console run each expectation perfectly, creating , destroying objects. here's sample:

it "should not destroy notification on comment"   comment = factorygirl.create(:comment)   = factorygirl.create_list(:like, 2, likable: comment)   like.first.destroy   note = comment.user.notifications.find_by(notifiable: comment, from_comment: false)   note.should_not be_nil end 

only first on specific comment send notification comment's author. , if comment has 1 like, , destroyed, destroy notification had sent, won't destroy notification if comment has more 0 likes @ time.

is problem i'm not writing scalable code? know specs aren't perfect, why console getting different results identical input?

are running rails console in test environment or in development defaults to? different database , environment configurations might reason different behavior, note object might exist in development db @ time test manually in console.

either try running console in test environment:

$ rails c test 

or better temporarily put debugger line inside test code (you need 'debugger' gem installed if don't have already):

it "should not destroy notification on comment"   comment = factorygirl.create(:comment)   = factorygirl.create_list(:like, 2, likable: comment) debugger   like.first.destroy   note = comment.user.notifications.find_by(notifiable: comment, from_comment: false)   note.should_not be_nil end 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -