1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

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