[rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4

David Chelimsky dchelimsky at gmail.com
Wed Jul 2 23:54:40 EDT 2008


On Jul 2, 2008, at 7:12 PM, Jim Morris wrote:

> Hi,
>
> Many moons ago I wrote this blog entry...
>
> http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers
>
> I just upgraded that rails project to use rspec 1.1.4 and associated  
> rspec_rails.
>
> It seems that my helper when called from the helper specs no longer  
> are able to access flash, controller etc as they did before.
>
> I already prepended all helper calls with helper. so I fixed those  
> changes, but I have been unable to figure out how to access flash  
> etc...
>
> Here is a simplified example...
>
> in ApplicationHelper.rb
>
> def test_flash
>    for name in [:notice, :warning, :error]
>      if flash[name]
>        return "#{flash[name]}"
>      end
>    end
>    nil
>  end
>
> In my rails/spec/helpers/application_helper_spec.rb
>
> require File.dirname(__FILE__) + '/../spec_helper'
>
> describe ApplicationHelper do
>
>  it "should test flash" do
>    for name in [:notice, :warning, :error]
>      flash[name]= "flash #{name.to_s} message"
>      helper.test_flash.should match(/.*#{name}.*/)
>      flash[name]= nil
>    end
>  end
>
> end
>
> I get this error trace...
> 1)
> NoMethodError in 'ApplicationHelper should test flash'
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.[]
> /.../app/helpers/application_helper.rb:23:in `test_flash'
> ...
>
> flash is nil, this used to work, so what is the new magic  
> incantation to get this to work again?

Hey Jim - I fixed this in http://github.com/dchelimsky/rspec-rails/commit/40a0916325dbe9a1631849146d078e330fca71f2 
, so you can either grab the very latest from github or wait for the  
1.1.5 release (coming in the next few days).

Cheers,
David


More information about the rspec-users mailing list