Skip to content

Commit 1bb4f35

Browse files
committed
Add with_inertia_config test helper and turn on :random order
1 parent c8f36c6 commit 1bb4f35

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

spec/inertia/sharing_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@
7070
end
7171

7272
context 'with deep merge configured as the default' do
73-
before {
74-
InertiaRails.configure { |config| config.deep_merge_shared_data = true }
75-
}
76-
after {
77-
InertiaRails.configure { |config| config.deep_merge_shared_data = false }
78-
}
73+
with_inertia_config deep_merge_shared_data: true
74+
7975
describe 'deep merging by default' do
8076
let(:props) { { nested: { goals: 100, assists: 200 } } }
8177
before { get merge_shared_path, headers: {'X-Inertia' => true} }

spec/inertia/ssr_spec.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33

44
RSpec.describe 'inertia ssr', type: :request do
55
context 'ssr is enabled' do
6-
before do
7-
InertiaRails.configure do |config|
8-
config.ssr_enabled = true
9-
config.ssr_url = 'ssr-url'
10-
config.version = '1.0'
11-
end
12-
end
6+
with_inertia_config ssr_enabled: true, ssr_url: 'ssr-url', version: '1.0'
137

148
context 'with a successful ssr response' do
159
before do

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
config.filter_run_when_matching :focus
99

10+
config.order = :random
11+
1012
config.expect_with :rspec do |c|
1113
c.syntax = :expect
1214
end

spec/support/helper_module.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22

33
module HelperModule
4+
def self.included(base)
5+
base.extend(ClassMethods)
6+
end
7+
48
def with_forgery_protection
59
orig = ActionController::Base.allow_forgery_protection
610
begin
@@ -20,4 +24,17 @@ def with_env(**env)
2024
ENV.replace(orig)
2125
end
2226
end
27+
28+
module ClassMethods
29+
def with_inertia_config(**props)
30+
around do |example|
31+
config = InertiaRails.configuration
32+
orig_options = config.send(:options).dup
33+
config.merge!(InertiaRails::Configuration.new(**props))
34+
example.run
35+
ensure
36+
config.instance_variable_set(:@options, orig_options)
37+
end
38+
end
39+
end
2340
end

0 commit comments

Comments
 (0)