That's really weird. I can't see anywhere that it would be trying to use
a Symbol as a String. However, I do know how to get "open" as a string.
The trick is that "open" and "puts," like "form_for" and the like, write
directly to Haml's output buffer. However, there's a helper that allows
you to take something directly written to the buffer and get it as a
string, called "capture". It works like so:
capture do
open :foo, 'bar'
end
That would return "<foo>\n bar\n</foo>". So you could do "capture {
display_flash }.should == ...".
Try that and see if it works. If it doesn't, let me know.
- Nathan
wolfmanjm wrote:
> So presuming I can require haml or something and overcome this error,
> how would U check the output? Obviously this spec was written
> expecting the display_flash helper to return a string (which it used
> to do), by using open it now presumably renders directly to the haml
> buffer, so how would I retrieve that so I can test it? (Remember this
> helper spec runs without using actually using a view).
>
> Thanks
>
> On Jul 11, 10:13 pm, wolfmanjm <[EMAIL PROTECTED]> wrote:
>
>> Sure here you go...
>>
>> TypeError in 'ApplicationHelper should display flash'
>> can't convert Symbol into String
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/config/../app/helpers/
>> application_helper.rb:15:in `open'
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/config/../app/helpers/
>> application_helper.rb:15:in `display_flash'
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/config/../app/helpers/
>> application_helper.rb:13:in `each'
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/config/../app/helpers/
>> application_helper.rb:13:in `display_flash'
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/spec/helpers/
>> application_helper_spec.rb:12:
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/spec/helpers/
>> application_helper_spec.rb:10:in `each'
>> /home/morris/work/snowdogsrus/rails/snowdogsrus/spec/helpers/
>> application_helper_spec.rb:10:
>>
>> # application_helper_spec.rb
>> require File.dirname(__FILE__) + '/../spec_helper'
>>
>> describe ApplicationHelper do
>>
>> it "should display flash" do
>> for name in [:notice, :warning, :error]
>> flash[name]= "flash #{name.to_s} message"
>> display_flash.should == "<div class=\"#{name}\">#{flash[name]}</
>> div>" # Line 12
>> flash[name]= nil
>> end
>> end
>> end
>>
>> # application_helper.rb
>>
>> def display_flash
>> for name in [:notice, :warning, :error]
>> if flash[name]
>> open :div, flash[name], {:class => name} # Line 15
>> end
>> end
>> nil
>> end
>>
>> (Note I know this test will not match, but it is meant to fail the
>> first time ;)
>> However the error has nothing to do with the test, it is because open
>> is probably trying to call File::open
>>
>> I don't believe HAML is even being loaded for this test.
>>
>> On Jul 11, 6:19 pm, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
>>
>>
>>> Do you have a backtrace I can see? I'm too lazy to do it myself :p. In
>>> my defense, it's the hottest day of the year in Seattle...
>>>
>>> - Nathan
>>>
>>> wolfmanjm wrote:
>>>
>>>> I like RSpec as it has the ability to test helpers standalone.
>>>>
>>>> However I have not yet found the magic incantation to get it to work
>>>> with a helper that uses open or puts.
>>>>
>>>> I suspect you need to include HAML and setup some context for it to
>>>> render to.
>>>>
>>>> Any ideas on how to do that would be appreciated as I had to disable
>>>> many of my RSpec helper tests when I started using HAML open.
>>>>
>>>> On Jul 10, 11:46 pm, Moses Hohman <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> What's the best way to test helper methods that generate HTML using
>>>>> Haml::Helpers#open? I want to test the helper method directly without
>>>>> using it in a view.
>>>>>
>>>>> thanks, M
>>>>>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---