Skip to content

Commit 111fec3

Browse files
author
Jake Boxer
committed
Reorganize live reloading specs
* Move live asset and view reloading specs into their own contexts
1 parent 13b4237 commit 111fec3

File tree

1 file changed

+70
-60
lines changed

1 file changed

+70
-60
lines changed

spec/application_spec.rb

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -190,68 +190,78 @@
190190
end
191191

192192
describe "live reloading" do
193-
before :each do
194-
@root = prepare_fixture(:assets)
195-
@app = Hyperloop::Application.new(@root)
196-
@request = Rack::MockRequest.new(@app)
197-
end
198-
199-
it "reloads assets when they're changed" do
200-
# On the first request, stylesheet should have `display: block;` and not
201-
# `display: inline;`.
202-
response = @request.get("/assets/stylesheets/app.css")
203-
expect(response).to be_ok
204-
expect(response.body).to match(/display: ?block;/)
205-
expect(response.body).not_to match(/display: ?inline;/)
206-
207-
# Load layout and change the title to "Changed"
208-
asset_path = File.join(@root, "app", "assets", "stylesheets", "my-styles.scss")
209-
asset_data = File.read(asset_path)
210-
asset_data.sub!("display: block;", "display: inline;")
211-
File.write(asset_path, asset_data)
212-
213-
# On the second request, stylesheet should have `display: inline;` and not
214-
# `display: block;`.
215-
response = @request.get("/assets/stylesheets/app.css")
216-
expect(response).to be_ok
217-
expect(response.body).to match(/display: ?inline;/)
218-
expect(response.body).not_to match(/display: ?block;/)
219-
end
220-
221-
it "reloads layouts when they're changed" do
222-
# On the first request, <title> text should not be "Changed"
223-
response = @request.get("/")
224-
expect(response).to be_ok
225-
expect(text_in(response.body, "title")).not_to eql("Changed")
226-
227-
# Load layout and change the title to "Changed"
228-
layout_path = File.join(@root, "app", "views", "layouts", "application.html.erb")
229-
layout_data = File.read(layout_path)
230-
layout_data.sub!(/<title>[^<]*<\/title>/, "<title>Changed</title>")
231-
File.write(layout_path, layout_data)
232-
233-
# On the second request, <title> text should be "Changed"
234-
response = @request.get("/")
235-
expect(response).to be_ok
236-
expect(text_in(response.body, "title")).to eql("Changed")
193+
context "with assets" do
194+
before :each do
195+
@root = prepare_fixture(:assets)
196+
@app = Hyperloop::Application.new(@root)
197+
@request = Rack::MockRequest.new(@app)
198+
end
199+
200+
it "reloads changed assets" do
201+
# On the first request, stylesheet should have `display: block;` and not
202+
# `display: inline;`.
203+
response = @request.get("/assets/stylesheets/app.css")
204+
expect(response).to be_ok
205+
expect(response.body).to match(/display: ?block;/)
206+
expect(response.body).not_to match(/display: ?inline;/)
207+
208+
# Load layout and change the title to "Changed"
209+
asset_path = File.join(@root, "app", "assets", "stylesheets", "my-styles.scss")
210+
asset_data = File.read(asset_path)
211+
asset_data.sub!("display: block;", "display: inline;")
212+
File.write(asset_path, asset_data)
213+
214+
# On the second request, stylesheet should have `display: inline;` and not
215+
# `display: block;`.
216+
response = @request.get("/assets/stylesheets/app.css")
217+
expect(response).to be_ok
218+
expect(response.body).to match(/display: ?inline;/)
219+
expect(response.body).not_to match(/display: ?block;/)
220+
end
237221
end
238222

239-
it "reloads views when they're changed" do
240-
# On the first request, <h2> text should not be "Changed"
241-
response = @request.get("/")
242-
expect(response).to be_ok
243-
expect(text_in(response.body, "h2")).not_to eql("Changed")
244-
245-
# Load index.html.erb and change the title to "Changed"
246-
index_file_path = File.join(@root, "app", "views", "index.html.erb")
247-
index_file_data = File.read(index_file_path)
248-
index_file_data.sub!(/<h2>[^<]*<\/h2>/, "<h2>Changed</h2>")
249-
File.write(index_file_path, index_file_data)
250-
251-
# On the second request, <h2> text should be "Changed"
252-
response = @request.get("/")
253-
expect(response).to be_ok
254-
expect(text_in(response.body, "h2")).to eql("Changed")
223+
context "with views" do
224+
before :each do
225+
@root = prepare_fixture(:partials)
226+
@app = Hyperloop::Application.new(@root)
227+
@request = Rack::MockRequest.new(@app)
228+
end
229+
230+
it "reloads changed layouts" do
231+
# On the first request, <title> text should not be "Changed"
232+
response = @request.get("/")
233+
expect(response).to be_ok
234+
expect(text_in(response.body, "title")).not_to eql("Changed")
235+
236+
# Load layout and change the title to "Changed"
237+
layout_path = File.join(@root, "app", "views", "layouts", "application.html.erb")
238+
layout_data = File.read(layout_path)
239+
layout_data.sub!(/<title>[^<]*<\/title>/, "<title>Changed</title>")
240+
File.write(layout_path, layout_data)
241+
242+
# On the second request, <title> text should be "Changed"
243+
response = @request.get("/")
244+
expect(response).to be_ok
245+
expect(text_in(response.body, "title")).to eql("Changed")
246+
end
247+
248+
it "reloads changed views" do
249+
# On the first request, <h2> text should not be "Changed"
250+
response = @request.get("/")
251+
expect(response).to be_ok
252+
expect(text_in(response.body, "h2")).not_to eql("Changed")
253+
254+
# Load index.html.erb and change the title to "Changed"
255+
index_file_path = File.join(@root, "app", "views", "index.html.erb")
256+
index_file_data = File.read(index_file_path)
257+
index_file_data.sub!(/<h2>[^<]*<\/h2>/, "<h2>Changed</h2>")
258+
File.write(index_file_path, index_file_data)
259+
260+
# On the second request, <h2> text should be "Changed"
261+
response = @request.get("/")
262+
expect(response).to be_ok
263+
expect(text_in(response.body, "h2")).to eql("Changed")
264+
end
255265
end
256266
end
257267
end

0 commit comments

Comments
 (0)