daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest May 16th, 2018 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## A simple HAML helper [ruby]
  2. module ApplicationHelper
  3.   # display a flash message, when one is available
  4.   # usage:  (in haml)
  5.   #   - display_flash
  6.   def display_flash
  7.     for name in [:notice, :warning, :error]
  8.       if flash[name]
  9.         haml_tag :div, flash[name], {:class => name.to_s}
  10.       end
  11.     end
  12.     nil
  13.   end
  14. end
  15.  
  16. ## RSpec for the helper [ruby]
  17. describe ApplicationHelper do
  18.   include ApplicationHelper
  19.   include ActionView::Helpers
  20.   include Haml::Helpers
  21.  
  22.   before(:all) do
  23.     @haml_is_haml = true
  24.     @haml_stack = [Haml::Buffer.new(:attr_wrapper => "'")]
  25.   end
  26.  
  27.   it "should display flash" do
  28.     for name in [ :notice, :warning, :error ]
  29.       flash[name] = "flash #{name.to_s} message"
  30.       capture_haml {
  31.         display_flash
  32.       }.should have_tag( "div.#{name.to_s}", 1, :text => flash[name] )
  33.     end
  34.   end
  35. end
  36.  
  37. ## Error!!!
  38. 1)
  39. NoMethodError in 'ApplicationHelper should display flash'
  40. You have a nil object when you didn't expect it!
  41. The error occurred while evaluating nil.buffer
  42. /home/evgeny/.gems/gems/haml-1.9.0/lib/haml/helpers.rb:255:in `capture_haml'
  43. ./spec/helpers/application_helper_spec.rb:16:
  44. ./spec/helpers/application_helper_spec.rb:14:in `each'
  45. ./spec/helpers/application_helper_spec.rb:14:
  46. script/spec:4:
  47.  
  48.  
  49. ## HELP
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top