Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f11de6

Browse files
Merge pull request #41 from mudbugmedia/refactor-tests
Refactor tests
2 parents 7464614 + 7f85a10 commit 6f11de6

File tree

7 files changed

+90
-95
lines changed

7 files changed

+90
-95
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
css_paths:
4+
- /test.css
5+
- /test2.css
6+
routes:
7+
- /
8+
- /new_route
9+
10+
development:
11+
<<: *defaults
12+
13+
test:
14+
<<: *defaults
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
manifest_name: application
4+
routes:
5+
- /
6+
7+
development:
8+
<<: *defaults
9+
10+
test:
11+
<<: *defaults
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
css_paths:
4+
- /test.css
5+
- /test2.css
6+
routes:
7+
- /
8+
- /new_route
9+
- /newer_route
10+
11+
development:
12+
<<: *defaults
13+
14+
test:
15+
<<: *defaults
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
css_path: /test.css
4+
css_paths:
5+
- /test.css
6+
- /test2.css
7+
routes:
8+
- /
9+
- /new_route
10+
11+
development:
12+
<<: *defaults
13+
14+
test:
15+
<<: *defaults
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
css_path: /test.css
4+
routes:
5+
- /
6+
7+
development:
8+
<<: *defaults
9+
10+
test:
11+
<<: *defaults

‎spec/lib/critical_path_css/css_fetcher_spec.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
require 'spec_helper'
22

33
RSpec.describe 'CssFetcher' do
4-
let(:subject) { CriticalPathCss::CssFetcher.new(config) }
4+
subject { CriticalPathCss::CssFetcher.new(config) }
5+
6+
let(:base_url) { 'http://0.0.0.0:9292' }
57
let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] }
6-
let(:routes) { ['/', '/new_route'] }
8+
let(:routes) { ['/', '/new_route'] }
79
let(:config) do
810
OpenStruct.new(
9-
base_url: 'http://0.0.0.0:9292',
11+
base_url: base_url,
1012
css_path: css_path,
1113
css_paths: css_paths,
1214
penthouse_options: {},
@@ -22,6 +24,7 @@
2224
it 'generates css for the single route' do
2325
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
2426
options = JSON.parse(arg3)
27+
2528
expect(options['css']).to eq '/test.css'
2629
end.once.and_return(response)
2730

@@ -38,8 +41,10 @@
3841
it 'generates css for each route from the same file' do
3942
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
4043
options = JSON.parse(arg3)
44+
4145
expect(options['css']).to eq '/test.css'
4246
end.twice.and_return(response)
47+
4348
subject.fetch
4449
end
4550
end
@@ -51,9 +56,12 @@
5156
it 'generates css for each route from the respective file' do
5257
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
5358
options = JSON.parse(arg3)
54-
expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/'
55-
expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route'
59+
60+
css_paths.each_with_index do |path, index|
61+
expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}"
62+
end
5663
end.twice.and_return(response)
64+
5765
subject.fetch
5866
end
5967
end
@@ -66,10 +74,12 @@
6674
it 'generates css for each route from the respective file' do
6775
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
6876
options = JSON.parse(arg3)
69-
expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/'
70-
expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route'
71-
expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/newer_route'
77+
78+
css_paths.each_with_index do |path, index|
79+
expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}"
80+
end
7281
end.thrice.and_return(response)
82+
7383
subject.fetch
7484
end
7585
end

‎spec/lib/critical_path_css/rails/config_loader_spec.rb

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
require 'spec_helper'
22

33
RSpec.describe 'ConfigLoader' do
4-
let(:subject) { CriticalPathCss::Rails::ConfigLoader.new }
4+
subject { CriticalPathCss::Rails::ConfigLoader.new }
55

66
describe '#load' do
77
before do
88
allow(File).to receive(:read).and_return(config_file)
99
end
1010

1111
context 'when single css_path is specified' do
12-
let(:config_file) {
13-
<<~CONFIG
14-
defaults: &defaults
15-
base_url: http://0.0.0.0:9292
16-
css_path: /test.css
17-
routes:
18-
- /
19-
20-
development:
21-
<<: *defaults
22-
23-
test:
24-
<<: *defaults
25-
CONFIG
26-
}
12+
let(:config_file) { file_fixture('config/single-css-path.yml').read }
2713

2814
it 'sets css_path with the path' do
2915
expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css'
@@ -35,24 +21,7 @@
3521
end
3622

3723
context 'when multiple css_paths are specified' do
38-
let(:config_file) {
39-
<<~CONFIG
40-
defaults: &defaults
41-
base_url: http://0.0.0.0:9292
42-
css_paths:
43-
- /test.css
44-
- /test2.css
45-
routes:
46-
- /
47-
- /new_route
48-
49-
development:
50-
<<: *defaults
51-
52-
test:
53-
<<: *defaults
54-
CONFIG
55-
}
24+
let(:config_file) { file_fixture('config/mutliple-css-paths.yml').read }
5625

5726
it 'sets css_path to empty string' do
5827
expect(subject.config['css_path']).to eq ''
@@ -64,21 +33,7 @@
6433
end
6534

6635
context 'when no paths are specified' do
67-
let(:config_file) {
68-
<<~CONFIG
69-
defaults: &defaults
70-
base_url: http://0.0.0.0:9292
71-
manifest_name: application
72-
routes:
73-
- /
74-
75-
development:
76-
<<: *defaults
77-
78-
test:
79-
<<: *defaults
80-
CONFIG
81-
}
36+
let(:config_file) { file_fixture('config/no-paths-specified.yml').read }
8237

8338
it 'sets css_path with the path' do
8439
expect(subject.config['css_path']).to eq '/stylesheets/application.css'
@@ -90,51 +45,15 @@
9045
end
9146

9247
context 'when single css_path and multiple css_paths are both specified' do
93-
let(:config_file) {
94-
<<~CONFIG
95-
defaults: &defaults
96-
base_url: http://0.0.0.0:9292
97-
css_path: /test.css
98-
css_paths:
99-
- /test.css
100-
- /test2.css
101-
routes:
102-
- /
103-
- /new_route
104-
105-
development:
106-
<<: *defaults
107-
108-
test:
109-
<<: *defaults
110-
CONFIG
111-
}
48+
let(:config_file) { file_fixture('config/paths-both-specified.yml').read }
11249

11350
it 'raises an error' do
11451
expect { subject }.to raise_error LoadError, 'Cannot specify both css_path and css_paths'
11552
end
11653
end
11754

11855
context 'when css_paths and routes are not the same length' do
119-
let(:config_file) {
120-
<<~CONFIG
121-
defaults: &defaults
122-
base_url: http://0.0.0.0:9292
123-
css_paths:
124-
- /test.css
125-
- /test2.css
126-
routes:
127-
- /
128-
- /new_route
129-
- /newer_route
130-
131-
development:
132-
<<: *defaults
133-
134-
test:
135-
<<: *defaults
136-
CONFIG
137-
}
56+
let(:config_file) { file_fixture('config/paths-and-routes-not-same-length.yml').read }
13857

13958
it 'raises an error' do
14059
expect { subject }.to raise_error LoadError, 'Must specify css_paths for each route'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /