|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -# rubocop:disable RSpec/VerifiedDoubles |
4 | | - |
5 | 3 | require_relative "../../react_on_rails/spec_helper" |
6 | 4 | require_relative "../../../lib/react_on_rails/doctor" |
7 | 5 |
|
|
89 | 87 |
|
90 | 88 | describe "#determine_server_bundle_path" do |
91 | 89 | context "when Shakapacker gem is available with relative paths" do |
92 | | - let(:shakapacker_config) { double(source_path: "client/app", source_entry_path: "packs") } |
| 90 | + let(:shakapacker_config) do |
| 91 | + instance_double(Shakapacker::Configuration, source_path: "client/app", source_entry_path: "packs") |
| 92 | + end |
93 | 93 |
|
94 | 94 | before do |
95 | | - shakapacker_module = double("Shakapacker", config: shakapacker_config) |
| 95 | + shakapacker_module = instance_double(Shakapacker, config: shakapacker_config) |
96 | 96 | stub_const("Shakapacker", shakapacker_module) |
97 | 97 | allow(doctor).to receive(:require).with("shakapacker").and_return(true) |
98 | | - allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js") |
| 98 | + allow(doctor).to receive(:server_bundle_filename).and_return("server-bundle.js") |
99 | 99 | end |
100 | 100 |
|
101 | 101 | it "uses Shakapacker API configuration with relative paths" do |
|
106 | 106 |
|
107 | 107 | context "when Shakapacker gem is available with absolute paths" do |
108 | 108 | let(:rails_root) { "/Users/test/myapp" } |
109 | | - let(:shakapacker_config) { double(source_path: "#{rails_root}/client/app", source_entry_path: "packs") } |
| 109 | + let(:shakapacker_config) do |
| 110 | + instance_double(Shakapacker::Configuration, source_path: "#{rails_root}/client/app", |
| 111 | + source_entry_path: "packs") |
| 112 | + end |
110 | 113 |
|
111 | 114 | before do |
112 | | - shakapacker_module = double("Shakapacker", config: shakapacker_config) |
| 115 | + shakapacker_module = instance_double(Shakapacker, config: shakapacker_config) |
113 | 116 | stub_const("Shakapacker", shakapacker_module) |
114 | 117 | allow(doctor).to receive(:require).with("shakapacker").and_return(true) |
115 | | - allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js") |
| 118 | + allow(doctor).to receive(:server_bundle_filename).and_return("server-bundle.js") |
116 | 119 | allow(Dir).to receive(:pwd).and_return(rails_root) |
117 | 120 | end |
118 | 121 |
|
|
125 | 128 | context "when Shakapacker gem returns nested absolute paths" do |
126 | 129 | let(:rails_root) { "/Users/test/myapp" } |
127 | 130 | let(:shakapacker_config) do |
128 | | - double(source_path: "#{rails_root}/client/app", source_entry_path: "#{rails_root}/client/app/packs") |
| 131 | + instance_double(Shakapacker::Configuration, source_path: "#{rails_root}/client/app", |
| 132 | + source_entry_path: "#{rails_root}/client/app/packs") |
129 | 133 | end |
130 | 134 |
|
131 | 135 | before do |
132 | | - shakapacker_module = double("Shakapacker", config: shakapacker_config) |
| 136 | + shakapacker_module = instance_double(Shakapacker, config: shakapacker_config) |
133 | 137 | stub_const("Shakapacker", shakapacker_module) |
134 | 138 | allow(doctor).to receive(:require).with("shakapacker").and_return(true) |
135 | | - allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js") |
| 139 | + allow(doctor).to receive(:server_bundle_filename).and_return("server-bundle.js") |
136 | 140 | allow(Dir).to receive(:pwd).and_return(rails_root) |
137 | 141 | end |
138 | 142 |
|
|
145 | 149 | context "when Shakapacker gem is not available" do |
146 | 150 | before do |
147 | 151 | allow(doctor).to receive(:require).with("shakapacker").and_raise(LoadError) |
148 | | - allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js") |
| 152 | + allow(doctor).to receive(:server_bundle_filename).and_return("server-bundle.js") |
149 | 153 | end |
150 | 154 |
|
151 | 155 | it "uses default path" do |
|
155 | 159 | end |
156 | 160 | end |
157 | 161 |
|
158 | | - describe "#get_server_bundle_filename" do |
| 162 | + describe "#server_bundle_filename" do |
159 | 163 | context "when react_on_rails.rb has custom filename" do |
160 | 164 | let(:initializer_content) do |
161 | 165 | 'config.server_bundle_js_file = "custom-server-bundle.js"' |
|
167 | 171 | end |
168 | 172 |
|
169 | 173 | it "extracts filename from initializer" do |
170 | | - filename = doctor.send(:get_server_bundle_filename) |
| 174 | + filename = doctor.send(:server_bundle_filename) |
171 | 175 | expect(filename).to eq("custom-server-bundle.js") |
172 | 176 | end |
173 | 177 | end |
|
178 | 182 | end |
179 | 183 |
|
180 | 184 | it "returns default filename" do |
181 | | - filename = doctor.send(:get_server_bundle_filename) |
| 185 | + filename = doctor.send(:server_bundle_filename) |
182 | 186 | expect(filename).to eq("server-bundle.js") |
183 | 187 | end |
184 | 188 | end |
185 | 189 | end |
186 | 190 | end |
187 | 191 | end |
188 | | - |
189 | | -# rubocop:enable RSpec/VerifiedDoubles |
|
0 commit comments