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:
parent
bf2cb85e86
commit
9a3106721a
3 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue