[rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4
Jim Morris
ml at e4net.com
Thu Jul 3 02:29:53 EDT 2008
Hi David,
Thanks that worked, and fixed that problem.
Now I have run into another problem, from the same blog example (which I'll update once I get it all
to work).
Within the application helper I call haml_tag, which works fine when the app runs. (used to be
called open).
However when I try to test that helper in my helper spec I get...
NoMethodError in 'ApplicationHelper should display flash'
undefined method `haml_tag' for #<Spec::Rails::Example::HelperExampleGroup::HelperObject:0xb71ced20>
For some reason it doesn't know anything about haml when run from the spec.
I guess I need to inject a require haml or something into the HelperObject? I just don't know how to
do that.
I am using the latest version of HAML but I am still using rails 1.2.6
Any ideas?
Thanks
Jim
David Chelimsky wrote:
> 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
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
Jim Morris, http://blog.wolfman.com
More information about the rspec-users
mailing list