Skip to content

Commit 5e2e23e

Browse files
committed
Merge pull request #2685 from rspec/fix-rails-main-build
Fix Rails `main` build
1 parent bb5718d commit 5e2e23e

File tree

6 files changed

+74
-25
lines changed

6 files changed

+74
-25
lines changed

Gemfile-rails-dependencies

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ end
1414
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
1515
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
1616

17-
# Due to capybara strings issue
18-
gem 'puma', '< 6.0.0'
17+
if RUBY_VERSION.to_f < 2.7
18+
gem 'puma', '< 6.0.0'
19+
else
20+
gem 'puma'
21+
end
1922

2023
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
2124
when /main/

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ end
9595
namespace :smoke do
9696
desc "create a new example app with generated specs and run them"
9797
task app: ["clobber:app", "generate:app", "generate:stuff", :smoke]
98+
99+
desc "run RSPEC_OPTS environment variable in the example app for local dev"
100+
task :rspec do
101+
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}"
102+
end
98103
end
99104

100105
desc 'clobber generated files'
@@ -129,6 +134,11 @@ namespace :no_active_record do
129134
"no_active_record:generate:stuff",
130135
"no_active_record:smoke",
131136
]
137+
138+
desc "run RSPEC_OPTS environment variable in the example app for local dev"
139+
task :rspec do
140+
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}", app_dir: example_app_dir
141+
end
132142
end
133143

134144
desc "remove the old non-ActiveRecord app"

example_app_generator/no_active_record/app/models/in_memory/model.rb

+2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ def save(*)
7272
self.class.all << self
7373
true
7474
end
75+
alias :save! :save
7576

7677
def destroy
7778
self.class.all.delete(self)
7879
true
7980
end
81+
alias :destroy! :destroy
8082

8183
def reload(*)
8284
self

lib/rspec/rails/example/view_example_group.rb

+20-8
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,26 @@ def view
8282
_view
8383
end
8484

85-
# Simulates the presence of a template on the file system by adding a
86-
# Rails' FixtureResolver to the front of the view_paths list. Designed to
87-
# help isolate view examples from partials rendered by the view template
88-
# that is the subject of the example.
89-
#
90-
# stub_template("widgets/_widget.html.erb" => "This content.")
91-
def stub_template(hash)
92-
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
85+
if ::Rails.version.to_f >= 7.1
86+
# Simulates the presence of a template on the file system by adding a
87+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
88+
# help isolate view examples from partials rendered by the view template
89+
# that is the subject of the example.
90+
#
91+
# stub_template("widgets/_widget.html.erb" => "This content.")
92+
def stub_template(hash)
93+
view.view_paths.send(:initialize_copy, ActionView::PathSet.new([StubResolverCache.resolver_for(hash)] + view.view_paths.paths))
94+
end
95+
else
96+
# Simulates the presence of a template on the file system by adding a
97+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
98+
# help isolate view examples from partials rendered by the view template
99+
# that is the subject of the example.
100+
#
101+
# stub_template("widgets/_widget.html.erb" => "This content.")
102+
def stub_template(hash)
103+
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
104+
end
93105
end
94106

95107
# Provides access to the params hash that will be available within the

lib/rspec/rails/fixture_support.rb

+36-14
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,50 @@ def run_in_transaction?
3737
module Fixtures
3838
extend ActiveSupport::Concern
3939

40+
# rubocop:disable Metrics/BlockLength
4041
class_methods do
41-
def fixtures(*args)
42-
orig_methods = private_instance_methods
43-
super.tap do
44-
new_methods = private_instance_methods - orig_methods
45-
new_methods.each do |method_name|
46-
proxy_method_warning_if_called_in_before_context_scope(method_name)
42+
if ::Rails.version.to_f >= 7.1
43+
def fixtures(*args)
44+
super.tap do
45+
fixture_sets.each_key do |fixture_name|
46+
proxy_method_warning_if_called_in_before_context_scope(fixture_name)
47+
end
48+
end
49+
end
50+
51+
def proxy_method_warning_if_called_in_before_context_scope(fixture_name)
52+
define_method(fixture_name) do |*args, **kwargs, &blk|
53+
if RSpec.current_scope == :before_context_hook
54+
RSpec.warn_with("Calling fixture method in before :context ")
55+
else
56+
access_fixture(fixture_name, *args, **kwargs, &blk)
57+
end
58+
end
59+
end
60+
else
61+
def fixtures(*args)
62+
orig_methods = private_instance_methods
63+
super.tap do
64+
new_methods = private_instance_methods - orig_methods
65+
new_methods.each do |method_name|
66+
proxy_method_warning_if_called_in_before_context_scope(method_name)
67+
end
4768
end
4869
end
49-
end
5070

51-
def proxy_method_warning_if_called_in_before_context_scope(method_name)
52-
orig_implementation = instance_method(method_name)
53-
define_method(method_name) do |*args, &blk|
54-
if RSpec.current_scope == :before_context_hook
55-
RSpec.warn_with("Calling fixture method in before :context ")
56-
else
57-
orig_implementation.bind(self).call(*args, &blk)
71+
def proxy_method_warning_if_called_in_before_context_scope(method_name)
72+
orig_implementation = instance_method(method_name)
73+
define_method(method_name) do |*args, &blk|
74+
if RSpec.current_scope == :before_context_hook
75+
RSpec.warn_with("Calling fixture method in before :context ")
76+
else
77+
orig_implementation.bind(self).call(*args, &blk)
78+
end
5879
end
5980
end
6081
end
6182
end
83+
# rubocop:enable Metrics/BlockLength
6284
end
6385
end
6486
end

spec/rspec/rails/example/view_example_group_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _view; end
283283
Class.new do
284284
include ViewExampleGroup::ExampleMethods
285285
def _view
286-
@_view ||= Struct.new(:view_paths).new(['some-path'])
286+
@_view ||= Struct.new(:view_paths).new(ActionView::PathSet.new(['some-path']))
287287
end
288288
end
289289
end

0 commit comments

Comments
 (0)