rspec-rails 4.0.0.beta3 → 4.0.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/Capybara.md +5 -54
- data/Changelog.md +70 -12
- data/README.md +4 -5
- data/lib/generators/rspec/controller/controller_generator.rb +13 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +1 -1
- data/lib/generators/rspec/feature/feature_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
- data/lib/generators/rspec/integration/integration_generator.rb +3 -3
- data/lib/generators/rspec/mailer/mailer_generator.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +4 -4
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +26 -18
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +0 -6
- data/lib/rspec/rails/adapters.rb +10 -76
- data/lib/rspec/rails/configuration.rb +35 -35
- data/lib/rspec/rails/example/channel_example_group.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +4 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -10
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +10 -4
- data/lib/rspec/rails/example/view_example_group.rb +38 -48
- data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
- data/lib/rspec/rails/feature_check.rb +1 -28
- data/lib/rspec/rails/fixture_file_upload_support.rb +1 -1
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
- data/lib/rspec/rails/matchers/action_cable.rb +1 -1
- data/lib/rspec/rails/matchers/active_job.rb +126 -16
- data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +6 -3
- data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
- data/lib/rspec/rails/matchers/routing_matchers.rb +11 -11
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +3 -3
- data/lib/rspec-rails.rb +6 -9
- data.tar.gz.sig +0 -0
- metadata +30 -29
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- data/lib/generators/rspec/observer/templates/observer_spec.rb +0 -7
@@ -5,52 +5,58 @@ module RSpec
|
|
5
5
|
if defined?(ActiveRecord::TestFixtures)
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
include RSpec::Rails::SetupAndTeardownAdapter
|
8
|
-
include RSpec::Rails::MinitestLifecycleAdapter
|
8
|
+
include RSpec::Rails::MinitestLifecycleAdapter
|
9
9
|
include RSpec::Rails::MinitestAssertionAdapter
|
10
10
|
include ActiveRecord::TestFixtures
|
11
11
|
|
12
12
|
included do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# should be part of the 3.1 release, at which point we can include
|
17
|
-
# these lines for rails < 3.1.
|
18
|
-
ActiveSupport::TestCase.class_exec do
|
19
|
-
include ActiveRecord::TestFixtures
|
13
|
+
if RSpec.configuration.use_active_record?
|
14
|
+
include Fixtures
|
15
|
+
|
20
16
|
self.fixture_path = RSpec.configuration.fixture_path
|
21
|
-
|
22
|
-
|
17
|
+
if ::Rails::VERSION::STRING > '5'
|
18
|
+
self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
|
19
|
+
else
|
20
|
+
self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
|
21
|
+
end
|
22
|
+
self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
|
23
23
|
|
24
|
-
|
25
|
-
if ::Rails::VERSION::STRING > '5'
|
26
|
-
self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
|
27
|
-
else
|
28
|
-
self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
|
24
|
+
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
|
29
25
|
end
|
30
|
-
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
module Fixtures
|
29
|
+
extend ActiveSupport::Concern
|
30
|
+
|
31
|
+
class_methods do
|
32
|
+
def fixtures(*args)
|
33
|
+
orig_methods = private_instance_methods
|
34
|
+
super.tap do
|
35
|
+
new_methods = private_instance_methods - orig_methods
|
36
|
+
new_methods.each do |method_name|
|
37
|
+
proxy_method_warning_if_called_in_before_context_scope(method_name)
|
38
|
+
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
def proxy_method_warning_if_called_in_before_context_scope(method_name)
|
43
|
+
orig_implementation = instance_method(method_name)
|
44
|
+
define_method(method_name) do |*args, &blk|
|
45
|
+
if inspect.include?("before(:context)")
|
46
|
+
RSpec.warn_with("Calling fixture method in before :context ")
|
47
|
+
else
|
48
|
+
orig_implementation.bind(self).call(*args, &blk)
|
49
|
+
end
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
|
54
|
+
if ::Rails.version.to_f >= 6.1
|
55
|
+
# @private return the example name for TestFixtures
|
56
|
+
def name
|
57
|
+
@example
|
58
|
+
end
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -8,15 +8,15 @@ module RSpec
|
|
8
8
|
def initialize(target, channel:)
|
9
9
|
@target = target
|
10
10
|
@channel = channel
|
11
|
-
@block =
|
11
|
+
@block = proc { }
|
12
12
|
@data = nil
|
13
13
|
set_expected_number(:exactly, 1)
|
14
14
|
end
|
15
15
|
|
16
|
-
def with(data = nil)
|
16
|
+
def with(data = nil, &block)
|
17
17
|
@data = data
|
18
18
|
@data = @data.with_indifferent_access if @data.is_a?(Hash)
|
19
|
-
@block =
|
19
|
+
@block = block if block
|
20
20
|
self
|
21
21
|
end
|
22
22
|
|
@@ -48,7 +48,7 @@ module RSpec
|
|
48
48
|
def have_broadcasted_to(target = nil)
|
49
49
|
check_action_cable_adapter
|
50
50
|
|
51
|
-
ActionCable::HaveBroadcastedTo.new(target, :
|
51
|
+
ActionCable::HaveBroadcastedTo.new(target, channel: described_class)
|
52
52
|
end
|
53
53
|
alias_method :broadcast_to, :have_broadcasted_to
|
54
54
|
|
@@ -15,7 +15,7 @@ module RSpec
|
|
15
15
|
@args = []
|
16
16
|
@queue = nil
|
17
17
|
@at = nil
|
18
|
-
@block =
|
18
|
+
@block = proc { }
|
19
19
|
set_expected_number(:exactly, 1)
|
20
20
|
end
|
21
21
|
|
@@ -26,7 +26,7 @@ module RSpec
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def on_queue(queue)
|
29
|
-
@queue = queue
|
29
|
+
@queue = queue.to_s
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
@@ -67,7 +67,7 @@ module RSpec
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def failure_message
|
70
|
-
"expected to
|
70
|
+
"expected to #{self.class::FAILURE_MESSAGE_EXPECTATION_ACTION} #{base_message}".tap do |msg|
|
71
71
|
if @unmatching_jobs.any?
|
72
72
|
msg << "\nQueued jobs:"
|
73
73
|
@unmatching_jobs.each do |job|
|
@@ -78,7 +78,7 @@ module RSpec
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def failure_message_when_negated
|
81
|
-
"expected not to
|
81
|
+
"expected not to #{self.class::FAILURE_MESSAGE_EXPECTATION_ACTION} #{base_message}"
|
82
82
|
end
|
83
83
|
|
84
84
|
def message_expectation_modifier
|
@@ -97,7 +97,7 @@ module RSpec
|
|
97
97
|
|
98
98
|
def check(jobs)
|
99
99
|
@matching_jobs, @unmatching_jobs = jobs.partition do |job|
|
100
|
-
if job_match?(job) && arguments_match?(job) &&
|
100
|
+
if job_match?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job)
|
101
101
|
args = deserialize_arguments(job)
|
102
102
|
@block.call(*args)
|
103
103
|
true
|
@@ -119,7 +119,7 @@ module RSpec
|
|
119
119
|
msg << " with #{@args}," if @args.any?
|
120
120
|
msg << " on queue #{@queue}," if @queue
|
121
121
|
msg << " at #{@at.inspect}," if @at
|
122
|
-
msg << " but
|
122
|
+
msg << " but #{self.class::MESSAGE_EXPECTATION_ACTION} #{@matching_jobs_count}"
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -148,19 +148,18 @@ module RSpec
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
def
|
152
|
-
|
153
|
-
end
|
151
|
+
def queue_match?(job)
|
152
|
+
return true unless @queue
|
154
153
|
|
155
|
-
|
156
|
-
{}.tap do |attributes|
|
157
|
-
attributes[:at] = serialized_at if @at
|
158
|
-
attributes[:queue] = @queue if @queue
|
159
|
-
end
|
154
|
+
@queue == job[:queue]
|
160
155
|
end
|
161
156
|
|
162
|
-
def
|
163
|
-
|
157
|
+
def at_match?(job)
|
158
|
+
return true unless @at
|
159
|
+
return job[:at].nil? if @at == :no_wait
|
160
|
+
return false unless job[:at]
|
161
|
+
|
162
|
+
values_match?(@at, Time.at(job[:at]))
|
164
163
|
end
|
165
164
|
|
166
165
|
def set_expected_number(relativity, count)
|
@@ -194,6 +193,9 @@ module RSpec
|
|
194
193
|
|
195
194
|
# @private
|
196
195
|
class HaveEnqueuedJob < Base
|
196
|
+
FAILURE_MESSAGE_EXPECTATION_ACTION = 'enqueue'.freeze
|
197
|
+
MESSAGE_EXPECTATION_ACTION = 'enqueued'.freeze
|
198
|
+
|
197
199
|
def initialize(job)
|
198
200
|
super()
|
199
201
|
@job = job
|
@@ -218,6 +220,9 @@ module RSpec
|
|
218
220
|
|
219
221
|
# @private
|
220
222
|
class HaveBeenEnqueued < Base
|
223
|
+
FAILURE_MESSAGE_EXPECTATION_ACTION = 'enqueue'.freeze
|
224
|
+
MESSAGE_EXPECTATION_ACTION = 'enqueued'.freeze
|
225
|
+
|
221
226
|
def matches?(job)
|
222
227
|
@job = job
|
223
228
|
check(queue_adapter.enqueued_jobs)
|
@@ -229,6 +234,38 @@ module RSpec
|
|
229
234
|
!matches?(proc)
|
230
235
|
end
|
231
236
|
end
|
237
|
+
|
238
|
+
# @private
|
239
|
+
class HavePerformedJob < Base
|
240
|
+
FAILURE_MESSAGE_EXPECTATION_ACTION = 'perform'.freeze
|
241
|
+
MESSAGE_EXPECTATION_ACTION = 'performed'.freeze
|
242
|
+
|
243
|
+
def initialize(job)
|
244
|
+
super()
|
245
|
+
@job = job
|
246
|
+
end
|
247
|
+
|
248
|
+
def matches?(proc)
|
249
|
+
raise ArgumentError, "have_performed_job only supports block expectations" unless Proc === proc
|
250
|
+
|
251
|
+
original_performed_jobs_count = queue_adapter.performed_jobs.count
|
252
|
+
proc.call
|
253
|
+
in_block_jobs = queue_adapter.performed_jobs.drop(original_performed_jobs_count)
|
254
|
+
|
255
|
+
check(in_block_jobs)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# @private
|
260
|
+
class HaveBeenPerformed < Base
|
261
|
+
FAILURE_MESSAGE_EXPECTATION_ACTION = 'perform'.freeze
|
262
|
+
MESSAGE_EXPECTATION_ACTION = 'performed'.freeze
|
263
|
+
|
264
|
+
def matches?(job)
|
265
|
+
@job = job
|
266
|
+
check(queue_adapter.performed_jobs)
|
267
|
+
end
|
268
|
+
end
|
232
269
|
end
|
233
270
|
|
234
271
|
# @api public
|
@@ -316,6 +353,79 @@ module RSpec
|
|
316
353
|
ActiveJob::HaveBeenEnqueued.new
|
317
354
|
end
|
318
355
|
|
356
|
+
# @api public
|
357
|
+
# Passes if a job has been performed inside block. May chain at_least, at_most or exactly to specify a number of times.
|
358
|
+
#
|
359
|
+
# @example
|
360
|
+
# expect {
|
361
|
+
# perform_jobs { HeavyLiftingJob.perform_later }
|
362
|
+
# }.to have_performed_job
|
363
|
+
#
|
364
|
+
# expect {
|
365
|
+
# perform_jobs {
|
366
|
+
# HelloJob.perform_later
|
367
|
+
# HeavyLiftingJob.perform_later
|
368
|
+
# }
|
369
|
+
# }.to have_performed_job(HelloJob).exactly(:once)
|
370
|
+
#
|
371
|
+
# expect {
|
372
|
+
# perform_jobs { 3.times { HelloJob.perform_later } }
|
373
|
+
# }.to have_performed_job(HelloJob).at_least(2).times
|
374
|
+
#
|
375
|
+
# expect {
|
376
|
+
# perform_jobs { HelloJob.perform_later }
|
377
|
+
# }.to have_performed_job(HelloJob).at_most(:twice)
|
378
|
+
#
|
379
|
+
# expect {
|
380
|
+
# perform_jobs {
|
381
|
+
# HelloJob.perform_later
|
382
|
+
# HeavyLiftingJob.perform_later
|
383
|
+
# }
|
384
|
+
# }.to have_performed_job(HelloJob).and have_performed_job(HeavyLiftingJob)
|
385
|
+
#
|
386
|
+
# expect {
|
387
|
+
# perform_jobs {
|
388
|
+
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
389
|
+
# }
|
390
|
+
# }.to have_performed_job.with(42).on_queue("low").at(Date.tomorrow.noon)
|
391
|
+
def have_performed_job(job = nil)
|
392
|
+
check_active_job_adapter
|
393
|
+
ActiveJob::HavePerformedJob.new(job)
|
394
|
+
end
|
395
|
+
alias_method :perform_job, :have_performed_job
|
396
|
+
|
397
|
+
# @api public
|
398
|
+
# Passes if a job has been performed. May chain at_least, at_most or exactly to specify a number of times.
|
399
|
+
#
|
400
|
+
# @example
|
401
|
+
# before do
|
402
|
+
# ActiveJob::Base.queue_adapter.performed_jobs.clear
|
403
|
+
# ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
|
404
|
+
# ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
|
405
|
+
# end
|
406
|
+
#
|
407
|
+
# HeavyLiftingJob.perform_later
|
408
|
+
# expect(HeavyLiftingJob).to have_been_performed
|
409
|
+
#
|
410
|
+
# HelloJob.perform_later
|
411
|
+
# HeavyLiftingJob.perform_later
|
412
|
+
# expect(HeavyLiftingJob).to have_been_performed.exactly(:once)
|
413
|
+
#
|
414
|
+
# 3.times { HelloJob.perform_later }
|
415
|
+
# expect(HelloJob).to have_been_performed.at_least(2).times
|
416
|
+
#
|
417
|
+
# HelloJob.perform_later
|
418
|
+
# HeavyLiftingJob.perform_later
|
419
|
+
# expect(HelloJob).to have_been_performed
|
420
|
+
# expect(HeavyLiftingJob).to have_been_performed
|
421
|
+
#
|
422
|
+
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
423
|
+
# expect(HelloJob).to have_been_performed.with(42).on_queue("low").at(Date.tomorrow.noon)
|
424
|
+
def have_been_performed
|
425
|
+
check_active_job_adapter
|
426
|
+
ActiveJob::HaveBeenPerformed.new
|
427
|
+
end
|
428
|
+
|
319
429
|
private
|
320
430
|
|
321
431
|
# @private
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Rails
|
3
3
|
module Matchers
|
4
|
-
# @
|
4
|
+
# @api private
|
5
|
+
#
|
6
|
+
# Base class to build matchers. Should not be instantiated directly.
|
5
7
|
class BaseMatcher
|
6
8
|
include RSpec::Matchers::Composable
|
7
9
|
|
@@ -119,15 +121,7 @@ module RSpec
|
|
119
121
|
raise "#{self.class.name} needs to supply#{ivar_list}"
|
120
122
|
end
|
121
123
|
|
122
|
-
|
123
|
-
# :nocov:
|
124
|
-
def present_ivars
|
125
|
-
instance_variables.map(&:to_sym)
|
126
|
-
end
|
127
|
-
# :nocov:
|
128
|
-
else
|
129
|
-
alias present_ivars instance_variables
|
130
|
-
end
|
124
|
+
alias present_ivars instance_variables
|
131
125
|
|
132
126
|
# @private
|
133
127
|
module HashFormatting
|
@@ -1,4 +1,7 @@
|
|
1
|
-
require
|
1
|
+
# We require the minimum amount of rspec-mocks possible to avoid
|
2
|
+
# conflicts with other mocking frameworks.
|
3
|
+
# See: https://github.com/rspec/rspec-rails/issues/2252
|
4
|
+
require "rspec/mocks/argument_matchers"
|
2
5
|
require "rspec/rails/matchers/active_job"
|
3
6
|
|
4
7
|
module RSpec
|
@@ -11,7 +14,7 @@ module RSpec
|
|
11
14
|
class HaveEnqueuedMail < ActiveJob::HaveEnqueuedJob
|
12
15
|
MAILER_JOB_METHOD = 'deliver_now'.freeze
|
13
16
|
|
14
|
-
include RSpec::Mocks::
|
17
|
+
include RSpec::Mocks::ArgumentMatchers
|
15
18
|
|
16
19
|
def initialize(mailer_class, method_name)
|
17
20
|
super(nil)
|
@@ -90,7 +93,7 @@ module RSpec
|
|
90
93
|
end
|
91
94
|
|
92
95
|
def yield_mail_args(block)
|
93
|
-
|
96
|
+
proc { |*job_args| block.call(*(job_args - base_mailer_args)) }
|
94
97
|
end
|
95
98
|
|
96
99
|
def check_active_job_adapter
|
@@ -73,7 +73,7 @@ module RSpec
|
|
73
73
|
# @example
|
74
74
|
# expect(response).to have_http_status(404)
|
75
75
|
#
|
76
|
-
# @see RSpec::Rails::Matchers
|
76
|
+
# @see RSpec::Rails::Matchers#have_http_status
|
77
77
|
class NumericCode < RSpec::Rails::Matchers::BaseMatcher
|
78
78
|
include HaveHttpStatus
|
79
79
|
|
@@ -123,7 +123,7 @@ module RSpec
|
|
123
123
|
# @example
|
124
124
|
# expect(response).to have_http_status(:created)
|
125
125
|
#
|
126
|
-
# @see RSpec::Rails::Matchers
|
126
|
+
# @see RSpec::Rails::Matchers#have_http_status
|
127
127
|
# @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb `Rack::Utils::SYMBOL_TO_STATUS_CODE`
|
128
128
|
class SymbolicStatus < RSpec::Rails::Matchers::BaseMatcher
|
129
129
|
include HaveHttpStatus
|
@@ -236,8 +236,8 @@ module RSpec
|
|
236
236
|
# expect(response).to have_http_status(:missing)
|
237
237
|
# expect(response).to have_http_status(:redirect)
|
238
238
|
#
|
239
|
-
# @see RSpec::Rails::Matchers
|
240
|
-
# @see ActionDispatch::TestResponse
|
239
|
+
# @see RSpec::Rails::Matchers#have_http_status
|
240
|
+
# @see https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
|
241
241
|
class GenericStatus < RSpec::Rails::Matchers::BaseMatcher
|
242
242
|
include HaveHttpStatus
|
243
243
|
|
@@ -293,9 +293,9 @@ module RSpec
|
|
293
293
|
protected
|
294
294
|
|
295
295
|
RESPONSE_METHODS = {
|
296
|
-
:
|
297
|
-
:
|
298
|
-
:
|
296
|
+
success: 'successful',
|
297
|
+
error: 'server_error',
|
298
|
+
missing: 'not_found'
|
299
299
|
}.freeze
|
300
300
|
|
301
301
|
def check_expected_status(test_response, expected)
|
@@ -14,7 +14,7 @@ module RSpec
|
|
14
14
|
@expected.merge!(expected[0])
|
15
15
|
else
|
16
16
|
controller, action = expected[0].split('#')
|
17
|
-
@expected.merge!(:
|
17
|
+
@expected.merge!(controller: controller, action: action)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -26,7 +26,7 @@ module RSpec
|
|
26
26
|
path, query = *verb_to_path_map.values.first.split('?')
|
27
27
|
@scope.assert_recognizes(
|
28
28
|
@expected,
|
29
|
-
{
|
29
|
+
{method: verb_to_path_map.keys.first, path: path},
|
30
30
|
Rack::Utils.parse_nested_query(query)
|
31
31
|
)
|
32
32
|
end
|
@@ -50,12 +50,12 @@ module RSpec
|
|
50
50
|
#
|
51
51
|
# @example
|
52
52
|
#
|
53
|
-
# expect(:
|
54
|
-
# :
|
55
|
-
# :
|
53
|
+
# expect(get: "/things/special").to route_to(
|
54
|
+
# controller: "things",
|
55
|
+
# action: "special"
|
56
56
|
# )
|
57
57
|
#
|
58
|
-
# expect(:
|
58
|
+
# expect(get: "/things/special").to route_to("things#special")
|
59
59
|
#
|
60
60
|
# @see https://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
|
61
61
|
def route_to(*expected)
|
@@ -72,7 +72,7 @@ module RSpec
|
|
72
72
|
@actual = path
|
73
73
|
match_unless_raises ActionController::RoutingError do
|
74
74
|
@routing_options = @scope.routes.recognize_path(
|
75
|
-
path.values.first, :
|
75
|
+
path.values.first, method: path.keys.first
|
76
76
|
)
|
77
77
|
end
|
78
78
|
end
|
@@ -95,9 +95,9 @@ module RSpec
|
|
95
95
|
# `RouteSet#recognize_path`.
|
96
96
|
#
|
97
97
|
# @example You can use route helpers provided by rspec-rails.
|
98
|
-
# expect(:
|
99
|
-
# expect(:
|
100
|
-
# expect(:
|
98
|
+
# expect(get: "/a/path").to be_routable
|
99
|
+
# expect(post: "/another/path").to be_routable
|
100
|
+
# expect(put: "/yet/another/path").to be_routable
|
101
101
|
def be_routable
|
102
102
|
BeRoutableMatcher.new(self)
|
103
103
|
end
|
@@ -115,7 +115,7 @@ module RSpec
|
|
115
115
|
# Shorthand method for matching this type of route.
|
116
116
|
%w[get post put patch delete options head].each do |method|
|
117
117
|
define_method method do |path|
|
118
|
-
{
|
118
|
+
{method.to_sym => path}
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -3,19 +3,19 @@ if default = Rake.application.instance_variable_get('@tasks')['default']
|
|
3
3
|
default.prerequisites.delete('test')
|
4
4
|
end
|
5
5
|
|
6
|
-
task :
|
6
|
+
task default: :spec
|
7
7
|
|
8
|
-
task :
|
8
|
+
task stats: "spec:statsetup"
|
9
9
|
|
10
10
|
desc "Run all specs in spec directory (excluding plugin specs)"
|
11
|
-
RSpec::Core::RakeTask.new(:
|
11
|
+
RSpec::Core::RakeTask.new(spec: "spec:prepare")
|
12
12
|
|
13
13
|
namespace :spec do
|
14
14
|
types = begin
|
15
|
-
dirs = Dir['./spec/**/*_spec.rb']
|
16
|
-
map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
|
17
|
-
uniq
|
18
|
-
select { |f| File.directory?(f) }
|
15
|
+
dirs = Dir['./spec/**/*_spec.rb']
|
16
|
+
.map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
|
17
|
+
.uniq
|
18
|
+
.select { |f| File.directory?(f) }
|
19
19
|
Hash[dirs.map { |d| [d.split('/').last, d] }]
|
20
20
|
end
|
21
21
|
|
@@ -35,16 +35,6 @@ namespace :spec do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
# RCov task only enabled for Ruby 1.8
|
39
|
-
if RUBY_VERSION < '1.9'
|
40
|
-
desc "Run all specs with rcov"
|
41
|
-
RSpec::Core::RakeTask.new(:rcov => "spec:prepare") do |t|
|
42
|
-
t.rcov = true
|
43
|
-
t.pattern = "./spec/**/*_spec.rb"
|
44
|
-
t.rcov_opts = '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-,spec'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
38
|
task :statsetup do
|
49
39
|
require 'rails/code_statistics'
|
50
40
|
types.each do |type, dir|
|
@@ -9,31 +9,26 @@ rescue LoadError
|
|
9
9
|
end
|
10
10
|
|
11
11
|
if defined?(Capybara)
|
12
|
-
require 'rspec/support/comparable_version'
|
13
|
-
unless RSpec::Support::ComparableVersion.new(Capybara::VERSION) >= '2.2.0'
|
14
|
-
raise "You are using capybara #{Capybara::VERSION}. RSpec requires >= 2.2.0."
|
15
|
-
end
|
16
|
-
|
17
12
|
RSpec.configure do |c|
|
18
13
|
if defined?(Capybara::DSL)
|
19
|
-
c.include Capybara::DSL, :
|
14
|
+
c.include Capybara::DSL, type: :feature
|
20
15
|
if defined?(ActionPack) && ActionPack::VERSION::STRING >= "5.1"
|
21
|
-
c.include Capybara::DSL, :
|
16
|
+
c.include Capybara::DSL, type: :system
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
if defined?(Capybara::RSpecMatchers)
|
26
|
-
c.include Capybara::RSpecMatchers, :
|
27
|
-
c.include Capybara::RSpecMatchers, :
|
28
|
-
c.include Capybara::RSpecMatchers, :
|
29
|
-
c.include Capybara::RSpecMatchers, :
|
30
|
-
c.include Capybara::RSpecMatchers, :
|
31
|
-
c.include Capybara::RSpecMatchers, :
|
21
|
+
c.include Capybara::RSpecMatchers, type: :view
|
22
|
+
c.include Capybara::RSpecMatchers, type: :helper
|
23
|
+
c.include Capybara::RSpecMatchers, type: :mailer
|
24
|
+
c.include Capybara::RSpecMatchers, type: :controller
|
25
|
+
c.include Capybara::RSpecMatchers, type: :feature
|
26
|
+
c.include Capybara::RSpecMatchers, type: :system
|
32
27
|
end
|
33
28
|
|
34
29
|
unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
|
35
|
-
c.include Capybara, :
|
36
|
-
c.include Capybara, :
|
30
|
+
c.include Capybara, type: :request
|
31
|
+
c.include Capybara, type: :controller
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -20,7 +20,7 @@ module RSpec
|
|
20
20
|
# view_path_builder.path_for({ :controller => 'posts', :action => 'delete' })
|
21
21
|
# # => ActionController::UrlGenerationError: No route matches {:action=>"delete", :controller=>"posts"}
|
22
22
|
def path_for(path_params)
|
23
|
-
url_for(path_params.merge(:
|
23
|
+
url_for(path_params.merge(only_path: true))
|
24
24
|
rescue => e
|
25
25
|
e.message
|
26
26
|
end
|
@@ -55,9 +55,9 @@ module RSpec
|
|
55
55
|
"",
|
56
56
|
template.identifier,
|
57
57
|
EmptyTemplateHandler,
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
58
|
+
virtual_path: template.virtual_path,
|
59
|
+
format: template_format(template),
|
60
|
+
locals: []
|
61
61
|
)
|
62
62
|
end
|
63
63
|
end
|
data/lib/rspec-rails.rb
CHANGED
@@ -15,8 +15,7 @@ module RSpec
|
|
15
15
|
SourceAnnotationExtractor::Annotation.register_directories("spec")
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
18
|
+
generators = config.app_generators
|
20
19
|
generators.integration_tool :rspec
|
21
20
|
generators.test_framework :rspec
|
22
21
|
|
@@ -31,9 +30,9 @@ module RSpec
|
|
31
30
|
# This is called after the environment has been loaded but before Rails
|
32
31
|
# sets the default for the `preview_path`
|
33
32
|
initializer "rspec_rails.action_mailer",
|
34
|
-
:
|
35
|
-
|
36
|
-
|
33
|
+
before: "action_mailer.set_configs" do |app|
|
34
|
+
setup_preview_path(app)
|
35
|
+
end
|
37
36
|
|
38
37
|
private
|
39
38
|
|
@@ -47,9 +46,7 @@ module RSpec
|
|
47
46
|
def config_preview_path?(options)
|
48
47
|
# We cannot use `respond_to?(:show_previews)` here as it will always
|
49
48
|
# return `true`.
|
50
|
-
if
|
51
|
-
::Rails.env.development?
|
52
|
-
elsif options.show_previews.nil?
|
49
|
+
if options.show_previews.nil?
|
53
50
|
options.show_previews = ::Rails.env.development?
|
54
51
|
else
|
55
52
|
options.show_previews
|
@@ -74,7 +71,7 @@ module RSpec
|
|
74
71
|
# not respond to the method. However, we cannot use
|
75
72
|
# `config.action_mailer.respond_to?(:preview_path)` here as it will
|
76
73
|
# always return `true`.
|
77
|
-
config.respond_to?(:action_mailer)
|
74
|
+
config.respond_to?(:action_mailer)
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|