-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from benpickles/layout
Add support for wrapping a Phlex view in a layout
- Loading branch information
Showing
9 changed files
with
165 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ source 'https://rubygems.org' | |
gemspec | ||
|
||
gem 'capybara' | ||
gem 'haml' | ||
gem 'puma' | ||
gem 'rack-test' | ||
gem 'rake' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'capybara/rspec' | ||
|
||
class StreamingView < Phlex::HTML | ||
def view_template | ||
html { | ||
head { | ||
title { 'Streaming' } | ||
} | ||
body { | ||
p { 1 } | ||
flush # Internal private Phlex method. | ||
p { 2 } | ||
} | ||
} | ||
end | ||
end | ||
|
||
class StreamingApp < Sinatra::Application | ||
set :environment, :test | ||
|
||
get '/stream' do | ||
phlex StreamingView.new, stream: true | ||
end | ||
end | ||
|
||
# Trick Capybara into managing Puma for us. | ||
class NeedsServerDriver < Capybara::Driver::Base | ||
def needs_server? | ||
true | ||
end | ||
end | ||
|
||
Capybara.register_driver :needs_server do | ||
NeedsServerDriver.new | ||
end | ||
|
||
Capybara.app = StreamingApp | ||
Capybara.default_driver = :needs_server | ||
Capybara.server = :puma, { Silent: true } | ||
|
||
RSpec.describe Phlex::Sinatra do | ||
attr_reader :last_response | ||
|
||
def get(path) | ||
Net::HTTP.start( | ||
Capybara.current_session.server.host, | ||
Capybara.current_session.server.port, | ||
) { |http| | ||
@last_response = http.get(path) | ||
} | ||
end | ||
|
||
context 'when streaming' do | ||
it 'outputs the full response' do | ||
get('/stream') | ||
|
||
expect(last_response.body).to eql('<html><head><title>Streaming</title></head><body><p>1</p><p>2</p></body></html>') | ||
|
||
# Indicates that Sinatra's streaming is being used. | ||
expect(last_response['Content-Length']).to be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<main><%= yield %></main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%article | ||
!= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div><%= yield %></div> |