Skip to content

Commit 6062707

Browse files
committed
refactor(test_helper) move WebpackerHelpers to module
1 parent 6d5ff63 commit 6062707

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

test/react/rails/webpacker_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'test_helper'
22

33

4-
when_webpacker_available do
4+
WebpackerHelpers.when_webpacker_available do
55
class ReactRailsWebpackerTest < ActionDispatch::IntegrationTest
66
include Capybara::DSL
77

@@ -10,7 +10,7 @@ class ReactRailsWebpackerTest < ActionDispatch::IntegrationTest
1010
end
1111

1212
teardown do
13-
clear_webpacker_packs
13+
WebpackerHelpers.clear_webpacker_packs
1414
end
1515

1616
test 'it mounts pages from the pack' do

test/support/webpacker_helpers.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module WebpackerHelpers
2+
module_function
3+
4+
def when_webpacker_available
5+
if defined?(Webpacker)
6+
clear_webpacker_packs
7+
Dir.chdir("./test/dummy") do
8+
Rake::Task['webpacker:compile'].invoke
9+
end
10+
# Reload cached JSON manifest:
11+
Webpacker::Manifest.load
12+
yield
13+
end
14+
end
15+
16+
def clear_webpacker_packs
17+
packs_directory = File.expand_path("../dummy/public/packs", __FILE__)
18+
FileUtils.rm_rf(packs_directory)
19+
end
20+
end

test/test_helper.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
require "capybara/poltergeist"
1616
Dummy::Application.load_tasks
1717

18+
support_path = File.expand_path("../support/*.rb", __FILE__)
19+
Dir.glob(support_path).each do |f|
20+
require(f)
21+
end
22+
1823
Capybara.javascript_driver = :poltergeist
1924
Capybara.app = Rails.application
2025

@@ -131,23 +136,6 @@ def when_sprockets_available
131136
end
132137
end
133138

134-
def when_webpacker_available
135-
if defined?(Webpacker)
136-
clear_webpacker_packs
137-
Dir.chdir("./test/dummy") do
138-
Rake::Task['webpacker:compile'].invoke
139-
end
140-
# Reload cached JSON manifest:
141-
Webpacker::Manifest.load
142-
yield
143-
end
144-
end
145-
146-
def clear_webpacker_packs
147-
packs_directory = File.expand_path("../dummy/public/packs", __FILE__)
148-
FileUtils.rm_rf(packs_directory)
149-
end
150-
151139
def fetch_asset_body(asset_logical_path)
152140
Rails.application.assets[asset_logical_path].to_s
153141
end

0 commit comments

Comments
 (0)