Skip to content

Only include Minitest assertions when RSpec is configured to use them #2639

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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
### Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.1...main)

Breaking Changes:

* Only include Minitest assertions when RSpec is configured to use them. (Phil Pirozhkov, #????)

Bug Fixes:

* Fix ActionView::PathSet when `render_views` is off for Rails 7.1.
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/example/rails_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module RailsExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::MinitestLifecycleAdapter
include RSpec::Rails::MinitestAssertionAdapter
include RSpec::Rails::MinitestAssertionAdapter if defined?(::RSpec::Core::MinitestAssertionsAdapter)
include RSpec::Rails::FixtureSupport
include RSpec::Rails::TaggedLoggingAdapter if ::Rails::VERSION::MAJOR >= 7
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module FixtureSupport
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::MinitestLifecycleAdapter
include RSpec::Rails::MinitestAssertionAdapter
include RSpec::Rails::MinitestAssertionAdapter if defined?(::RSpec::Core::MinitestAssertionsAdapter)
include ActiveRecord::TestFixtures

# @private prevent ActiveSupport::TestFixtures to start a DB transaction.
Expand Down
60 changes: 60 additions & 0 deletions snippets/with_minitest_expectation_framework.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
if __FILE__ =~ /^snippets/
fail "Snippets are supposed to be run from their own directory to avoid side " \
"effects as e.g. the root `Gemfile`, or `spec/spec_helpers.rb` to be " \
"loaded by the root `.rspec`."
end

# We opt-out from using RubyGems, but `bundler/inline` requires it
require 'rubygems'

require "bundler/inline"

# We pass `false` to `gemfile` to skip the installation of gems,
# because it may install versions that would conflict with versions
# from the main `Gemfile.lock`.
gemfile(false) do
source "https://rubygems.org"

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

# Those Gemfiles carefully pick the right versions depending on
# settings in the ENV, `.rails-version` and `maintenance-branch`.
Dir.chdir('..') do
# This Gemfile expects `maintenance-branch` file to be present
# in the current directory.
eval_gemfile 'Gemfile-rspec-dependencies'
# This Gemfile expects `.rails-version` file
eval_gemfile 'Gemfile-rails-dependencies'
end

gem "rspec-rails", path: "../"
end

# Run specs at exit
require "rspec/autorun"

# This snippet describes the case when ActiveRecord is loaded, but
# `use_active_record` is set to `false` in RSpec configuration.

# RSpec configuration
RSpec.configure do |config|
config.expect_with :minitest
config.expect_with :rspec
end

# Typically, rails_helper is loading spec_helper before loading rspec-rails,
# so by the time rspec-rails is loaded, expectation framework is configured.

# Initialization
require "active_record/railtie"
require "rspec/rails"

# This connection will do for database-independent bug reports
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

# Rails project specs
RSpec.describe 'with Minitest assertions', type: :model do
it 'allows using Minitest assertions' do
assert_equal 1, 1
end
end
61 changes: 61 additions & 0 deletions snippets/without_minitest_expectation_framework.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
if __FILE__ =~ /^snippets/
fail "Snippets are supposed to be run from their own directory to avoid side " \
"effects as e.g. the root `Gemfile`, or `spec/spec_helpers.rb` to be " \
"loaded by the root `.rspec`."
end

# We opt-out from using RubyGems, but `bundler/inline` requires it
require 'rubygems'

require "bundler/inline"

# We pass `false` to `gemfile` to skip the installation of gems,
# because it may install versions that would conflict with versions
# from the main `Gemfile.lock`.
gemfile(false) do
source "https://rubygems.org"

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

# Those Gemfiles carefully pick the right versions depending on
# settings in the ENV, `.rails-version` and `maintenance-branch`.
Dir.chdir('..') do
# This Gemfile expects `maintenance-branch` file to be present
# in the current directory.
eval_gemfile 'Gemfile-rspec-dependencies'
# This Gemfile expects `.rails-version` file
eval_gemfile 'Gemfile-rails-dependencies'
end

gem "rspec-rails", path: "../"
end

# Run specs at exit
require "rspec/autorun"

# This snippet describes the case when ActiveRecord is loaded, but
# `use_active_record` is set to `false` in RSpec configuration.

# RSpec configuration
RSpec.configure do |config|
config.expect_with :rspec
end

# Typically, rails_helper is loading spec_helper before loading rspec-rails,
# so by the time rspec-rails is loaded, expectation framework is configured.

# Initialization
require "active_record/railtie"
require "rspec/rails"

# This connection will do for database-independent bug reports
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

# Rails project specs
RSpec.describe 'without Minitest assertions', type: :model do
it 'provides no Minitest assertions' do
expect {
assert_equal 1, 1
}.to raise_error(NoMethodError, /undefined method `assert_equal' for/)
end
end