Forum: RSpec assigns variable maintaining state across request?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ivor P. (Guest)
on 2008-12-10 12:09
(Received via mailing list)
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
David C. (Guest)
on 2008-12-10 15:06
(Received via mailing list)
On Wed, Dec 10, 2008 at 4:08 AM, Ivor P. <removed_email_address@domain.invalid> 
wrote:
>     @variable
> #this does not pass
>     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
This topic is locked and can not be replied to.