Update capture to handle empty blocks

This commit is contained in:
Jordan Owens 2018-12-09 01:15:52 -05:00
parent bf2cb85e86
commit 9a3106721a
3 changed files with 8 additions and 2 deletions

View File

@ -110,7 +110,7 @@ module Sinatra
buffer.clear unless buffer.nil?
result = render(current_engine, dummy, options, &block)
end
result.strip.empty? && @capture ? @capture : result
result && result.strip.empty? && @capture ? @capture : result
ensure
buffer.replace(old_buffer) unless buffer.nil?
end

View File

@ -50,6 +50,12 @@ describe Sinatra::Capture do
expect(render(:erb, "iso_8859_1")).to eq("ISO-8859-1 -")
end
end
describe 'without templates' do
it 'captures empty blocks' do
expect(capture {}).to be_nil
end
end
end
__END__

View File

@ -33,7 +33,7 @@ describe Sinatra::ContentFor do
end
it 'renders default content if no block matches the key and a default block is specified' do
content_for(:bar) { "bar" }
expect(yield_content(:foo) {}).to be_nil
expect(yield_content(:foo) { "foo" }).to eq("foo")
end