rspec-rails 4.0.0.beta3 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +61 -7
- data/README.md +20 -19
- data/lib/generators/rspec.rb +0 -6
- 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/rspec-rails.rb +6 -9
- data/lib/rspec/rails/adapters.rb +10 -76
- data/lib/rspec/rails/configuration.rb +72 -36
- 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/mailbox_example_group.rb +1 -1
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +14 -7
- data/lib/rspec/rails/example/view_example_group.rb +38 -48
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +1 -28
- data/lib/rspec/rails/fixture_file_upload_support.rb +8 -13
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable.rb +1 -1
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
- data/lib/rspec/rails/matchers/active_job.rb +132 -18
- data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +9 -6
- data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- 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
- metadata +34 -33
- 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,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= ns_file_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 -%>
|
10
10
|
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
|
11
11
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
<% module_namespacing do -%>
|
16
|
+
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
18
|
+
# adjust the attributes here as well.
|
19
|
+
let(:valid_attributes) {
|
20
|
+
skip("Add a hash of attributes valid for your model")
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:invalid_attributes) {
|
24
|
+
skip("Add a hash of attributes invalid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
<% unless options[:singleton] -%>
|
28
|
+
describe "GET /index" do
|
29
|
+
it "renders a successful response" do
|
30
|
+
<%= class_name %>.create! valid_attributes
|
31
|
+
get <%= index_helper %>_url
|
32
|
+
expect(response).to be_successful
|
33
|
+
end
|
34
|
+
end
|
35
|
+
<% end -%>
|
36
|
+
|
37
|
+
describe "GET /show" do
|
38
|
+
it "renders a successful response" do
|
39
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
40
|
+
get <%= show_helper.tr('@', '') %>
|
41
|
+
expect(response).to be_successful
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "GET /new" do
|
46
|
+
it "renders a successful response" do
|
47
|
+
get <%= new_helper %>
|
48
|
+
expect(response).to be_successful
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GET /edit" do
|
53
|
+
it "render a successful response" do
|
54
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
55
|
+
get <%= edit_helper.tr('@','') %>
|
56
|
+
expect(response).to be_successful
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "POST /create" do
|
61
|
+
context "with valid parameters" do
|
62
|
+
it "creates a new <%= class_name %>" do
|
63
|
+
expect {
|
64
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
65
|
+
}.to change(<%= class_name %>, :count).by(1)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "redirects to the created <%= ns_file_name %>" do
|
69
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
70
|
+
expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", class_name+".last") %>)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with invalid parameters" do
|
75
|
+
it "does not create a new <%= class_name %>" do
|
76
|
+
expect {
|
77
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
78
|
+
}.to change(<%= class_name %>, :count).by(0)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
82
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
83
|
+
expect(response).to be_successful
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "PATCH /update" do
|
89
|
+
context "with valid parameters" do
|
90
|
+
let(:new_attributes) {
|
91
|
+
skip("Add a hash of attributes valid for your model")
|
92
|
+
}
|
93
|
+
|
94
|
+
it "updates the requested <%= ns_file_name %>" do
|
95
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
97
|
+
<%= file_name %>.reload
|
98
|
+
skip("Add assertions for updated state")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "redirects to the <%= ns_file_name %>" do
|
102
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
103
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
104
|
+
<%= file_name %>.reload
|
105
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "with invalid parameters" do
|
110
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
111
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
112
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
|
113
|
+
expect(response).to be_successful
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "DELETE /destroy" do
|
119
|
+
it "destroys the requested <%= ns_file_name %>" do
|
120
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
121
|
+
expect {
|
122
|
+
delete <%= show_helper.tr('@', '') %>
|
123
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "redirects to the <%= table_name %> list" do
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
+
delete <%= show_helper.tr('@', '') %>
|
129
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
<% end -%>
|
@@ -5,43 +5,41 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing
|
|
5
5
|
describe "routing" do
|
6
6
|
<% unless options[:singleton] -%>
|
7
7
|
it "routes to #index" do
|
8
|
-
expect(:
|
8
|
+
expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
9
9
|
end
|
10
10
|
|
11
11
|
<% end -%>
|
12
12
|
<% unless options[:api] -%>
|
13
13
|
it "routes to #new" do
|
14
|
-
expect(:
|
14
|
+
expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
15
15
|
end
|
16
16
|
|
17
17
|
<% end -%>
|
18
18
|
it "routes to #show" do
|
19
|
-
expect(:
|
19
|
+
expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
|
20
20
|
end
|
21
21
|
|
22
22
|
<% unless options[:api] -%>
|
23
23
|
it "routes to #edit" do
|
24
|
-
expect(:
|
24
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
25
25
|
end
|
26
26
|
|
27
27
|
<% end -%>
|
28
28
|
|
29
29
|
it "routes to #create" do
|
30
|
-
expect(:
|
30
|
+
expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "routes to #update via PUT" do
|
34
|
-
expect(:
|
34
|
+
expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
35
35
|
end
|
36
36
|
|
37
|
-
<% if Rails::VERSION::STRING > '4' -%>
|
38
37
|
it "routes to #update via PATCH" do
|
39
|
-
expect(:
|
38
|
+
expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
40
39
|
end
|
41
40
|
|
42
|
-
<% end -%>
|
43
41
|
it "routes to #destroy" do
|
44
|
-
expect(:
|
42
|
+
expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1")
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
|
5
5
|
before(:each) do
|
6
6
|
@<%= ns_file_name %> = assign(:<%= ns_file_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 -%>
|
10
10
|
<% if !output_attributes.empty? -%>
|
11
11
|
))
|
@@ -5,7 +5,7 @@ if ::Rails::VERSION::STRING >= '5.1'
|
|
5
5
|
module Generators
|
6
6
|
# @private
|
7
7
|
class SystemGenerator < Base
|
8
|
-
class_option :system_specs, :
|
8
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
9
|
|
10
10
|
def generate_system_spec
|
11
11
|
return unless options[:system_specs]
|
@@ -4,9 +4,9 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class ViewGenerator < Base
|
7
|
-
argument :actions, :
|
7
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
8
8
|
|
9
|
-
class_option :template_engine, :
|
9
|
+
class_option :template_engine, desc: "Template engine to generate view files"
|
10
10
|
|
11
11
|
def create_view_specs
|
12
12
|
empty_directory File.join("spec", "views", file_path)
|
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/lib/rspec/rails/adapters.rb
CHANGED
@@ -19,68 +19,15 @@ module RSpec
|
|
19
19
|
end
|
20
20
|
private_class_method :disable_testunit_autorun
|
21
21
|
|
22
|
-
if
|
23
|
-
|
24
|
-
gem 'minitest'
|
25
|
-
else
|
26
|
-
require 'minitest'
|
27
|
-
end
|
28
|
-
require 'minitest/assertions'
|
29
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
30
|
-
# loaded.
|
31
|
-
Assertions = Minitest::Assertions
|
32
|
-
elsif RUBY_VERSION >= '2.2.0'
|
33
|
-
# Minitest / TestUnit has been removed from ruby core. However, we are
|
34
|
-
# on an old Rails version and must load the appropriate gem
|
35
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
36
|
-
# ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency
|
37
|
-
# This gem has no `lib/minitest.rb` file.
|
38
|
-
gem 'minitest' if defined?(Kernel.gem)
|
39
|
-
require 'minitest/unit'
|
40
|
-
Assertions = MiniTest::Assertions
|
41
|
-
elsif ::Rails::VERSION::STRING >= '3.2.21'
|
42
|
-
# TODO: Change the above check to >= '3.2.22' once it's released
|
43
|
-
begin
|
44
|
-
# Test::Unit "helpfully" sets up autoload for its `AutoRunner`.
|
45
|
-
# While we do not reference it directly, when we load the `TestCase`
|
46
|
-
# classes from AS (ActiveSupport), AS kindly references `AutoRunner`
|
47
|
-
# for everyone.
|
48
|
-
#
|
49
|
-
# To handle this we need to pre-emptively load 'test/unit' and make
|
50
|
-
# sure the version installed has `AutoRunner` (the 3.x line does to
|
51
|
-
# date). If so, we turn the auto runner off.
|
52
|
-
require 'test/unit'
|
53
|
-
require 'test/unit/assertions'
|
54
|
-
disable_testunit_autorun
|
55
|
-
rescue LoadError => e
|
56
|
-
raise LoadError, <<-ERR.squish, e.backtrace
|
57
|
-
Ruby 2.2+ has removed test/unit from the core library. Rails
|
58
|
-
requires this as a dependency. Please add test-unit gem to your
|
59
|
-
Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})"
|
60
|
-
ERR
|
61
|
-
end
|
62
|
-
Assertions = Test::Unit::Assertions
|
63
|
-
else
|
64
|
-
abort <<-MSG.squish
|
65
|
-
Ruby 2.2+ is not supported on Rails #{::Rails::VERSION::STRING}.
|
66
|
-
Check the Rails release notes for the appropriate update with
|
67
|
-
support.
|
68
|
-
MSG
|
69
|
-
end
|
22
|
+
if defined?(Kernel.gem)
|
23
|
+
gem 'minitest'
|
70
24
|
else
|
71
|
-
|
72
|
-
require 'test/unit/assertions'
|
73
|
-
rescue LoadError
|
74
|
-
# work around for Rubinius not having a std std-lib
|
75
|
-
require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
76
|
-
require 'test/unit/assertions'
|
77
|
-
end
|
78
|
-
# Turn off test unit's auto runner for those using the gem
|
79
|
-
disable_testunit_autorun
|
80
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
81
|
-
# loaded.
|
82
|
-
Assertions = Test::Unit::Assertions
|
25
|
+
require 'minitest'
|
83
26
|
end
|
27
|
+
require 'minitest/assertions'
|
28
|
+
# Constant aliased to either Minitest or TestUnit, depending on what is
|
29
|
+
# loaded.
|
30
|
+
Assertions = Minitest::Assertions
|
84
31
|
|
85
32
|
# @private
|
86
33
|
class AssertionDelegator < Module
|
@@ -199,12 +146,11 @@ module RSpec
|
|
199
146
|
# examples without exposing non-assertion methods in Test::Unit or
|
200
147
|
# Minitest.
|
201
148
|
def assertion_method_names
|
202
|
-
|
203
|
-
public_instance_methods
|
204
|
-
select do |m|
|
149
|
+
::RSpec::Rails::Assertions
|
150
|
+
.public_instance_methods
|
151
|
+
.select do |m|
|
205
152
|
m.to_s =~ /^(assert|flunk|refute)/
|
206
153
|
end
|
207
|
-
methods + test_unit_specific_methods
|
208
154
|
end
|
209
155
|
|
210
156
|
def define_assertion_delegators
|
@@ -214,18 +160,6 @@ module RSpec
|
|
214
160
|
end
|
215
161
|
end
|
216
162
|
end
|
217
|
-
|
218
|
-
# Starting on Rails 4, Minitest is the default testing framework so no
|
219
|
-
# need to add TestUnit specific methods.
|
220
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
221
|
-
def test_unit_specific_methods
|
222
|
-
[]
|
223
|
-
end
|
224
|
-
else
|
225
|
-
def test_unit_specific_methods
|
226
|
-
[:build_message]
|
227
|
-
end
|
228
|
-
end
|
229
163
|
end
|
230
164
|
|
231
165
|
class AssertionDelegator
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop: disable Metrics/ModuleLength
|
1
2
|
module RSpec
|
2
3
|
module Rails
|
3
4
|
# Fake class to document RSpec Rails configuration options. In practice,
|
@@ -25,46 +26,46 @@ module RSpec
|
|
25
26
|
#
|
26
27
|
# @api private
|
27
28
|
DIRECTORY_MAPPINGS = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
29
|
+
channel: %w[spec channels],
|
30
|
+
controller: %w[spec controllers],
|
31
|
+
helper: %w[spec helpers],
|
32
|
+
job: %w[spec jobs],
|
33
|
+
mailer: %w[spec mailers],
|
34
|
+
model: %w[spec models],
|
35
|
+
request: %w[spec (requests|integration|api)],
|
36
|
+
routing: %w[spec routing],
|
37
|
+
view: %w[spec views],
|
38
|
+
feature: %w[spec features],
|
39
|
+
system: %w[spec system],
|
40
|
+
mailbox: %w[spec mailboxes]
|
40
41
|
}
|
41
42
|
|
42
43
|
# Sets up the different example group modules for the different spec types
|
43
44
|
#
|
44
45
|
# @api private
|
45
46
|
def self.add_test_type_configurations(config)
|
46
|
-
config.include RSpec::Rails::ControllerExampleGroup, :
|
47
|
-
config.include RSpec::Rails::HelperExampleGroup, :
|
48
|
-
config.include RSpec::Rails::ModelExampleGroup, :
|
49
|
-
config.include RSpec::Rails::RequestExampleGroup, :
|
50
|
-
config.include RSpec::Rails::RoutingExampleGroup, :
|
51
|
-
config.include RSpec::Rails::ViewExampleGroup, :
|
52
|
-
config.include RSpec::Rails::FeatureExampleGroup, :
|
47
|
+
config.include RSpec::Rails::ControllerExampleGroup, type: :controller
|
48
|
+
config.include RSpec::Rails::HelperExampleGroup, type: :helper
|
49
|
+
config.include RSpec::Rails::ModelExampleGroup, type: :model
|
50
|
+
config.include RSpec::Rails::RequestExampleGroup, type: :request
|
51
|
+
config.include RSpec::Rails::RoutingExampleGroup, type: :routing
|
52
|
+
config.include RSpec::Rails::ViewExampleGroup, type: :view
|
53
|
+
config.include RSpec::Rails::FeatureExampleGroup, type: :feature
|
53
54
|
config.include RSpec::Rails::Matchers
|
54
|
-
config.include RSpec::Rails::SystemExampleGroup, :
|
55
|
+
config.include RSpec::Rails::SystemExampleGroup, type: :system
|
55
56
|
end
|
56
57
|
|
57
58
|
# @private
|
58
|
-
# rubocop:disable Metrics/MethodLength
|
59
|
-
def self.initialize_configuration(config)
|
59
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
60
60
|
config.backtrace_exclusion_patterns << /vendor\//
|
61
61
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
62
62
|
|
63
63
|
# controller settings
|
64
|
-
config.add_setting :infer_base_class_for_anonymous_controllers, :
|
64
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, default: true
|
65
65
|
|
66
66
|
# fixture support
|
67
|
-
config.add_setting :
|
67
|
+
config.add_setting :use_active_record, default: true
|
68
|
+
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
68
69
|
config.add_setting :use_instantiated_fixtures
|
69
70
|
config.add_setting :global_fixtures
|
70
71
|
config.add_setting :fixture_path
|
@@ -80,7 +81,7 @@ module RSpec
|
|
80
81
|
config.include RSpec::Rails::FixtureSupport
|
81
82
|
|
82
83
|
if ::Rails::VERSION::STRING > '5'
|
83
|
-
config.add_setting :file_fixture_path, :
|
84
|
+
config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
|
84
85
|
config.include RSpec::Rails::FileFixtureSupport
|
85
86
|
end
|
86
87
|
|
@@ -93,7 +94,7 @@ module RSpec
|
|
93
94
|
# as a getter. This makes it easier for rspec-rails users because we use
|
94
95
|
# `render_views` directly in example groups, so this aligns the two APIs,
|
95
96
|
# but requires this workaround:
|
96
|
-
config.add_setting :rendering_views, :
|
97
|
+
config.add_setting :rendering_views, default: false
|
97
98
|
|
98
99
|
config.instance_exec do
|
99
100
|
def render_views=(val)
|
@@ -105,13 +106,47 @@ module RSpec
|
|
105
106
|
end
|
106
107
|
|
107
108
|
def render_views?
|
108
|
-
rendering_views
|
109
|
+
rendering_views?
|
110
|
+
end
|
111
|
+
|
112
|
+
undef :rendering_views? if respond_to?(:rendering_views?)
|
113
|
+
def rendering_views?
|
114
|
+
!!rendering_views
|
115
|
+
end
|
116
|
+
|
117
|
+
# Define boolean predicates rather than relying on rspec-core due
|
118
|
+
# to the bug fix in rspec/rspec-core#2736, note some of these
|
119
|
+
# predicates are a bit nonsensical, but they exist for backwards
|
120
|
+
# compatibility, we can tidy these up in `rspec-rails` 5.
|
121
|
+
undef :fixture_path? if respond_to?(:fixture_path?)
|
122
|
+
def fixture_path?
|
123
|
+
!!fixture_path
|
124
|
+
end
|
125
|
+
|
126
|
+
undef :global_fixtures? if respond_to?(:global_fixtures?)
|
127
|
+
def global_fixtures?
|
128
|
+
!!global_fixtures
|
129
|
+
end
|
130
|
+
|
131
|
+
undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
|
132
|
+
def infer_base_class_for_anonymous_controllers?
|
133
|
+
!!infer_base_class_for_anonymous_controllers
|
134
|
+
end
|
135
|
+
|
136
|
+
undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
|
137
|
+
def use_instantiated_fixtures?
|
138
|
+
!!use_instantiated_fixtures
|
139
|
+
end
|
140
|
+
|
141
|
+
undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
|
142
|
+
def use_transactional_fixtures?
|
143
|
+
!!use_transactional_fixtures
|
109
144
|
end
|
110
145
|
|
111
146
|
def infer_spec_type_from_file_location!
|
112
147
|
DIRECTORY_MAPPINGS.each do |type, dir_parts|
|
113
148
|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
114
|
-
define_derived_metadata(:
|
149
|
+
define_derived_metadata(file_path: escaped_path) do |metadata|
|
115
150
|
metadata[:type] ||= type
|
116
151
|
end
|
117
152
|
end
|
@@ -129,30 +164,31 @@ module RSpec
|
|
129
164
|
|
130
165
|
if defined?(::Rails::Controller::Testing)
|
131
166
|
[:controller, :view, :request].each do |type|
|
132
|
-
config.include ::Rails::Controller::Testing::TestProcess, :
|
133
|
-
config.include ::Rails::Controller::Testing::TemplateAssertions, :
|
134
|
-
config.include ::Rails::Controller::Testing::Integration, :
|
167
|
+
config.include ::Rails::Controller::Testing::TestProcess, type: type
|
168
|
+
config.include ::Rails::Controller::Testing::TemplateAssertions, type: type
|
169
|
+
config.include ::Rails::Controller::Testing::Integration, type: type
|
135
170
|
end
|
136
171
|
end
|
137
172
|
|
138
173
|
if RSpec::Rails::FeatureCheck.has_action_mailer?
|
139
|
-
config.include RSpec::Rails::MailerExampleGroup, :
|
174
|
+
config.include RSpec::Rails::MailerExampleGroup, type: :mailer
|
175
|
+
config.after { ActionMailer::Base.deliveries.clear }
|
140
176
|
end
|
141
177
|
|
142
178
|
if RSpec::Rails::FeatureCheck.has_active_job?
|
143
|
-
config.include RSpec::Rails::JobExampleGroup, :
|
179
|
+
config.include RSpec::Rails::JobExampleGroup, type: :job
|
144
180
|
end
|
145
181
|
|
146
182
|
if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
147
|
-
config.include RSpec::Rails::ChannelExampleGroup, :
|
183
|
+
config.include RSpec::Rails::ChannelExampleGroup, type: :channel
|
148
184
|
end
|
149
185
|
|
150
186
|
if RSpec::Rails::FeatureCheck.has_action_mailbox?
|
151
|
-
config.include RSpec::Rails::MailboxExampleGroup, :
|
187
|
+
config.include RSpec::Rails::MailboxExampleGroup, type: :mailbox
|
152
188
|
end
|
153
189
|
end
|
154
|
-
# rubocop:enable Metrics/MethodLength
|
155
190
|
|
156
191
|
initialize_configuration RSpec.configuration
|
157
192
|
end
|
158
193
|
end
|
194
|
+
# rubocop: enable Metrics/ModuleLength
|