Skip to content

Repro name scope error in a Rails file app #2445

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions lib/rspec/rails/fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ module FixtureSupport
include RSpec::Rails::MinitestAssertionAdapter
include ActiveRecord::TestFixtures

if ::Rails.version.to_f >= 6.1
def name
@example
end
end

included do
if RSpec.configuration.use_active_record?
include Fixtures
Expand Down Expand Up @@ -51,12 +57,6 @@ def proxy_method_warning_if_called_in_before_context_scope(method_name)
end
end

if ::Rails.version.to_f >= 6.1
# @private return the example name for TestFixtures
def name
@example
end
end
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/rspec/rails/features/rails_app/partial_active_record_false.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "bundler/inline"

gemfile(true) do
source "https://rubygems.org"

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem "rails", (ENV["RAILS_VERSION"] || "~> 6.0.0")
gem "rspec-rails", path: "./"
gem "sqlite3"
gem "ammeter"
end

require "active_record/railtie"

require "ammeter"
require "rspec/autorun"
require "rspec/rails"

class Command
end

RSpec.configure do |config|
config.use_active_record = false
end

RSpec.describe Command do
it 'should not break' do
Command.new
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
RSpec.describe 'Rails app with use_active_record = false but active record railties loaded' do
it 'properly handles name scope in fixture_support' do
cmd = 'ruby spec/rspec/rails/features/rails_app/partial_active_record_false.rb'
cmd_status = ruby_script_runner(cmd)
expect(cmd_status[:stdout].last&.chomp).to eq("1 example, 0 failures")
expect(cmd_status[:exitstatus]).to eq(0)
end

def ruby_script_runner(cmd)
require 'open3'
cmd_status = { stdout: [], exitstatus: nil }
Open3.popen2(cmd) do |_stdin, stdout, wait_thr|
frame_stdout do
while line = stdout.gets
puts "| #{line}"
cmd_status[:stdout] << line if line =~ /\d+ (example|examples), \d+ failure/
end
end
cmd_status[:exitstatus] = wait_thr.value.exitstatus
end
cmd_status
end

def frame_stdout
puts
puts '-' * 50
yield
puts '-' * 50
end
end