Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristianmandrup/545866 to your computer and use it in GitHub Desktop.
Save kristianmandrup/545866 to your computer and use it in GitHub Desktop.
# Functioning RSpec 2 spec for ActiveView helper
require 'spec_helper'
require 'action_view/template/handlers/erb'
module MyViewHelper
def tab_for(clazz, &block)
content = with_output_buffer(&block)
content_tag :li, content, :class => clazz
end
end
module MyOtherViewHelper
def hello(clazz, &block)
content = with_output_buffer(&block)
content_tag :div, content, :class => clazz
end
end
class ActionViewTester
include ActionView::Helpers::TagHelper
include ActionView::Helpers::CaptureHelper
def initialize &block
if block
block.arity < 1 ? self.instance_eval(&block) : block.call(self)
end
end
def with_output_buffer(buf = nil)
yield
end
def self.tests *helpers
helpers.flatten.each do |name|
include name.to_s.camelize.constantize
end
end
end
describe "do it" do
it "works" do
ActionViewTester.tests MyViewHelper, MyOtherViewHelper
ActionViewTester.new do |helper|
helper.tab_for('kristian') { 'hello' }.should match /kristian/
helper.hello('david') { 'hello' }.should match /david/
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment