rspec-rails 6.0.4 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecae469592630a6ecaaa39d6f2be0e2616cb2079c044bc390e548956b823d6bc
4
- data.tar.gz: f24952e5edf9bf57f6e8c94fced8c7b2d38938b4a1b250fa83043bf316c8de9c
3
+ metadata.gz: 4670e0b41ea2e22cb7a3fd5d28a421fe82fed0c591dbb245e011b497a1ac81f3
4
+ data.tar.gz: a3cf937f37a03c114b8397216d034eae1645ea8575906f6f5a444973a1626419
5
5
  SHA512:
6
- metadata.gz: e50c692c774cd0a874bedd667e7c0e3997236d43a74750efb6cc215a3019ce9a4babc5437a79825c43c885b70f1c3da9c90599ce1b0bf123ba1538e77cc7884e
7
- data.tar.gz: a148f034a8667af85e68c478849bd9ea33443567dec01335d0a83ad9fd44d63d7dd0780694ebaee55f2278add2fefa61032674e38dec865cf01ee1205e13d1e9
6
+ metadata.gz: dd476082c87a5735996ce66d0efcf7bb1f5860b81118e05b71388872b50a11bb28d6fb981a23aed71597c45585244aa4c5d53a45c6d8500a751e36fa8d4f3039
7
+ data.tar.gz: b996549661e01669b60767064e24b7dd7836ce79db985048856d7c98c9ed5892d04551050dbaa3727c2a358026990611559144c824f198a85b7c78c3651e3401
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,25 @@
1
+ ### Development
2
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.4...main)
3
+
4
+ ### 6.1.0 / 2023-11-21
5
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.4...v6.1.0)
6
+
7
+ Enhancements:
8
+
9
+ * Support for Rails 7.1
10
+ * Minor tweak to generated `rails_helper.rb` to use `Rails.root.join`.
11
+ (@masato-bkn, Ryo Nakamura, #2640, #2678)
12
+ * Add `RSpec::Rails::Configuration.fixture_paths` configuration to support
13
+ the matching change to `ActiveRecord::TestFixtures`, previous singular
14
+ form is deprecated and will be removed in Rails 7.2. (Juan Gueçaimburu, #2673)
15
+ * Add `send_email` matcher to match emails rather than specific jobs.
16
+ (Andrei Kaleshka, #2670)
17
+ * When using `render` in view specs, `:locals` will now be merged into the
18
+ default implicit template, allowing `render locals: {...}` style calls.
19
+ (Jon Rowe, #2686)
20
+ * Add support for `Rails.config.action_mailer.preview_paths` on Rails 7.1/
21
+ (Jon Rowe, #2706)
22
+
1
23
  ### 6.0.4 / 2023-11-21
2
24
  [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.3...v6.0.4)
3
25
 
data/README.md CHANGED
@@ -25,13 +25,14 @@ According to [RSpec Rails new versioning strategy][] use:
25
25
  [`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
26
26
  [`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
27
27
  [`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
28
- [`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-0-maintenance
28
+ [`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
29
29
  [RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
30
30
 
31
31
  ## Installation
32
32
 
33
- **IMPORTANT** This README / branch refers to the current development build.
34
- See the [`6-0-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/6-0-maintenance) if you want or require the latest stable release.
33
+ **IMPORTANT** This README / branch refers to the 6.1.x stable release series, only bugfixes from this series will
34
+ be added here. See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) if you want or
35
+ require the latest unstable features.
35
36
 
36
37
  1. Add `rspec-rails` to **both** the `:development` and `:test` groups
37
38
  of your app’s `Gemfile`:
@@ -39,7 +40,7 @@ See the [`6-0-maintenance` branch on Github](https://github.com/rspec/rspec-rail
39
40
  ```ruby
40
41
  # Run against this stable release
41
42
  group :development, :test do
42
- gem 'rspec-rails', '~> 6.0.0'
43
+ gem 'rspec-rails', '~> 6.1.0'
43
44
  end
44
45
 
45
46
  # Or, run against the main branch
@@ -20,7 +20,7 @@ require 'rspec/rails'
20
20
  # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
21
  # require only the support files necessary.
22
22
  #
23
- # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
23
+ # Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }
24
24
 
25
25
  <% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
26
26
  # Checks for pending migrations and applies them before tests are run.
@@ -34,7 +34,13 @@ end
34
34
  RSpec.configure do |config|
35
35
  <% if RSpec::Rails::FeatureCheck.has_active_record? -%>
36
36
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
37
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
37
+ <% if ::Rails::VERSION::STRING < "7.1.0" -%>
38
+ config.fixture_path = Rails.root.join('spec/fixtures')
39
+ <% else -%>
40
+ config.fixture_paths = [
41
+ Rails.root.join('spec/fixtures')
42
+ ]
43
+ <% end -%>
38
44
 
39
45
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
40
46
  # examples within a transaction, remove the following line or assign false
@@ -52,7 +58,7 @@ RSpec.configure do |config|
52
58
  # note if you'd prefer not to run each example within a transaction, you
53
59
  # should set use_transactional_fixtures to false.
54
60
  #
55
- # config.fixture_path = "#{::Rails.root}/spec/fixtures"
61
+ # config.fixture_path = Rails.root.join('spec/fixtures')
56
62
  # config.use_transactional_fixtures = true
57
63
 
58
64
  <% end -%>
@@ -57,7 +57,7 @@ module RSpec
57
57
  end
58
58
 
59
59
  # @private
60
- def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
60
+ def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
61
61
  config.backtrace_exclusion_patterns << /vendor\//
62
62
  config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
63
63
 
@@ -69,7 +69,13 @@ module RSpec
69
69
  config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
70
70
  config.add_setting :use_instantiated_fixtures
71
71
  config.add_setting :global_fixtures
72
- config.add_setting :fixture_path
72
+
73
+ if ::Rails::VERSION::STRING < "7.1.0"
74
+ config.add_setting :fixture_path
75
+ else
76
+ config.add_setting :fixture_paths
77
+ end
78
+
73
79
  config.include RSpec::Rails::FixtureSupport, :use_fixtures
74
80
 
75
81
  # We'll need to create a deprecated module in order to properly report to
@@ -157,6 +163,27 @@ module RSpec
157
163
  filter_gems_from_backtrace "activemodel", "activerecord",
158
164
  "activesupport", "activejob"
159
165
  end
166
+
167
+ # @deprecated TestFixtures#fixture_path is deprecated and will be removed in Rails 7.2
168
+ if ::Rails::VERSION::STRING >= "7.1.0"
169
+ def fixture_path
170
+ RSpec.deprecate(
171
+ "config.fixture_path",
172
+ replacement: "config.fixture_paths",
173
+ message: "Rails 7.1 has deprecated the singular fixture_path in favour of an array"
174
+ )
175
+ fixture_paths&.first
176
+ end
177
+
178
+ def fixture_path=(path)
179
+ RSpec.deprecate(
180
+ "config.fixture_path = #{path.inspect}",
181
+ replacement: "config.fixture_paths = [#{path.inspect}]",
182
+ message: "Rails 7.1 has deprecated the singular fixture_path in favour of an array"
183
+ )
184
+ self.fixture_paths = Array(path)
185
+ end
186
+ end
160
187
  end
161
188
 
162
189
  add_test_type_configurations(config)
@@ -65,6 +65,7 @@ module RSpec
65
65
  # end
66
66
  def render(options = {}, local_assigns = {}, &block)
67
67
  options = _default_render_options if Hash === options && options.empty?
68
+ options = options.merge(_default_render_options) if Hash === options && options.keys == [:locals]
68
69
  super(options, local_assigns, &block)
69
70
  end
70
71
 
@@ -14,6 +14,8 @@ module RSpec
14
14
  resolved_fixture_path =
15
15
  if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
16
16
  file_fixture_path.to_s
17
+ elsif respond_to?(:fixture_paths)
18
+ (RSpec.configuration.fixture_paths&.first || '').to_s
17
19
  else
18
20
  (RSpec.configuration.fixture_path || '').to_s
19
21
  end
@@ -26,7 +28,11 @@ module RSpec
26
28
  include ActiveSupport::Testing::FileFixtures
27
29
 
28
30
  class << self
29
- attr_accessor :fixture_path
31
+ if ::Rails::VERSION::STRING < "7.1.0"
32
+ attr_accessor :fixture_path
33
+ else
34
+ attr_accessor :fixture_paths
35
+ end
30
36
 
31
37
  # Get instance of wrapper
32
38
  def instance
@@ -23,10 +23,11 @@ module RSpec
23
23
 
24
24
  # TestFixtures#fixture_path is deprecated and will be removed in Rails 7.2
25
25
  if respond_to?(:fixture_paths=)
26
- fixture_paths << RSpec.configuration.fixture_path
26
+ self.fixture_paths = RSpec.configuration.fixture_paths
27
27
  else
28
28
  self.fixture_path = RSpec.configuration.fixture_path
29
29
  end
30
+
30
31
  self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
31
32
  self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
32
33
 
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Rails
5
+ module Matchers
6
+ # @api private
7
+ #
8
+ # Matcher class for `send_email`. Should not be instantiated directly.
9
+ #
10
+ # @see RSpec::Rails::Matchers#send_email
11
+ class SendEmail < RSpec::Rails::Matchers::BaseMatcher
12
+ # @api private
13
+ # Define the email attributes that should be included in the inspection output.
14
+ INSPECT_EMAIL_ATTRIBUTES = %i[subject from to cc bcc].freeze
15
+
16
+ def initialize(criteria)
17
+ @criteria = criteria
18
+ end
19
+
20
+ # @api private
21
+ def supports_value_expectations?
22
+ false
23
+ end
24
+
25
+ # @api private
26
+ def supports_block_expectations?
27
+ true
28
+ end
29
+
30
+ def matches?(block)
31
+ define_matched_emails(block)
32
+
33
+ @matched_emails.one?
34
+ end
35
+
36
+ # @api private
37
+ # @return [String]
38
+ def failure_message
39
+ result =
40
+ if multiple_match?
41
+ "More than 1 matching emails were sent."
42
+ else
43
+ "No matching emails were sent."
44
+ end
45
+ "#{result}#{sent_emails_message}"
46
+ end
47
+
48
+ # @api private
49
+ # @return [String]
50
+ def failure_message_when_negated
51
+ "Expected not to send an email but it was sent."
52
+ end
53
+
54
+ private
55
+
56
+ def diffable?
57
+ true
58
+ end
59
+
60
+ def deliveries
61
+ ActionMailer::Base.deliveries
62
+ end
63
+
64
+ def define_matched_emails(block)
65
+ before = deliveries.dup
66
+
67
+ block.call
68
+
69
+ after = deliveries
70
+
71
+ @diff = after - before
72
+ @matched_emails = @diff.select(&method(:matched_email?))
73
+ end
74
+
75
+ def matched_email?(email)
76
+ @criteria.all? do |attr, value|
77
+ expected =
78
+ case attr
79
+ when :to, :from, :cc, :bcc then Array(value)
80
+ else
81
+ value
82
+ end
83
+
84
+ values_match?(expected, email.public_send(attr))
85
+ end
86
+ end
87
+
88
+ def multiple_match?
89
+ @matched_emails.many?
90
+ end
91
+
92
+ def sent_emails_message
93
+ if @diff.empty?
94
+ "\n\nThere were no any emails sent inside the expectation block."
95
+ else
96
+ sent_emails =
97
+ @diff.map do |email|
98
+ inspected = INSPECT_EMAIL_ATTRIBUTES.map { |attr| "#{attr}: #{email.public_send(attr)}" }.join(", ")
99
+ "- #{inspected}"
100
+ end.join("\n")
101
+ "\n\nThe following emails were sent:\n#{sent_emails}"
102
+ end
103
+ end
104
+ end
105
+
106
+ # @api public
107
+ # Check email sending with specific parameters.
108
+ #
109
+ # @example Positive expectation
110
+ # expect { action }.to send_email
111
+ #
112
+ # @example Negative expectations
113
+ # expect { action }.not_to send_email
114
+ #
115
+ # @example More precise expectation with attributes to match
116
+ # expect { action }.to send_email(to: 'test@example.com', subject: 'Confirm email')
117
+ def send_email(criteria = {})
118
+ SendEmail.new(criteria)
119
+ end
120
+ end
121
+ end
122
+ end
@@ -20,6 +20,7 @@ require 'rspec/rails/matchers/be_a_new'
20
20
  require 'rspec/rails/matchers/relation_match_array'
21
21
  require 'rspec/rails/matchers/be_valid'
22
22
  require 'rspec/rails/matchers/have_http_status'
23
+ require 'rspec/rails/matchers/send_email'
23
24
 
24
25
  if RSpec::Rails::FeatureCheck.has_active_job?
25
26
  require 'rspec/rails/matchers/active_job'
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec Rails.
4
4
  module Version
5
5
  # Current version of RSpec Rails, in semantic versioning format.
6
- STRING = '6.0.4'
6
+ STRING = '6.1.0'
7
7
  end
8
8
  end
9
9
  end
data/lib/rspec-rails.rb CHANGED
@@ -47,10 +47,18 @@ module RSpec
47
47
  end
48
48
  end
49
49
 
50
- def config_default_preview_path(options)
51
- return unless options.preview_path.blank?
50
+ if ::Rails::VERSION::STRING >= "7.1.0"
51
+ def config_default_preview_path(options)
52
+ return unless options.preview_paths.empty?
52
53
 
53
- options.preview_path = "#{::Rails.root}/spec/mailers/previews"
54
+ options.preview_paths << "#{::Rails.root}/spec/mailers/previews"
55
+ end
56
+ else
57
+ def config_default_preview_path(options)
58
+ return unless options.preview_path.blank?
59
+
60
+ options.preview_path = "#{::Rails.root}/spec/mailers/previews"
61
+ end
54
62
  end
55
63
 
56
64
  def supports_action_mailer_previews?(config)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.4
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -284,6 +284,7 @@ files:
284
284
  - lib/rspec/rails/matchers/redirect_to.rb
285
285
  - lib/rspec/rails/matchers/relation_match_array.rb
286
286
  - lib/rspec/rails/matchers/routing_matchers.rb
287
+ - lib/rspec/rails/matchers/send_email.rb
287
288
  - lib/rspec/rails/tasks/rspec.rake
288
289
  - lib/rspec/rails/vendor/capybara.rb
289
290
  - lib/rspec/rails/version.rb
@@ -296,7 +297,7 @@ licenses:
296
297
  - MIT
297
298
  metadata:
298
299
  bug_tracker_uri: https://github.com/rspec/rspec-rails/issues
299
- changelog_uri: https://github.com/rspec/rspec-rails/blob/v6.0.4/Changelog.md
300
+ changelog_uri: https://github.com/rspec/rspec-rails/blob/v6.1.0/Changelog.md
300
301
  documentation_uri: https://rspec.info/documentation/
301
302
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
302
303
  source_code_uri: https://github.com/rspec/rspec-rails
metadata.gz.sig CHANGED
Binary file