Ivor Paul
2008-Dec-10 10:08 UTC
[rspec-users] assigns variable maintaining state across request?
Hi I found that if I set assigns[:variables] in a spec, the value is maintained in subsequent specs. Example rails helper method: def return_at_variable @variable end Specs: #this passes obviously it ''should return true if assigns[:variable] is true'' do assigns[:variable] = true helper.return_at_variable.should be_true end #this does not pass it ''should return nil becasue assigns[:variable] is not set'' do helper.return_at_variable.should be_nil end '''' FAILED expected nil? to return true, got false In this case both tests pass: it ''should return true if assigns[:variable] is true'' do assigns[:variable] = true helper.return_at_variable.should be_true end it ''should return nil becasue assigns[:variable] is not set'' do helper.return_at_variable.should be_true end Getting around this is simple enough - by just clearing/declaring the assigs[:variables] where ever I need to, but I am wondering if this is normal behaviour? Regards Ivor -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081210/66b0ffa3/attachment.html>
David Chelimsky
2008-Dec-10 13:05 UTC
[rspec-users] assigns variable maintaining state across request?
On Wed, Dec 10, 2008 at 4:08 AM, Ivor Paul <ivorpaul at gmail.com> wrote:> Hi > > I found that if I set assigns[:variables] in a spec, the value is maintained > in subsequent specs. > > Example > > rails helper method: > > def return_at_variable > @variable > end > > Specs: > > #this passes obviously > it ''should return true if assigns[:variable] is true'' do > assigns[:variable] = true > helper.return_at_variable.should be_true > end > > #this does not pass > it ''should return nil becasue assigns[:variable] is not set'' do > helper.return_at_variable.should be_nil > end > > '''' FAILED > expected nil? to return true, got false > > In this case both tests pass: > > it ''should return true if assigns[:variable] is true'' do > assigns[:variable] = true > helper.return_at_variable.should be_true > end > > it ''should return nil becasue assigns[:variable] is not set'' do > helper.return_at_variable.should be_true > end > > Getting around this is simple enough - by just clearing/declaring the > assigs[:variables] where ever I need to, but I am wondering if this is > normal behaviour?Nope. Please file a ticket at http://rspec.lighthouseapp.com. Thanks, David> > Regards > Ivor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >