|
3 | 3 | RSpec.describe 'CssFetcher' do
|
4 | 4 | subject { CriticalPathCss::CssFetcher.new(config) }
|
5 | 5 |
|
| 6 | + let(:base_url) { 'http://0.0.0.0:9292' } |
6 | 7 | let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] }
|
7 |
| - let(:routes) { ['/', '/new_route'] } |
| 8 | + let(:routes) { ['/', '/new_route'] } |
8 | 9 | let(:config) do
|
9 | 10 | OpenStruct.new(
|
10 |
| - base_url: 'http://0.0.0.0:9292', |
| 11 | + base_url: base_url, |
11 | 12 | css_path: css_path,
|
12 | 13 | css_paths: css_paths,
|
13 | 14 | penthouse_options: {},
|
|
23 | 24 | it 'generates css for the single route' do
|
24 | 25 | expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
25 | 26 | options = JSON.parse(arg3)
|
| 27 | + |
26 | 28 | expect(options['css']).to eq '/test.css'
|
27 | 29 | end.once.and_return(response)
|
28 | 30 |
|
|
39 | 41 | it 'generates css for each route from the same file' do
|
40 | 42 | expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
41 | 43 | options = JSON.parse(arg3)
|
| 44 | + |
42 | 45 | expect(options['css']).to eq '/test.css'
|
43 | 46 | end.twice.and_return(response)
|
| 47 | + |
44 | 48 | subject.fetch
|
45 | 49 | end
|
46 | 50 | end
|
|
52 | 56 | it 'generates css for each route from the respective file' do
|
53 | 57 | expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
54 | 58 | 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 |
57 | 63 | end.twice.and_return(response)
|
| 64 | + |
58 | 65 | subject.fetch
|
59 | 66 | end
|
60 | 67 | end
|
|
67 | 74 | it 'generates css for each route from the respective file' do
|
68 | 75 | expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
|
69 | 76 | 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 |
73 | 81 | end.thrice.and_return(response)
|
| 82 | + |
74 | 83 | subject.fetch
|
75 | 84 | end
|
76 | 85 | end
|
|
0 commit comments