rspec-rails 6.0.4 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecae469592630a6ecaaa39d6f2be0e2616cb2079c044bc390e548956b823d6bc
4
- data.tar.gz: f24952e5edf9bf57f6e8c94fced8c7b2d38938b4a1b250fa83043bf316c8de9c
3
+ metadata.gz: b5ff6b0dc14db86b07e0cc46cd193329c85e21d15c9863ccbb5b73c54972daa6
4
+ data.tar.gz: c7bd505a3bfd16f881fb04b04e98ff7df9910d230eb17183fc68621a74d4b9d9
5
5
  SHA512:
6
- metadata.gz: e50c692c774cd0a874bedd667e7c0e3997236d43a74750efb6cc215a3019ce9a4babc5437a79825c43c885b70f1c3da9c90599ce1b0bf123ba1538e77cc7884e
7
- data.tar.gz: a148f034a8667af85e68c478849bd9ea33443567dec01335d0a83ad9fd44d63d7dd0780694ebaee55f2278add2fefa61032674e38dec865cf01ee1205e13d1e9
6
+ metadata.gz: 6abbc3617dd82480b86c99c5d9347c94f8ac62bb944cf4ce1a223bea60046d9108be76fc3045a2e5f8549ad9813f7e831882f9ddee31de9d4215f643ce8a6d43
7
+ data.tar.gz: 07b551b367df408eaaa847307a6abd28a566a6a17ee4b552dc99a8bad95794f262884dc6e34a4d5717146fa001f89f6060cd1784818ed29f11f5361753fa606d
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,34 @@
1
+ ### Development
2
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.1...6-1-maintenance)
3
+
4
+ ### 6.1.1 / 2024-01-25
5
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.0...v6.1.1)
6
+
7
+ Bug Fixes:
8
+
9
+ * Improved deprecation message for `RSpec::Rails::Configuration.fixture_paths`
10
+ (Benoit Tigeot, #2720)
11
+ * Fix support for namespaced fixtures in Rails 7.1. (Benedikt Deicke, #2716)
12
+
13
+ ### 6.1.0 / 2023-11-21
14
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.4...v6.1.0)
15
+
16
+ Enhancements:
17
+
18
+ * Support for Rails 7.1
19
+ * Minor tweak to generated `rails_helper.rb` to use `Rails.root.join`.
20
+ (@masato-bkn, Ryo Nakamura, #2640, #2678)
21
+ * Add `RSpec::Rails::Configuration.fixture_paths` configuration to support
22
+ the matching change to `ActiveRecord::TestFixtures`, previous singular
23
+ form is deprecated and will be removed in Rails 7.2. (Juan Gueçaimburu, #2673)
24
+ * Add `send_email` matcher to match emails rather than specific jobs.
25
+ (Andrei Kaleshka, #2670)
26
+ * When using `render` in view specs, `:locals` will now be merged into the
27
+ default implicit template, allowing `render locals: {...}` style calls.
28
+ (Jon Rowe, #2686)
29
+ * Add support for `Rails.config.action_mailer.preview_paths` on Rails 7.1/
30
+ (Jon Rowe, #2706)
31
+
1
32
  ### 6.0.4 / 2023-11-21
2
33
  [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.3...v6.0.4)
3
34
 
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,29 @@ 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
+ "You should migrate to plural:"
175
+ )
176
+ fixture_paths&.first
177
+ end
178
+
179
+ def fixture_path=(path)
180
+ RSpec.deprecate(
181
+ "config.fixture_path = #{path.inspect}",
182
+ replacement: "config.fixture_paths = [#{path.inspect}]",
183
+ message: "Rails 7.1 has deprecated the singular fixture_path in favour of an array." \
184
+ "You should migrate to plural:"
185
+ )
186
+ self.fixture_paths = Array(path)
187
+ end
188
+ end
160
189
  end
161
190
 
162
191
  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
 
@@ -42,14 +43,14 @@ module RSpec
42
43
  if ::Rails.version.to_f >= 7.1
43
44
  def fixtures(*args)
44
45
  super.tap do
45
- fixture_sets.each_key do |fixture_name|
46
- proxy_method_warning_if_called_in_before_context_scope(fixture_name)
46
+ fixture_sets.each_pair do |method_name, fixture_name|
47
+ proxy_method_warning_if_called_in_before_context_scope(method_name, fixture_name)
47
48
  end
48
49
  end
49
50
  end
50
51
 
51
- def proxy_method_warning_if_called_in_before_context_scope(fixture_name)
52
- define_method(fixture_name) do |*args, **kwargs, &blk|
52
+ def proxy_method_warning_if_called_in_before_context_scope(method_name, fixture_name)
53
+ define_method(method_name) do |*args, **kwargs, &blk|
53
54
  if RSpec.current_scope == :before_context_hook
54
55
  RSpec.warn_with("Calling fixture method in before :context ")
55
56
  else
@@ -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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -44,7 +44,7 @@ cert_chain:
44
44
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
45
45
  F3MdtaDehhjC
46
46
  -----END CERTIFICATE-----
47
- date: 2023-11-21 00:00:00.000000000 Z
47
+ date: 2024-01-25 00:00:00.000000000 Z
48
48
  dependencies:
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: actionpack
@@ -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.1/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
@@ -316,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
317
  - !ruby/object:Gem::Version
317
318
  version: '0'
318
319
  requirements: []
319
- rubygems_version: 3.4.10
320
+ rubygems_version: 3.5.3
320
321
  signing_key:
321
322
  specification_version: 4
322
323
  summary: RSpec for Rails
metadata.gz.sig CHANGED
Binary file