Skip to content

Commit 7f85a10

Browse files
Refactor fetcher spec
Refactor base url and expect options
1 parent 60ee217 commit 7f85a10

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

spec/lib/critical_path_css/css_fetcher_spec.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
RSpec.describe 'CssFetcher' do
44
subject { CriticalPathCss::CssFetcher.new(config) }
55

6+
let(:base_url) { 'http://0.0.0.0:9292' }
67
let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] }
7-
let(:routes) { ['/', '/new_route'] }
8+
let(:routes) { ['/', '/new_route'] }
89
let(:config) do
910
OpenStruct.new(
10-
base_url: 'http://0.0.0.0:9292',
11+
base_url: base_url,
1112
css_path: css_path,
1213
css_paths: css_paths,
1314
penthouse_options: {},
@@ -23,6 +24,7 @@
2324
it 'generates css for the single route' do
2425
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
2526
options = JSON.parse(arg3)
27+
2628
expect(options['css']).to eq '/test.css'
2729
end.once.and_return(response)
2830

@@ -39,8 +41,10 @@
3941
it 'generates css for each route from the same file' do
4042
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
4143
options = JSON.parse(arg3)
44+
4245
expect(options['css']).to eq '/test.css'
4346
end.twice.and_return(response)
47+
4448
subject.fetch
4549
end
4650
end
@@ -52,9 +56,12 @@
5256
it 'generates css for each route from the respective file' do
5357
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
5458
options = JSON.parse(arg3)
55-
expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/'
56-
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
5763
end.twice.and_return(response)
64+
5865
subject.fetch
5966
end
6067
end
@@ -67,10 +74,12 @@
6774
it 'generates css for each route from the respective file' do
6875
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
6976
options = JSON.parse(arg3)
70-
expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/'
71-
expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route'
72-
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
7381
end.thrice.and_return(response)
82+
7483
subject.fetch
7584
end
7685
end

0 commit comments

Comments
 (0)