Created
August 23, 2010 17:00
-
-
Save kristianmandrup/545866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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