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

Prepare changes for 7.0.0 #2788

Merged
merged 8 commits into from
Sep 2, 2024
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
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ jobs:
env:
RAILS_VERSION: '~> 7.0.0'

# Rails 6.1 builds >= 2.5
- ruby: 3.1
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: '3.0'
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.7
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.6
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.5
env:
RAILS_VERSION: '~> 6.1.0'

env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 0 additions & 5 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<!---
This file was generated on 2023-04-16T20:53:24+01:00 from the rspec-dev repo.
DO NOT modify it by hand as your changes will get lost the next time it is generated.
-->

# Contributor Code of Conduct

For the purpose of building a welcoming, harassment-free community that
Expand Down
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.5...main)
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.0...main)

Enhancements:

Expand Down
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ detailed explanations of how the application is supposed to behave,
expressed in plain English.

According to [RSpec Rails new versioning strategy][] use:
* **[`rspec-rails` 6.x][]** for Rails 6.1 or 7.x.
* **[`rspec-rails` 7.x][]** for Rails 7.x.
* **[`rspec-rails` 6.x][]** for Rails 6.1.
* **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
Expand All @@ -26,20 +27,21 @@ According to [RSpec Rails new versioning strategy][] use:
[`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
[`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
[`rspec-rails` 7.x]: https://github.com/rspec/rspec-rails/tree/7-0-maintenance
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md

## Installation

**IMPORTANT** This README / branch refers to the current development build.
See the [`6-1-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/6-1-maintenance) if you want or require the latest stable release.
See the [`7-0-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/7-0-maintenance) if you want or require the latest stable release.

1. Add `rspec-rails` to **both** the `:development` and `:test` groups
of your app’s `Gemfile`:

```ruby
# Run against this stable release
group :development, :test do
gem 'rspec-rails', '~> 6.1.0'
gem 'rspec-rails', '~> 7.0.0'
end

# Or, run against the main branch
Expand Down Expand Up @@ -86,7 +88,7 @@ read the [`rspec-rails` upgrade notes][] to find out what to watch out for.

Be sure to check the general [RSpec upgrade notes][] as well.

[`rspec-rails` upgrade notes]: https://rspec.info/features/6-0/rspec-rails/upgrade
[`rspec-rails` upgrade notes]: https://rspec.info/features/7-0/rspec-rails/upgrade
[RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/

## Usage
Expand Down Expand Up @@ -208,22 +210,22 @@ to test the various parts of a Rails system:
Follow the links above for examples of how each matcher is used.

[the matchers that come standard in RSpec]: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers
[`be_a_new`]: https://rspec.info/features/6-0/rspec-rails/matchers/new-record-matcher
[`render_template`]: https://rspec.info/features/6-0/rspec-rails/matchers/render-template-matcher
[`redirect_to`]: https://rspec.info/features/6-0/rspec-rails/matchers/redirect-to-matcher
[`route_to`]: https://rspec.info/features/6-0/rspec-rails/routing-specs/route-to-matcher
[`be_routable`]: https://rspec.info/features/6-0/rspec-rails/routing-specs/be-routable-matcher
[`have_http_status`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-http-status-matcher
[`match_array`]: https://rspec.info/features/6-0/rspec-rails/matchers/relation-match-array
[`have_been_enqueued`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-been-enqueued-matcher
[`have_enqueued_job`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-enqueued-job-matcher
[`be_a_new`]: https://rspec.info/features/7-0/rspec-rails/matchers/new-record-matcher
[`render_template`]: https://rspec.info/features/7-0/rspec-rails/matchers/render-template-matcher
[`redirect_to`]: https://rspec.info/features/7-0/rspec-rails/matchers/redirect-to-matcher
[`route_to`]: https://rspec.info/features/7-0/rspec-rails/routing-specs/route-to-matcher
[`be_routable`]: https://rspec.info/features/7-0/rspec-rails/routing-specs/be-routable-matcher
[`have_http_status`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-http-status-matcher
[`match_array`]: https://rspec.info/features/7-0/rspec-rails/matchers/relation-match-array
[`have_been_enqueued`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-been-enqueued-matcher
[`have_enqueued_job`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-enqueued-job-matcher

### What else does RSpec Rails add?

For a comprehensive look at RSpec Rails’ features,
read the [official Cucumber documentation][].

[official Cucumber documentation]: https://rspec.info/features/6-0/rspec-rails
[official Cucumber documentation]: https://rspec.info/features/7-0/rspec-rails

## What tests should I write?

Expand Down Expand Up @@ -268,20 +270,20 @@ RSpec.describe User, type: :model do
...
```

[request]: https://rspec.info/features/6-0/rspec-rails/request-specs/request-spec
[feature]: https://rspec.info/features/6-0/rspec-rails/feature-specs/feature-spec
[system]: https://rspec.info/features/6-0/rspec-rails/system-specs/system-specs
[model]: https://rspec.info/features/6-0/rspec-rails/model-specs
[controller]: https://rspec.info/features/6-0/rspec-rails/controller-specs
[mailer]: https://rspec.info/features/6-0/rspec-rails/mailer-specs
[job]: https://rspec.info/features/6-0/rspec-rails/job-specs/job-spec
[view]: https://rspec.info/features/6-0/rspec-rails/view-specs/view-spec
[routing]: https://rspec.info/features/6-0/rspec-rails/routing-specs
[helper]: https://rspec.info/features/6-0/rspec-rails/helper-specs/helper-spec
[request]: https://rspec.info/features/7-0/rspec-rails/request-specs/request-spec
[feature]: https://rspec.info/features/7-0/rspec-rails/feature-specs/feature-spec
[system]: https://rspec.info/features/7-0/rspec-rails/system-specs/system-specs
[model]: https://rspec.info/features/7-0/rspec-rails/model-specs
[controller]: https://rspec.info/features/7-0/rspec-rails/controller-specs
[mailer]: https://rspec.info/features/7-0/rspec-rails/mailer-specs
[job]: https://rspec.info/features/7-0/rspec-rails/job-specs/job-spec
[view]: https://rspec.info/features/7-0/rspec-rails/view-specs/view-spec
[routing]: https://rspec.info/features/7-0/rspec-rails/routing-specs
[helper]: https://rspec.info/features/7-0/rspec-rails/helper-specs/helper-spec
[`ActionDispatch::IntegrationTest`]: https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
[`ActionDispatch::SystemTestCase`]: https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
[`ActionController::TestCase`]: https://api.rubyonrails.org/classes/ActionController/TestCase.html
[in the appropriate folder]: https://rspec.info/features/6-0/rspec-rails/directory-structure
[in the appropriate folder]: https://rspec.info/features/7-0/rspec-rails/directory-structure

### System specs, feature specs, request specs–what’s the difference?

Expand Down
4 changes: 2 additions & 2 deletions features/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Getting Started

Install Rails 6
Install Rails

```console
$ gem install rails -v "~> 6.0.0"
$ gem install rails -v "~> 7.2.0"
```

### Generate an app
Expand Down
7 changes: 4 additions & 3 deletions features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ check their documentation for help as well.

## Rails

rspec-rails 6 supports Rails 6.1 to 7.0. For earlier versions of Rails, you
should use [rspec-rails-5](https://github.com/rspec/rspec-rails/tree/5-1-maintenance)
rspec-rails 7 supports Rails 7.0 to 7.2. For earlier versions of Rails, you
should use [rspec-rails-6](https://github.com/rspec/rspec-rails/tree/5-1-maintenance)
for Rails 6.1, [rspec-rails-5](https://github.com/rspec/rspec-rails/tree/5-1-maintenance)
for Rails 5.2 and 6.0, [rspec-rails-4](https://github.com/rspec/rspec-rails/tree/4-1-maintenance)
for Rails 5.x, and [rspec-rails 3](https://github.com/rspec/rspec-rails/tree/3-9-maintenance)
for even older versions.
Expand All @@ -33,7 +34,7 @@ Add rspec-rails to the :test and :development groups in the Gemfile:

```ruby
group :test, :development do
gem 'rspec-rails', '~> 6.0.0'
gem 'rspec-rails', '~> 7.0.0'
end
```

Expand Down
31 changes: 26 additions & 5 deletions features/upgrade/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
# Upgrading from rspec-rails 5.x to version 6
# Upgrading

RSpec Rails versions follow semantic versioning of x.y.z where:

- `x` is a major release containing breaking changes and support changes for Rails.
- `y` is a minor release which will contain only feature additions and bug fixes.
- `z` is a patch release which will contain only bug fixes for the minor levels currently supported version of Rails.

On new Rails minor releases we will usually release our own new minor version to support that version, occasionally
we will release a new major version instead to allow us to remove support for now unsupported versions of Rails
as defined by the Rails team themselves.

The RSpec team will only maintain the current major / minor version, although it is common for the `main` branch
to contain changes for the next upcoming version of Rails and usage of this branch directly is also supported.

RSpec Rails 6 is a major version under semantic versioning, it also follows our new versioning strategy for RSpec-Rails, which is to keep in step with Rails supported versions. Thus it supports 6.1 and 7.0. There are no changes required to upgrade to RSpec Rails 6 if you are using a supported version of Rails.
# Upgrading from rspec-rails 6.x to version 7

RSpec Rails 7 supports Rails versions 7.0, 7.1 and 7.2. There are no changes required to upgrade from 6.x to 7 for these versions of Rails,
but we encourage those doing multiple step upgrades to upgrade to Rails 7.1 and RSpec Rails 6.1.x before upgrading to Rails 7.2 and RSpec Rails 7.0.

If you are on Rails 6.1 you will need to keep using RSpec Rails 6.1.

# Upgrading from rspec-rails 5.x to version 6

If you are using an older version of Rails, you can use 5.x which hard supports 5.2 and 6.x.
RSpec Rails 6 supports Rails versions 6.1, 7.0 and 7.1. There are no changes required to upgrade from 5.x to 6 for these versions of Rails.

# Upgrading from rspec-rails 4.x to version 5

RSpec Rails 5 is a major version under semantic versioning, it also follows our new versioning strategy for RSpec-Rails, which is to keep in step with Rails supported versions. Thus it supports 5.2, 6.0 and 6.1. There are no changes required to upgrade to RSpec Rails 5 if you are using a supported version of Rails.
RSpec Rails 5 supports 5.2, 6.0 and 6.1. There are no changes required to upgrade from 4.x to 5 for these versions of Rails.

If you are using an older version of Rails, you can use 4.x which hard supports 5.0 and 5.1, and soft supports 4.2 (which is unmaintained).

# Upgrading from rspec-rails 3.x to version 4

RSpec Rails 4 is a major version under semantic versioning, it allowed us to change the supported Rails versions to 5 and 6 only. There are no changes required to upgrade to RSpec Rails 4 if you are using Rails 5 or 6.
RSpec Rails 4 was the first version to be released out of step with rspec, as a major version under semantic versioning, it allowed us to change the supported Rails versions to 5 and 6 only.
There are no changes required to upgrade to RSpec Rails 4 from 3.x if you are using Rails 5 or 6.

If you are using Rails 4.2 you can use RSpec Rails 4, but note that support for it is not maintained, we consider this a breaking change hence the version change, and you must be on Ruby 2.2 as a minimum.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# end
#
# The different available types are documented in the features, such as in
# https://rspec.info/features/6-0/rspec-rails
# https://rspec.info/features/7-0/rspec-rails
config.infer_spec_type_from_file_location!

# Filter lines from Rails gems in backtraces.
Expand Down
3 changes: 1 addition & 2 deletions lib/rspec/rails/fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module FixtureSupport
include ActiveRecord::TestFixtures

# @private prevent ActiveSupport::TestFixtures to start a DB transaction.
# Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after
# and let(:method_name) before Rails 6.1.
# Monkey patched to avoid collisions with 'let(:name)' since Rails 6.1
def run_in_transaction?
current_example_name = (RSpec.current_example && RSpec.current_example.metadata[:description])
use_transactional_tests && !self.class.uses_transaction?(current_example_name)
Expand Down
17 changes: 3 additions & 14 deletions lib/rspec/rails/matchers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def base_job_message(job)
msg_parts << "on queue #{job[:queue]}" if job[:queue]
msg_parts << "at #{Time.at(job[:at])}" if job[:at]
msg_parts <<
if fetch_priority(job)
"with priority #{fetch_priority(job)}"
if job[:priority]
"with priority #{job[:priority]}"
else
"with no priority specified"
end
Expand All @@ -167,17 +167,6 @@ def job_matches?(job)
@job ? @job == job[:job] : true
end

# Rails 6.1 serializes the priority with a string key
if ::Rails.version.to_f >= 7
def fetch_priority(job)
job[:priority]
end
else
def fetch_priority(job)
job['priority']
end
end

def arguments_match?(job)
if @args.any?
args = serialize_and_deserialize_arguments(@args)
Expand Down Expand Up @@ -218,7 +207,7 @@ def queue_match?(job)
def priority_match?(job)
return true unless @priority

@priority == fetch_priority(job)
@priority == job[:priority]
end

def at_match?(job)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/have_http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def set_expected_code!
# expect(response).to have_http_status(:redirect)
#
# @see RSpec::Rails::Matchers#have_http_status
# @see https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
# @see https://github.com/rails/rails/blob/7-2-stable/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
class GenericStatus < RSpec::Rails::Matchers::BaseMatcher
include HaveHttpStatus

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Rails
# Version information for RSpec Rails.
module Version
# Current version of RSpec Rails, in semantic versioning format.
STRING = '6.2.0.pre'
STRING = '7.0.0.pre'
end
end
end
4 changes: 2 additions & 2 deletions rspec-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/rspec/rspec-rails"
s.summary = "RSpec for Rails"
s.description = "rspec-rails integrates the Rails testing helpers into RSpec."
s.required_ruby_version = ">= 2.5.0"
s.required_ruby_version = ">= 2.7.0"

s.metadata = {
'bug_tracker_uri' => 'https://github.com/rspec/rspec-rails/issues',
Expand All @@ -33,7 +33,7 @@ Gem::Specification.new do |s|
s.cert_chain = [File.expand_path('~/.gem/rspec-gem-public_cert.pem')]
end

version_string = ['>= 6.1']
version_string = ['>= 7.0']

s.add_runtime_dependency 'actionpack', version_string
s.add_runtime_dependency 'activesupport', version_string
Expand Down
3 changes: 0 additions & 3 deletions snippets/avoid_fixture_name_collision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
RSpec.describe 'Foo' do
subject { true }

# Rails 6.1 and after
let(:name) { raise "Should never raise" }
# Before Rails 6.1
let(:method_name) { raise "Should never raise" }

it { is_expected.to be_truthy }
end
7 changes: 1 addition & 6 deletions snippets/include_activesupport_testing_tagged_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ def perform

describe 'error raised in perform_enqueued_jobs with block' do
it 'raises the explicitly thrown error' do
# Rails 6.1+ wraps unexpected errors in tests
expected_error = if Rails::VERSION::STRING.to_f >= 6.1
Minitest::UnexpectedError.new(TestError)
else
TestError
end
expected_error = Minitest::UnexpectedError.new(TestError)

expect { perform_enqueued_jobs { TestJob.perform_later } }
.to raise_error(expected_error)
Expand Down
7 changes: 1 addition & 6 deletions spec/rspec/rails/example/controller_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ def my_helper
end
end

# Rails 6.1 removes config from ./activerecord/lib/active_record/test_fixtures.rb
if respond_to?(:config)
config.include mod
else
ActiveRecord::Base.include mod
end
ActiveRecord::Base.include mod

group.class_exec do
let(:my_helper) { "my_value" }
Expand Down