Skip to content

Commit 8895b87

Browse files
committed
Add a file repro app to test the fix on fixture_support name
1 parent 4e88eb3 commit 8895b87

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

lib/rspec/rails/fixture_support.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ module FixtureSupport
99
include RSpec::Rails::MinitestAssertionAdapter
1010
include ActiveRecord::TestFixtures
1111

12+
if ::Rails.version.to_f >= 6.1
13+
def name
14+
@example
15+
end
16+
end
17+
1218
included do
1319
if RSpec.configuration.use_active_record?
1420
include Fixtures
@@ -51,12 +57,6 @@ def proxy_method_warning_if_called_in_before_context_scope(method_name)
5157
end
5258
end
5359

54-
if ::Rails.version.to_f >= 6.1
55-
# @private return the example name for TestFixtures
56-
def name
57-
@example
58-
end
59-
end
6060
end
6161
end
6262
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require "bundler/inline"
2+
3+
gemfile(true) do
4+
source "https://rubygems.org"
5+
6+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
7+
8+
gem "rails", (ENV["RAILS_VERSION"] || "~> 6.0.0")
9+
gem "rspec-rails", path: "./"
10+
gem "sqlite3"
11+
gem "ammeter"
12+
end
13+
14+
require "active_record/railtie"
15+
16+
require "ammeter"
17+
require "rspec/autorun"
18+
require "rspec/rails"
19+
20+
class Command
21+
end
22+
23+
RSpec.configure do |config|
24+
config.use_active_record = false
25+
end
26+
27+
RSpec.describe Command do
28+
it 'should not break' do
29+
Command.new
30+
end
31+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
RSpec.describe 'Rails app with use_active_record = false but active record railties loaded' do
2+
it 'properly handles name scope in fixture_support' do
3+
cmd = 'ruby spec/rspec/rails/features/rails_app/partial_active_record_false.rb'
4+
cmd_status = ruby_script_runner(cmd)
5+
expect(cmd_status[:stdout].last.chomp).to eq("1 example, 0 failures")
6+
expect(cmd_status[:exitstatus]).to eq(0)
7+
end
8+
9+
def ruby_script_runner(cmd)
10+
require 'open3'
11+
cmd_status = { stdout: [], exitstatus: nil }
12+
Open3.popen2(cmd) do |_stdin, stdout, wait_thr|
13+
frame_stdout do
14+
while line = stdout.gets
15+
puts "| #{line}"
16+
cmd_status[:stdout] << line if line =~ /\d+ (example|examples), \d+ failure/
17+
end
18+
end
19+
cmd_status[:exitstatus] = wait_thr.value.exitstatus
20+
end
21+
cmd_status
22+
end
23+
24+
def frame_stdout
25+
puts
26+
puts '-' * 50
27+
yield
28+
puts '-' * 50
29+
end
30+
end

0 commit comments

Comments
 (0)