@@ -10,12 +10,12 @@ module ReactOnRails
1010 # If rspec tests are run locally, we want to test both packers.
1111 # If rspec tests are run in CI, we want to test the packer specified in the CI_PACKER_VERSION environment variable.
1212 # Check script/convert and .github/workflows/rspec-package-specs.yml for more details.
13- PACKERS_TO_TEST = if ENV [ "CI_PACKER_VERSION" ] == "old"
13+ packers_to_test = if ENV [ "CI_PACKER_VERSION" ] == "old"
1414 [ "webpacker" ]
1515 elsif ENV [ "CI_PACKER_VERSION" ] == "new"
1616 [ "shakapacker" ]
1717 else
18- [ " shakapacker" , " webpacker" ]
18+ %w[ shakapacker webpacker ]
1919 end
2020
2121 shared_context "with packer enabled" do
@@ -36,8 +36,8 @@ module ReactOnRails
3636 shared_context "with shakapacker enabled" do
3737 before do
3838 # Mock that shakapacker is not installed, so webpacker will be used instead
39- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( true )
40- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( false )
39+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( true )
40+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( false )
4141 end
4242
4343 include_context "with packer enabled"
@@ -54,8 +54,8 @@ module ReactOnRails
5454 shared_context "with webpacker enabled" do
5555 before do
5656 # Mock that shakapacker is not installed, so webpacker will be used instead
57- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( false )
58- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( true )
57+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( false )
58+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( true )
5959 end
6060
6161 include_context "with packer enabled"
@@ -72,8 +72,8 @@ module ReactOnRails
7272 before do
7373 allow ( ReactOnRails ) . to receive_message_chain ( :configuration , :generated_assets_dir )
7474 . and_return ( "public/webpack/dev" )
75- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( false )
76- allow ( ReactOnRails :: Utils ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( false )
75+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "shakapacker" ) . and_return ( false )
76+ allow ( described_class ) . to receive ( :gem_available? ) . with ( "webpacker" ) . and_return ( false )
7777 end
7878
7979 it "does not use packer" do
@@ -128,25 +128,22 @@ def mock_dev_server_running
128128 allow ( Rails ) . to receive ( :root ) . and_return ( File . expand_path ( "." ) )
129129 described_class . instance_variable_set ( :@server_bundle_path , nil )
130130 described_class . instance_variable_set ( :@rsc_bundle_path , nil )
131+ ReactOnRails ::PackerUtils . instance_variables . each do |instance_variable |
132+ ReactOnRails ::PackerUtils . remove_instance_variable ( instance_variable )
133+ end
131134 end
132135
133136 after do
134137 described_class . instance_variable_set ( :@server_bundle_path , nil )
135138 described_class . instance_variable_set ( :@rsc_bundle_path , nil )
136139 end
137140
138- before :each do
139- ReactOnRails ::PackerUtils . instance_variables . each do |instance_variable |
140- ReactOnRails ::PackerUtils . remove_instance_variable ( instance_variable )
141- end
142- end
143-
144141 describe ".bundle_js_file_path" do
145142 subject do
146143 described_class . bundle_js_file_path ( "webpack-bundle.js" )
147144 end
148145
149- PACKERS_TO_TEST . each do |packer_type |
146+ packers_to_test . each do |packer_type |
150147 context "with #{ packer_type } enabled" , packer_type . to_sym do
151148 include_context "with #{ packer_type } enabled"
152149
@@ -210,9 +207,10 @@ def mock_dev_server_running
210207 end
211208 end
212209
213- PACKERS_TO_TEST . each do |packer_type |
210+ packers_to_test . each do |packer_type |
214211 describe ".server_bundle_js_file_path with #{ packer_type } enabled" do
215212 let ( :packer_public_output_path ) { Pathname . new ( "public/webpack/development" ) }
213+
216214 include_context "with #{ packer_type } enabled"
217215
218216 context "with server file not in manifest" , packer_type . to_sym do
@@ -275,6 +273,7 @@ def mock_dev_server_running
275273
276274 describe ".rsc_bundle_js_file_path with #{ packer_type } enabled" do
277275 let ( :packer_public_output_path ) { Pathname . new ( "public/webpack/development" ) }
276+
278277 include_context "with #{ packer_type } enabled"
279278
280279 context "with server file not in manifest" , packer_type . to_sym do
0 commit comments