Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## A simple HAML helper [ruby]
- module ApplicationHelper
- # display a flash message, when one is available
- # usage: (in haml)
- # - display_flash
- def display_flash
- for name in [:notice, :warning, :error]
- if flash[name]
- haml_tag :div, flash[name], {:class => name.to_s}
- end
- end
- nil
- end
- end
- ## RSpec for the helper [ruby]
- describe ApplicationHelper do
- include ApplicationHelper
- include ActionView::Helpers
- include Haml::Helpers
- before(:all) do
- @haml_is_haml = true
- @haml_stack = [Haml::Buffer.new(:attr_wrapper => "'")]
- end
- it "should display flash" do
- for name in [ :notice, :warning, :error ]
- flash[name] = "flash #{name.to_s} message"
- capture_haml {
- display_flash
- }.should have_tag( "div.#{name.to_s}", 1, :text => flash[name] )
- end
- end
- end
- ## Error!!!
- 1)
- NoMethodError in 'ApplicationHelper should display flash'
- You have a nil object when you didn't expect it!
- The error occurred while evaluating nil.buffer
- /home/evgeny/.gems/gems/haml-1.9.0/lib/haml/helpers.rb:255:in `capture_haml'
- ./spec/helpers/application_helper_spec.rb:16:
- ./spec/helpers/application_helper_spec.rb:14:in `each'
- ./spec/helpers/application_helper_spec.rb:14:
- script/spec:4:
- ## HELP
Add Comment
Please, Sign In to add comment