Skip to content

Commit

Permalink
It's an ArgumentError (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
benpickles authored Jan 28, 2025
1 parent 44f1b55 commit f06ae9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/phlex-sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Phlex
module Sinatra
Error = Class.new(StandardError)
IncompatibleOptionError = Class.new(Error)
ArgumentError = Class.new(Error)

class TypeError < Error
MAX_SIZE = 32
Expand Down Expand Up @@ -47,6 +47,10 @@ def phlex(
)
raise Phlex::Sinatra::TypeError.new(obj) unless obj.is_a?(Phlex::SGML)

if layout && stream
raise Phlex::Sinatra::ArgumentError.new('streaming is not compatible with layout')
end

content_type ||= :svg if obj.is_a?(Phlex::SVG) && !layout
self.content_type(content_type) if content_type

Expand All @@ -55,10 +59,6 @@ def phlex(
layout = @default_layout if layout == true

if stream
raise Phlex::Sinatra::IncompatibleOptionError.new(
'streaming is not compatible with layout'
) if layout

self.stream do |out|
obj.call(out, view_context: self)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/general_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def app
expect(last_response.body).to start_with('<main><pre>')
end

it 'raises an error stream=true' do
it 'raises an error if stream=true' do
expect {
get('/stream-with-layout')
}.to raise_error(Phlex::Sinatra::IncompatibleOptionError)
}.to raise_error(Phlex::Sinatra::ArgumentError)
end

it 'works with non-ERB templates' do
Expand Down

0 comments on commit f06ae9f

Please sign in to comment.