Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails main build #2685

Merged
merged 7 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ jobs:
include:
# Edge Rails (7.1) builds >= 2.7
- ruby: 3.2
allow_failure: true
env:
RAILS_VERSION: 'main'
- ruby: 3.1
allow_failure: true
env:
RAILS_VERSION: 'main'
- ruby: '3.0'
allow_failure: true
env:
RAILS_VERSION: 'main'
- ruby: 2.7
allow_failure: true
env:
RAILS_VERSION: 'main'

Expand Down
7 changes: 5 additions & 2 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ end
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
gem 'sqlite3', '~> 1.4', platforms: [:ruby]

# Due to capybara strings issue
gem 'puma', '< 6.0.0'
if RUBY_VERSION.to_f < 2.7
gem 'puma', '< 6.0.0'
else
gem 'puma'
end

case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
when /main/
Expand Down
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ end
namespace :smoke do
desc "create a new example app with generated specs and run them"
task app: ["clobber:app", "generate:app", "generate:stuff", :smoke]

desc "run RSPEC_OPTS environment variable in the example app for local dev"
task :rspec do
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}"
end
end

desc 'clobber generated files'
Expand Down Expand Up @@ -129,6 +134,11 @@ namespace :no_active_record do
"no_active_record:generate:stuff",
"no_active_record:smoke",
]

desc "run RSPEC_OPTS environment variable in the example app for local dev"
task :rspec do
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}", app_dir: example_app_dir
end
end

desc "remove the old non-ActiveRecord app"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ def save(*)
self.class.all << self
true
end
alias :save! :save

def destroy
self.class.all.delete(self)
true
end
alias :destroy! :destroy

def reload(*)
self
Expand Down
28 changes: 20 additions & 8 deletions lib/rspec/rails/example/view_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,26 @@ def view
_view
end

# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
if ::Rails.version.to_f >= 7.1
# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.send(:initialize_copy, ActionView::PathSet.new([StubResolverCache.resolver_for(hash)] + view.view_paths.paths))
end
else
# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
end
end

# Provides access to the params hash that will be available within the
Expand Down
50 changes: 36 additions & 14 deletions lib/rspec/rails/fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,50 @@ def run_in_transaction?
module Fixtures
extend ActiveSupport::Concern

# rubocop:disable Metrics/BlockLength
class_methods do
def fixtures(*args)
orig_methods = private_instance_methods
super.tap do
new_methods = private_instance_methods - orig_methods
new_methods.each do |method_name|
proxy_method_warning_if_called_in_before_context_scope(method_name)
if ::Rails.version.to_f >= 7.1
def fixtures(*args)
super.tap do
fixture_sets.each_key do |fixture_name|
proxy_method_warning_if_called_in_before_context_scope(fixture_name)
end
end
end

def proxy_method_warning_if_called_in_before_context_scope(fixture_name)
define_method(fixture_name) do |*args, **kwargs, &blk|
if RSpec.current_scope == :before_context_hook
RSpec.warn_with("Calling fixture method in before :context ")
else
access_fixture(fixture_name, *args, **kwargs, &blk)
end
end
end
else
def fixtures(*args)
orig_methods = private_instance_methods
super.tap do
new_methods = private_instance_methods - orig_methods
new_methods.each do |method_name|
proxy_method_warning_if_called_in_before_context_scope(method_name)
end
end
end
end

def proxy_method_warning_if_called_in_before_context_scope(method_name)
orig_implementation = instance_method(method_name)
define_method(method_name) do |*args, &blk|
if RSpec.current_scope == :before_context_hook
RSpec.warn_with("Calling fixture method in before :context ")
else
orig_implementation.bind(self).call(*args, &blk)
def proxy_method_warning_if_called_in_before_context_scope(method_name)
orig_implementation = instance_method(method_name)
define_method(method_name) do |*args, &blk|
if RSpec.current_scope == :before_context_hook
RSpec.warn_with("Calling fixture method in before :context ")
else
orig_implementation.bind(self).call(*args, &blk)
end
end
end
end
end
# rubocop:enable Metrics/BlockLength
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/rails/example/view_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _view; end
Class.new do
include ViewExampleGroup::ExampleMethods
def _view
@_view ||= Struct.new(:view_paths).new(['some-path'])
@_view ||= Struct.new(:view_paths).new(ActionView::PathSet.new(['some-path']))
end
end
end
Expand Down