Skip to content

Commit

Permalink
Add a file repro app to test the fix on fixture_support name
Browse files Browse the repository at this point in the history
  • Loading branch information
benoittgt committed Jan 14, 2021
1 parent 4e88eb3 commit c9132e0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
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

0 comments on commit c9132e0

Please sign in to comment.