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