rspec-rails 3.5.0.beta3 → 3.5.0.beta4
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.tar.gz.sig +0 -0
- data/Changelog.md +41 -8
- data/README.md +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +64 -0
- data/lib/rspec-rails.rb +2 -0
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec/rails/adapters.rb +4 -2
- data/lib/rspec/rails/configuration.rb +6 -0
- data/lib/rspec/rails/example/view_example_group.rb +10 -0
- data/lib/rspec/rails/feature_check.rb +4 -0
- data/lib/rspec/rails/file_fixture_support.rb +17 -0
- data/lib/rspec/rails/matchers/active_job.rb +110 -29
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -2
- data/lib/rspec/rails/version.rb +1 -1
- metadata +12 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe6c556ed366e640bb5f0a4aa918fcc872020904
|
4
|
+
data.tar.gz: 1136962bda7a5bd265570b16bd51589e0f28156b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bba5f656f01beb05846a821080d4124a8150e99a531bc9407982543ee93e6eef03c48a2d9430bf3169f1a466d4bd20837072d673ebcf4da0d3d01836ee08e97c
|
7
|
+
data.tar.gz: 0e9061fcd609bbdd7031bfe879e10b9c1001b5669fd5f0d5bf72e7229ec021202b2e2f53c466df2ccaa820090608216a443228a461c24e111069a9558691053a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,20 +1,51 @@
|
|
1
|
-
### 3.5
|
2
|
-
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.
|
1
|
+
### 3.5 development
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.beta4...master)
|
3
3
|
|
4
|
-
### 3.5.0.
|
5
|
-
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.
|
4
|
+
### 3.5.0.beta4 / 2016-06-05
|
5
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.beta3...v3.5.0.beta4)
|
6
6
|
|
7
7
|
Enhancements:
|
8
|
+
|
9
|
+
* Add support for block when using `with` on `have_enqueued_job`. (John Schroeder, #1578)
|
10
|
+
* Add support for `file_fixture(...)`. (Wojciech Wnętrzak, #1587)
|
11
|
+
* Add support for `setup` and `teardown` with blocks (Miklós Fazekas, #1598)
|
12
|
+
* Add `enqueue_job ` alias for `have_enqueued_job`, support `once`/`twice`/
|
13
|
+
`thrice`, add `have_been_enqueued` matcher to support use without blocks.
|
14
|
+
(Sergey Alexandrovich, #1613)
|
15
|
+
|
16
|
+
Bug fixes:
|
17
|
+
|
18
|
+
* Prevent asset helpers from taking precendence over route helpers. (Prem Sichanugrist, #1496)
|
19
|
+
* Prevent `NoMethodError` during failed `have_rendered` assertions on weird templates.
|
20
|
+
(Jon Rowe, #1623).
|
21
|
+
|
22
|
+
### 3.5.0.beta3 / 2016-04-02
|
23
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.beta2...v3.5.0.beta3)
|
24
|
+
|
25
|
+
Enhancements:
|
26
|
+
|
8
27
|
* Add support for Rails 5 Beta 3 (Sam Phippen, Benjamin Quorning, Koen Punt, #1589, #1573)
|
9
28
|
|
10
|
-
Bug
|
29
|
+
Bug fixes:
|
11
30
|
|
12
|
-
* Make it possible to use floats in auto generated (scaffold) tests.
|
13
|
-
(Alwahsh, #1550)
|
14
31
|
* Support custom resolvers when preventing views from rendering.
|
15
32
|
(Jon Rowe, Benjamin Quorning, #1580)
|
16
33
|
|
17
|
-
### 3.5.0.
|
34
|
+
### 3.5.0.beta2 / 2016-03-10
|
35
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.5.0.beta1...v3.5.0.beta2)
|
36
|
+
|
37
|
+
Enhancements:
|
38
|
+
|
39
|
+
* Include `ActionDispatch::IntegrationTest::Behavior` in request spec
|
40
|
+
example groups when on Rails 5, allowing integration test helpers
|
41
|
+
to be used in request specs. (Scott Bronson, #1560)
|
42
|
+
|
43
|
+
Bug fixes:
|
44
|
+
|
45
|
+
* Make it possible to use floats in auto generated (scaffold) tests.
|
46
|
+
(Alwahsh, #1550)
|
47
|
+
|
48
|
+
### 3.5.0.beta1 / 2016-02-06
|
18
49
|
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.4.2...v3.5.0.beta1)
|
19
50
|
|
20
51
|
Enhancements:
|
@@ -32,6 +63,8 @@ Bug fixes:
|
|
32
63
|
crashing with a `undefined method for nil:NilClass`. (Sam Phippen, #1501)
|
33
64
|
* Expose path to view specs (Ryan Clark, Sarah Mei, Sam Phippen, #1402)
|
34
65
|
* Prevent installing Rails 3.2.22.1 on Ruby 1.8.7. (Jon Rowe, #1540)
|
66
|
+
* Raise a clear error when `have_enqueued_job` is used with non-test
|
67
|
+
adapter. (Wojciech Wnętrzak, #1489)
|
35
68
|
|
36
69
|
### 3.4.2 / 2016-02-02
|
37
70
|
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.4.1...v3.4.2)
|
data/README.md
CHANGED
@@ -41,7 +41,11 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
41
41
|
describe "GET #index" do
|
42
42
|
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
43
43
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
44
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
44
45
|
get :index, {}, valid_session
|
46
|
+
<% else -%>
|
47
|
+
get :index, params: {}, session: valid_session
|
48
|
+
<% end -%>
|
45
49
|
expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
|
46
50
|
end
|
47
51
|
end
|
@@ -50,14 +54,22 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
50
54
|
describe "GET #show" do
|
51
55
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
52
56
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
57
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
53
58
|
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
59
|
+
<% else -%>
|
60
|
+
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
61
|
+
<% end -%>
|
54
62
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
58
66
|
describe "GET #new" do
|
59
67
|
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
68
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
60
69
|
get :new, {}, valid_session
|
70
|
+
<% else -%>
|
71
|
+
get :new, params: {}, session: valid_session
|
72
|
+
<% end -%>
|
61
73
|
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
|
62
74
|
end
|
63
75
|
end
|
@@ -65,7 +77,11 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
65
77
|
describe "GET #edit" do
|
66
78
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
67
79
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
80
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
68
81
|
get :edit, {:id => <%= file_name %>.to_param}, valid_session
|
82
|
+
<% else -%>
|
83
|
+
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
84
|
+
<% end -%>
|
69
85
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
70
86
|
end
|
71
87
|
end
|
@@ -74,30 +90,50 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
74
90
|
context "with valid params" do
|
75
91
|
it "creates a new <%= class_name %>" do
|
76
92
|
expect {
|
93
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
77
94
|
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
95
|
+
<% else -%>
|
96
|
+
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
97
|
+
<% end -%>
|
78
98
|
}.to change(<%= class_name %>, :count).by(1)
|
79
99
|
end
|
80
100
|
|
81
101
|
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
102
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
82
103
|
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
104
|
+
<% else -%>
|
105
|
+
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
106
|
+
<% end -%>
|
83
107
|
expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
|
84
108
|
expect(assigns(:<%= ns_file_name %>)).to be_persisted
|
85
109
|
end
|
86
110
|
|
87
111
|
it "redirects to the created <%= ns_file_name %>" do
|
112
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
88
113
|
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
114
|
+
<% else -%>
|
115
|
+
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
116
|
+
<% end -%>
|
89
117
|
expect(response).to redirect_to(<%= class_name %>.last)
|
90
118
|
end
|
91
119
|
end
|
92
120
|
|
93
121
|
context "with invalid params" do
|
94
122
|
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
123
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
95
124
|
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
125
|
+
<% else -%>
|
126
|
+
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
127
|
+
<% end -%>
|
96
128
|
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
|
97
129
|
end
|
98
130
|
|
99
131
|
it "re-renders the 'new' template" do
|
132
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
100
133
|
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
134
|
+
<% else -%>
|
135
|
+
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
136
|
+
<% end -%>
|
101
137
|
expect(response).to render_template("new")
|
102
138
|
end
|
103
139
|
end
|
@@ -111,20 +147,32 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
111
147
|
|
112
148
|
it "updates the requested <%= ns_file_name %>" do
|
113
149
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
150
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
114
151
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
|
152
|
+
<% else -%>
|
153
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
154
|
+
<% end -%>
|
115
155
|
<%= file_name %>.reload
|
116
156
|
skip("Add assertions for updated state")
|
117
157
|
end
|
118
158
|
|
119
159
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
120
160
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
161
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
121
162
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
163
|
+
<% else -%>
|
164
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
165
|
+
<% end -%>
|
122
166
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
123
167
|
end
|
124
168
|
|
125
169
|
it "redirects to the <%= ns_file_name %>" do
|
126
170
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
171
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
127
172
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
173
|
+
<% else -%>
|
174
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
175
|
+
<% end -%>
|
128
176
|
expect(response).to redirect_to(<%= file_name %>)
|
129
177
|
end
|
130
178
|
end
|
@@ -132,13 +180,21 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
132
180
|
context "with invalid params" do
|
133
181
|
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
134
182
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
183
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
135
184
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
185
|
+
<% else -%>
|
186
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
187
|
+
<% end -%>
|
136
188
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
137
189
|
end
|
138
190
|
|
139
191
|
it "re-renders the 'edit' template" do
|
140
192
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
193
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
141
194
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
195
|
+
<% else -%>
|
196
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
197
|
+
<% end -%>
|
142
198
|
expect(response).to render_template("edit")
|
143
199
|
end
|
144
200
|
end
|
@@ -148,13 +204,21 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
148
204
|
it "destroys the requested <%= ns_file_name %>" do
|
149
205
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
150
206
|
expect {
|
207
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
151
208
|
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
209
|
+
<% else -%>
|
210
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
211
|
+
<% end -%>
|
152
212
|
}.to change(<%= class_name %>, :count).by(-1)
|
153
213
|
end
|
154
214
|
|
155
215
|
it "redirects to the <%= table_name %> list" do
|
156
216
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
217
|
+
<% if RUBY_VERSION < '1.9.3' -%>
|
157
218
|
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
219
|
+
<% else -%>
|
220
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
221
|
+
<% end -%>
|
158
222
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
159
223
|
end
|
160
224
|
end
|
data/lib/rspec-rails.rb
CHANGED
data/lib/rspec/rails.rb
CHANGED
@@ -9,6 +9,7 @@ require 'rspec/rails/extensions'
|
|
9
9
|
require 'rspec/rails/view_rendering'
|
10
10
|
require 'rspec/rails/matchers'
|
11
11
|
require 'rspec/rails/fixture_support'
|
12
|
+
require 'rspec/rails/file_fixture_support'
|
12
13
|
require 'rspec/rails/example'
|
13
14
|
require 'rspec/rails/vendor/capybara'
|
14
15
|
require 'rspec/rails/configuration'
|
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -157,7 +157,7 @@ module RSpec
|
|
157
157
|
module ClassMethods
|
158
158
|
# Wraps `setup` calls from within Rails' testing framework in `before`
|
159
159
|
# hooks.
|
160
|
-
def setup(*methods)
|
160
|
+
def setup(*methods, &block)
|
161
161
|
methods.each do |method|
|
162
162
|
if method.to_s =~ /^setup_(with_controller|fixtures|controller_request_and_response)$/
|
163
163
|
prepend_before { __send__ method }
|
@@ -165,14 +165,16 @@ module RSpec
|
|
165
165
|
before { __send__ method }
|
166
166
|
end
|
167
167
|
end
|
168
|
+
before(&block) if block
|
168
169
|
end
|
169
170
|
|
170
171
|
# @api private
|
171
172
|
#
|
172
173
|
# Wraps `teardown` calls from within Rails' testing framework in
|
173
174
|
# `after` hooks.
|
174
|
-
def teardown(*methods)
|
175
|
+
def teardown(*methods, &block)
|
175
176
|
methods.each { |method| after { __send__ method } }
|
177
|
+
after(&block) if block
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
@@ -50,6 +50,7 @@ module RSpec
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# @private
|
53
|
+
# rubocop:disable Style/MethodLength
|
53
54
|
def self.initialize_configuration(config)
|
54
55
|
config.backtrace_exclusion_patterns << /vendor\//
|
55
56
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
@@ -73,6 +74,10 @@ module RSpec
|
|
73
74
|
# `RSpec::Rails::FixtureSupport` directly instead
|
74
75
|
config.include RSpec::Rails::FixtureSupport
|
75
76
|
|
77
|
+
if ::Rails::VERSION::STRING > '5'
|
78
|
+
config.add_setting :file_fixture_path, :default => 'spec/fixtures/files'
|
79
|
+
config.include RSpec::Rails::FileFixtureSupport
|
80
|
+
end
|
76
81
|
# This allows us to expose `render_views` as a config option even though it
|
77
82
|
# breaks the convention of other options by using `render_views` as a
|
78
83
|
# command (i.e. `render_views = true`), where it would normally be used
|
@@ -129,6 +134,7 @@ module RSpec
|
|
129
134
|
config.include RSpec::Rails::JobExampleGroup, :type => :job
|
130
135
|
end
|
131
136
|
end
|
137
|
+
# rubocop:enable Style/MethodLength
|
132
138
|
|
133
139
|
initialize_configuration RSpec.configuration
|
134
140
|
end
|
@@ -31,6 +31,16 @@ module RSpec
|
|
31
31
|
|
32
32
|
# DSL exposed to view specs.
|
33
33
|
module ExampleMethods
|
34
|
+
extend ActiveSupport::Concern
|
35
|
+
|
36
|
+
included do
|
37
|
+
include ::Rails.application.routes.url_helpers
|
38
|
+
|
39
|
+
if ::Rails.application.routes.respond_to?(:mounted_helpers)
|
40
|
+
include ::Rails.application.routes.mounted_helpers
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
34
44
|
# @overload render
|
35
45
|
# @overload render({:partial => path_to_file})
|
36
46
|
# @overload render({:partial => path_to_file}, {... locals ...})
|
@@ -0,0 +1,17 @@
|
|
1
|
+
if ::Rails::VERSION::STRING > '5'
|
2
|
+
require 'active_support/testing/file_fixtures'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Rails
|
6
|
+
# @private
|
7
|
+
module FileFixtureSupport
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
include ActiveSupport::Testing::FileFixtures
|
10
|
+
|
11
|
+
included do
|
12
|
+
self.file_fixture_path = RSpec.configuration.file_fixture_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -8,36 +8,20 @@ module RSpec
|
|
8
8
|
#
|
9
9
|
# @api private
|
10
10
|
module ActiveJob
|
11
|
+
# rubocop: disable Style/ClassLength
|
11
12
|
# @private
|
12
|
-
class
|
13
|
-
def initialize
|
14
|
-
@job = job
|
13
|
+
class Base < RSpec::Matchers::BuiltIn::BaseMatcher
|
14
|
+
def initialize
|
15
15
|
@args = []
|
16
16
|
@queue = nil
|
17
17
|
@at = nil
|
18
|
+
@block = Proc.new {}
|
18
19
|
set_expected_number(:exactly, 1)
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
raise ArgumentError, "have_enqueued_jobs only supports block expectations" unless Proc === proc
|
23
|
-
|
24
|
-
original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count
|
25
|
-
proc.call
|
26
|
-
in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count)
|
27
|
-
|
28
|
-
@matching_jobs_count = in_block_jobs.count do |job|
|
29
|
-
serialized_attributes.all? { |key, value| value == job[key] }
|
30
|
-
end
|
31
|
-
|
32
|
-
case @expectation_type
|
33
|
-
when :exactly then @expected_number == @matching_jobs_count
|
34
|
-
when :at_most then @expected_number >= @matching_jobs_count
|
35
|
-
when :at_least then @expected_number <= @matching_jobs_count
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def with(*args)
|
22
|
+
def with(*args, &block)
|
40
23
|
@args = args
|
24
|
+
@block = block if block.present?
|
41
25
|
self
|
42
26
|
end
|
43
27
|
|
@@ -70,6 +54,18 @@ module RSpec
|
|
70
54
|
self
|
71
55
|
end
|
72
56
|
|
57
|
+
def once
|
58
|
+
exactly(:once)
|
59
|
+
end
|
60
|
+
|
61
|
+
def twice
|
62
|
+
exactly(:twice)
|
63
|
+
end
|
64
|
+
|
65
|
+
def thrice
|
66
|
+
exactly(:thrice)
|
67
|
+
end
|
68
|
+
|
73
69
|
def failure_message
|
74
70
|
"expected to enqueue #{base_message}"
|
75
71
|
end
|
@@ -92,6 +88,23 @@ module RSpec
|
|
92
88
|
|
93
89
|
private
|
94
90
|
|
91
|
+
def check(jobs)
|
92
|
+
@matching_jobs_count = jobs.count do |job|
|
93
|
+
if serialized_attributes.all? { |key, value| value == job[key] }
|
94
|
+
@block.call(*job[:args])
|
95
|
+
true
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
case @expectation_type
|
102
|
+
when :exactly then @expected_number == @matching_jobs_count
|
103
|
+
when :at_most then @expected_number >= @matching_jobs_count
|
104
|
+
when :at_least then @expected_number <= @matching_jobs_count
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
95
108
|
def base_message
|
96
109
|
"#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg|
|
97
110
|
msg << " with #{@args}," if @args.any?
|
@@ -124,25 +137,55 @@ module RSpec
|
|
124
137
|
::ActiveJob::Base.queue_adapter
|
125
138
|
end
|
126
139
|
end
|
140
|
+
# rubocop: enable Style/ClassLength
|
141
|
+
|
142
|
+
# @private
|
143
|
+
class HaveEnqueuedJob < Base
|
144
|
+
def initialize(job)
|
145
|
+
super()
|
146
|
+
@job = job
|
147
|
+
end
|
148
|
+
|
149
|
+
def matches?(proc)
|
150
|
+
raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
|
151
|
+
|
152
|
+
original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count
|
153
|
+
proc.call
|
154
|
+
in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count)
|
155
|
+
|
156
|
+
check(in_block_jobs)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# @private
|
161
|
+
class HaveBeenEnqueued < Base
|
162
|
+
def matches?(job)
|
163
|
+
@job = job
|
164
|
+
check(queue_adapter.enqueued_jobs)
|
165
|
+
end
|
166
|
+
end
|
127
167
|
end
|
128
168
|
|
129
169
|
# @api public
|
130
|
-
#
|
170
|
+
# Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times.
|
131
171
|
#
|
132
172
|
# @example
|
133
173
|
# expect {
|
134
174
|
# HeavyLiftingJob.perform_later
|
135
175
|
# }.to have_enqueued_job
|
136
176
|
#
|
177
|
+
# # Using alias
|
178
|
+
# expect {
|
179
|
+
# HeavyLiftingJob.perform_later
|
180
|
+
# }.to enqueue_job
|
181
|
+
#
|
137
182
|
# expect {
|
138
183
|
# HelloJob.perform_later
|
139
184
|
# HeavyLiftingJob.perform_later
|
140
185
|
# }.to have_enqueued_job(HelloJob).exactly(:once)
|
141
186
|
#
|
142
187
|
# expect {
|
143
|
-
# HelloJob.perform_later
|
144
|
-
# HelloJob.perform_later
|
145
|
-
# HelloJob.perform_later
|
188
|
+
# 3.times { HelloJob.perform_later }
|
146
189
|
# }.to have_enqueued_job(HelloJob).at_least(2).times
|
147
190
|
#
|
148
191
|
# expect {
|
@@ -158,11 +201,49 @@ module RSpec
|
|
158
201
|
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
159
202
|
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
|
160
203
|
def have_enqueued_job(job = nil)
|
161
|
-
|
162
|
-
raise StandardError, "To use have_enqueued_job matcher set `ActiveJob::Base.queue_adapter = :test`"
|
163
|
-
end
|
204
|
+
check_active_job_adapter
|
164
205
|
ActiveJob::HaveEnqueuedJob.new(job)
|
165
206
|
end
|
207
|
+
alias_method :enqueue_job, :have_enqueued_job
|
208
|
+
|
209
|
+
# @api public
|
210
|
+
# Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
|
211
|
+
#
|
212
|
+
# @example
|
213
|
+
# before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear }
|
214
|
+
#
|
215
|
+
# HeavyLiftingJob.perform_later
|
216
|
+
# expect(HeavyLiftingJob).to have_been_enqueued
|
217
|
+
#
|
218
|
+
# HelloJob.perform_later
|
219
|
+
# HeavyLiftingJob.perform_later
|
220
|
+
# expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once)
|
221
|
+
#
|
222
|
+
# 3.times { HelloJob.perform_later }
|
223
|
+
# expect(HelloJob).to have_been_enqueued.at_least(2).times
|
224
|
+
#
|
225
|
+
# HelloJob.perform_later
|
226
|
+
# expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice)
|
227
|
+
#
|
228
|
+
# HelloJob.perform_later
|
229
|
+
# HeavyLiftingJob.perform_later
|
230
|
+
# expect(HelloJob).to have_been_enqueued
|
231
|
+
# expect(HeavyLiftingJob).to have_been_enqueued
|
232
|
+
#
|
233
|
+
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
234
|
+
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon)
|
235
|
+
def have_been_enqueued
|
236
|
+
check_active_job_adapter
|
237
|
+
ActiveJob::HaveBeenEnqueued.new
|
238
|
+
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
# @private
|
243
|
+
def check_active_job_adapter
|
244
|
+
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
|
245
|
+
raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`"
|
246
|
+
end
|
166
247
|
end
|
167
248
|
end
|
168
249
|
end
|
@@ -35,8 +35,8 @@ module RSpec
|
|
35
35
|
# @api private
|
36
36
|
def failure_message
|
37
37
|
if @redirect_is
|
38
|
-
rescued_exception.message[
|
39
|
-
"was a redirect to <#{@redirect_is}>"
|
38
|
+
rescued_exception.message[/(.*?)( but|$)/, 1] +
|
39
|
+
" but was a redirect to <#{@redirect_is}>"
|
40
40
|
else
|
41
41
|
rescued_exception.message
|
42
42
|
end
|
data/lib/rspec/rails/version.rb
CHANGED
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: 3.5.0.
|
4
|
+
version: 3.5.0.beta4
|
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: 2016-
|
47
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
48
48
|
dependencies:
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: activesupport
|
@@ -94,56 +94,56 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - '='
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 3.5.0.
|
97
|
+
version: 3.5.0.beta4
|
98
98
|
type: :runtime
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - '='
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 3.5.0.
|
104
|
+
version: 3.5.0.beta4
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: rspec-expectations
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - '='
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: 3.5.0.
|
111
|
+
version: 3.5.0.beta4
|
112
112
|
type: :runtime
|
113
113
|
prerelease: false
|
114
114
|
version_requirements: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - '='
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: 3.5.0.
|
118
|
+
version: 3.5.0.beta4
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
120
|
name: rspec-mocks
|
121
121
|
requirement: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - '='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: 3.5.0.
|
125
|
+
version: 3.5.0.beta4
|
126
126
|
type: :runtime
|
127
127
|
prerelease: false
|
128
128
|
version_requirements: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - '='
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 3.5.0.
|
132
|
+
version: 3.5.0.beta4
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: rspec-support
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - '='
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 3.5.0.
|
139
|
+
version: 3.5.0.beta4
|
140
140
|
type: :runtime
|
141
141
|
prerelease: false
|
142
142
|
version_requirements: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - '='
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: 3.5.0.
|
146
|
+
version: 3.5.0.beta4
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: cucumber
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- lib/rspec/rails/extensions.rb
|
252
252
|
- lib/rspec/rails/extensions/active_record/proxy.rb
|
253
253
|
- lib/rspec/rails/feature_check.rb
|
254
|
+
- lib/rspec/rails/file_fixture_support.rb
|
254
255
|
- lib/rspec/rails/fixture_support.rb
|
255
256
|
- lib/rspec/rails/matchers.rb
|
256
257
|
- lib/rspec/rails/matchers/active_job.rb
|
@@ -290,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
291
|
version: 1.3.1
|
291
292
|
requirements: []
|
292
293
|
rubyforge_project:
|
293
|
-
rubygems_version: 2.
|
294
|
+
rubygems_version: 2.2.2
|
294
295
|
signing_key:
|
295
296
|
specification_version: 4
|
296
297
|
summary: RSpec for Rails
|
metadata.gz.sig
CHANGED
Binary file
|