Skip to content

Commit

Permalink
RailsWidget#capture should return a RawString
Browse files Browse the repository at this point in the history
  • Loading branch information
John Firebaugh committed Oct 27, 2009
1 parent 3f72a3f commit 465f0b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/erector/rails/extensions/rails_widget.rb
Expand Up @@ -34,7 +34,7 @@ def output
end

def capture(&block)
parent ? parent.capture(&block) : super
parent ? raw(parent.capture(&block).to_s) : super
end

# This is here to force #parent.capture to return the output
Expand Down
28 changes: 23 additions & 5 deletions spec/rails_root/spec/rails_widget_spec.rb
Expand Up @@ -7,14 +7,32 @@
end

describe "#capture" do
it "returns a RawString" do
captured = nil
Erector::RailsWidget.inline do
captured = capture {}
end.to_s(:parent => @view).should == ""
captured.should be_a_kind_of Erector::RawString
end

it "captures helper output" do
captured = nil
Erector::RailsWidget.inline do
captured = capture do
helpers.concat "capture me!"
end
end.to_s(:parent => @view, :helpers => @view).should == ""
captured.should == "capture me!"
end

it "captures with an erector block" do
captured = nil
Erector::RailsWidget.inline(:parent => @view) do
captured = parent.capture do
h1 'capture me!'
Erector::RailsWidget.inline do
captured = capture do
text 'capture me!'
end
end.to_s.should == ""
captured.should == "<h1>capture me!</h1>"
end.to_s(:parent => @view).should == ""
captured.should == "capture me!"
end
end
end

0 comments on commit 465f0b6

Please sign in to comment.