Skip to content

Commit 7e96f46

Browse files
Define methods in stubbed ReactOnRailsPro::Helper module
Instead of using allow().to receive(), define the actual methods in the stubbed module so RSpec's verifying doubles work properly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e03dd57 commit 7e96f46

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,35 @@ def self.configuration
3333
end
3434
end)
3535

36-
stub_const("ReactOnRailsPro::Helper", Module.new)
37-
allow(ReactOnRailsPro::Helper).to receive(:enhance_component_script_data) do |args|
38-
if args[:render_options].immediate_hydration
39-
dom_id = args[:render_options].dom_id
40-
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
41-
"ReactOnRails.reactOnRailsComponentLoaded('#{dom_id}');\n </script>"
42-
{
43-
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
44-
additional_scripts: [script_tag]
45-
}
46-
else
47-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
36+
stub_const("ReactOnRailsPro::Helper", Module.new do
37+
def self.enhance_component_script_data(args)
38+
if args[:render_options].immediate_hydration
39+
dom_id = args[:render_options].dom_id
40+
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
41+
"ReactOnRails.reactOnRailsComponentLoaded('#{dom_id}');\n </script>"
42+
{
43+
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
44+
additional_scripts: [script_tag]
45+
}
46+
else
47+
{ script_attrs: args[:script_attrs], additional_scripts: [] }
48+
end
4849
end
49-
end
50-
allow(ReactOnRailsPro::Helper).to receive(:enhance_store_script_data) do |args|
51-
if args[:redux_store_data][:immediate_hydration]
52-
store_name = args[:redux_store_data][:store_name]
53-
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
54-
"ReactOnRails.reactOnRailsStoreLoaded('#{store_name}');\n </script>"
55-
{
56-
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
57-
additional_scripts: [script_tag]
58-
}
59-
else
60-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
50+
51+
def self.enhance_store_script_data(args)
52+
if args[:redux_store_data][:immediate_hydration]
53+
store_name = args[:redux_store_data][:store_name]
54+
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
55+
"ReactOnRails.reactOnRailsStoreLoaded('#{store_name}');\n </script>"
56+
{
57+
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
58+
additional_scripts: [script_tag]
59+
}
60+
else
61+
{ script_attrs: args[:script_attrs], additional_scripts: [] }
62+
end
6163
end
62-
end
64+
end)
6365
end
6466

6567
let(:hash) do

0 commit comments

Comments
 (0)