Skip to content

Commit 9a31067

Browse files
committed
Update capture to handle empty blocks
1 parent bf2cb85 commit 9a31067

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

sinatra-contrib/lib/sinatra/capture.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def capture(*args, &block)
110110
buffer.clear unless buffer.nil?
111111
result = render(current_engine, dummy, options, &block)
112112
end
113-
result.strip.empty? && @capture ? @capture : result
113+
result && result.strip.empty? && @capture ? @capture : result
114114
ensure
115115
buffer.replace(old_buffer) unless buffer.nil?
116116
end

sinatra-contrib/spec/capture_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def render(engine, template)
5050
expect(render(:erb, "iso_8859_1")).to eq("ISO-8859-1 -")
5151
end
5252
end
53+
54+
describe 'without templates' do
55+
it 'captures empty blocks' do
56+
expect(capture {}).to be_nil
57+
end
58+
end
5359
end
5460

5561
__END__

sinatra-contrib/spec/content_for_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def render(engine, template)
3333
end
3434

3535
it 'renders default content if no block matches the key and a default block is specified' do
36-
content_for(:bar) { "bar" }
36+
expect(yield_content(:foo) {}).to be_nil
3737
expect(yield_content(:foo) { "foo" }).to eq("foo")
3838
end
3939

0 commit comments

Comments
 (0)