rspec-rails 6.0.3 → 6.1.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +35 -1
- data/README.md +5 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +9 -3
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +3 -3
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/rspec/rails/configuration.rb +29 -2
- data/lib/rspec/rails/example/rails_example_group.rb +8 -1
- data/lib/rspec/rails/example/system_example_group.rb +46 -0
- data/lib/rspec/rails/example/view_example_group.rb +2 -1
- data/lib/rspec/rails/fixture_file_upload_support.rb +7 -1
- data/lib/rspec/rails/fixture_support.rb +38 -15
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +1 -1
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec-rails.rb +11 -3
- data.tar.gz.sig +0 -0
- metadata +8 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4670e0b41ea2e22cb7a3fd5d28a421fe82fed0c591dbb245e011b497a1ac81f3
|
4
|
+
data.tar.gz: a3cf937f37a03c114b8397216d034eae1645ea8575906f6f5a444973a1626419
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd476082c87a5735996ce66d0efcf7bb1f5860b81118e05b71388872b50a11bb28d6fb981a23aed71597c45585244aa4c5d53a45c6d8500a751e36fa8d4f3039
|
7
|
+
data.tar.gz: b996549661e01669b60767064e24b7dd7836ce79db985048856d7c98c9ed5892d04551050dbaa3727c2a358026990611559144c824f198a85b7c78c3651e3401
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.
|
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
|
+
|
23
|
+
### 6.0.4 / 2023-11-21
|
24
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.3...v6.0.4)
|
25
|
+
|
26
|
+
Bug Fixes:
|
27
|
+
|
28
|
+
* Fuzzy match `have_broadcasted_to` so that argument matchers can be used.
|
29
|
+
(Timothy Peraza, #2684)
|
30
|
+
* Fix fixture warning during `:context` hooks on Rails `main`. (Jon Rowe, #2685)
|
31
|
+
* Fix `stub_template` on Rails `main`. (Jon Rowe, #2685)
|
32
|
+
* Fix variable name in scaffolded view specs when namespaced. (Taketo Takashima, #2694)
|
33
|
+
* Prevent `take_failed_screenshot` producing an additional error through `metadata`
|
34
|
+
access. (Jon Rowe, #2704)
|
35
|
+
* Use `ActiveSupport::ExecutionContext::TestHelper` on Rails 7+. (Jon Rowe, #2711)
|
36
|
+
* Fix leak of templates stubbed with `stub_template` on Rails 7.1. (Jon Rowe, #2714)
|
3
37
|
|
4
38
|
### 6.0.3 / 2023-05-31
|
5
39
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.2...v6.0.3)
|
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-
|
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
|
34
|
-
See the [`
|
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.
|
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
|
-
#
|
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
|
-
|
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 =
|
61
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
56
62
|
# config.use_transactional_fixtures = true
|
57
63
|
|
58
64
|
<% end -%>
|
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
5
|
-
let(:<%=
|
5
|
+
let(:<%= singular_table_name %>) {
|
6
6
|
<%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
@@ -11,13 +11,13 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
before(:each) do
|
14
|
-
assign(:<%=
|
14
|
+
assign(:<%= singular_table_name %>, <%= singular_table_name %>)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "renders the edit <%= ns_file_name %> form" do
|
18
18
|
render
|
19
19
|
|
20
|
-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%=
|
20
|
+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
|
21
21
|
<% for attribute in output_attributes -%>
|
22
22
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
23
23
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
@@ -3,7 +3,7 @@ require 'rails_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
@@ -3,7 +3,7 @@ require 'rails_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% 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
|
-
|
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)
|
@@ -2,6 +2,10 @@
|
|
2
2
|
# suite and ammeter.
|
3
3
|
require 'rspec/rails/matchers'
|
4
4
|
|
5
|
+
if ::Rails::VERSION::MAJOR >= 7
|
6
|
+
require 'active_support/execution_context/test_helper'
|
7
|
+
end
|
8
|
+
|
5
9
|
module RSpec
|
6
10
|
module Rails
|
7
11
|
# @api public
|
@@ -12,7 +16,10 @@ module RSpec
|
|
12
16
|
include RSpec::Rails::MinitestLifecycleAdapter
|
13
17
|
include RSpec::Rails::MinitestAssertionAdapter
|
14
18
|
include RSpec::Rails::FixtureSupport
|
15
|
-
|
19
|
+
if ::Rails::VERSION::MAJOR >= 7
|
20
|
+
include RSpec::Rails::TaggedLoggingAdapter
|
21
|
+
include ActiveSupport::ExecutionContext::TestHelper
|
22
|
+
end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -44,6 +44,52 @@ module RSpec
|
|
44
44
|
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
|
45
45
|
end
|
46
46
|
|
47
|
+
if ::Rails::VERSION::STRING.to_f >= 7.1
|
48
|
+
# @private
|
49
|
+
# Allows failure screenshot to work whilst not exposing metadata
|
50
|
+
class SuppressRailsScreenshotMetadata
|
51
|
+
def initialize
|
52
|
+
@example_data = {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def [](key)
|
56
|
+
if @example_data.key?(key)
|
57
|
+
@example_data[key]
|
58
|
+
else
|
59
|
+
raise_wrong_scope_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def []=(key, value)
|
64
|
+
if key == :failure_screenshot_path
|
65
|
+
@example_data[key] = value
|
66
|
+
else
|
67
|
+
raise_wrong_scope_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def method_missing(_name, *_args, &_block)
|
72
|
+
raise_wrong_scope_error
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def raise_wrong_scope_error
|
78
|
+
raise RSpec::Core::ExampleGroup::WrongScopeError,
|
79
|
+
"`metadata` is not available from within an example " \
|
80
|
+
"(e.g. an `it` block) or from constructs that run in the " \
|
81
|
+
"scope of an example (e.g. `before`, `let`, etc). It is " \
|
82
|
+
"only available on an example group (e.g. a `describe` or "\
|
83
|
+
"`context` block)"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @private
|
88
|
+
def metadata
|
89
|
+
@metadata ||= SuppressRailsScreenshotMetadata.new
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
47
93
|
# Delegates to `Rails.application`.
|
48
94
|
def app
|
49
95
|
::Rails.application
|
@@ -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
|
|
@@ -89,7 +90,7 @@ module RSpec
|
|
89
90
|
#
|
90
91
|
# stub_template("widgets/_widget.html.erb" => "This content.")
|
91
92
|
def stub_template(hash)
|
92
|
-
|
93
|
+
controller.prepend_view_path(StubResolverCache.resolver_for(hash))
|
93
94
|
end
|
94
95
|
|
95
96
|
# Provides access to the params hash that will be available within the
|
@@ -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
|
-
|
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
|
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
|
|
@@ -37,28 +38,50 @@ module RSpec
|
|
37
38
|
module Fixtures
|
38
39
|
extend ActiveSupport::Concern
|
39
40
|
|
41
|
+
# rubocop:disable Metrics/BlockLength
|
40
42
|
class_methods do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if ::Rails.version.to_f >= 7.1
|
44
|
+
def fixtures(*args)
|
45
|
+
super.tap do
|
46
|
+
fixture_sets.each_key do |fixture_name|
|
47
|
+
proxy_method_warning_if_called_in_before_context_scope(fixture_name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def proxy_method_warning_if_called_in_before_context_scope(fixture_name)
|
53
|
+
define_method(fixture_name) do |*args, **kwargs, &blk|
|
54
|
+
if RSpec.current_scope == :before_context_hook
|
55
|
+
RSpec.warn_with("Calling fixture method in before :context ")
|
56
|
+
else
|
57
|
+
access_fixture(fixture_name, *args, **kwargs, &blk)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
else
|
62
|
+
def fixtures(*args)
|
63
|
+
orig_methods = private_instance_methods
|
64
|
+
super.tap do
|
65
|
+
new_methods = private_instance_methods - orig_methods
|
66
|
+
new_methods.each do |method_name|
|
67
|
+
proxy_method_warning_if_called_in_before_context_scope(method_name)
|
68
|
+
end
|
47
69
|
end
|
48
70
|
end
|
49
|
-
end
|
50
71
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
def proxy_method_warning_if_called_in_before_context_scope(method_name)
|
73
|
+
orig_implementation = instance_method(method_name)
|
74
|
+
define_method(method_name) do |*args, &blk|
|
75
|
+
if RSpec.current_scope == :before_context_hook
|
76
|
+
RSpec.warn_with("Calling fixture method in before :context ")
|
77
|
+
else
|
78
|
+
orig_implementation.bind(self).call(*args, &blk)
|
79
|
+
end
|
58
80
|
end
|
59
81
|
end
|
60
82
|
end
|
61
83
|
end
|
84
|
+
# rubocop:enable Metrics/BlockLength
|
62
85
|
end
|
63
86
|
end
|
64
87
|
end
|
@@ -112,7 +112,7 @@ module RSpec
|
|
112
112
|
decoded = ActiveSupport::JSON.decode(msg)
|
113
113
|
decoded = decoded.with_indifferent_access if decoded.is_a?(Hash)
|
114
114
|
|
115
|
-
if @data.nil? || @data
|
115
|
+
if @data.nil? || values_match?(@data, decoded)
|
116
116
|
@block.call(decoded)
|
117
117
|
true
|
118
118
|
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
|
data/lib/rspec/rails/matchers.rb
CHANGED
@@ -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'
|
data/lib/rspec/rails/version.rb
CHANGED
data/lib/rspec-rails.rb
CHANGED
@@ -47,10 +47,18 @@ module RSpec
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
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
|
-
|
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,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chelimsky
|
8
8
|
- Andy Lindeman
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
@@ -44,7 +44,7 @@ cert_chain:
|
|
44
44
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
45
45
|
F3MdtaDehhjC
|
46
46
|
-----END CERTIFICATE-----
|
47
|
-
date: 2023-
|
47
|
+
date: 2023-11-21 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,11 +297,11 @@ 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
|
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
|
303
|
-
post_install_message:
|
304
|
+
post_install_message:
|
304
305
|
rdoc_options:
|
305
306
|
- "--charset=UTF-8"
|
306
307
|
require_paths:
|
@@ -316,8 +317,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
317
|
- !ruby/object:Gem::Version
|
317
318
|
version: '0'
|
318
319
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
320
|
-
signing_key:
|
320
|
+
rubygems_version: 3.4.10
|
321
|
+
signing_key:
|
321
322
|
specification_version: 4
|
322
323
|
summary: RSpec for Rails
|
323
324
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|