rspec-rails 3.5.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/Capybara.md +6 -55
- data/Changelog.md +321 -62
- data/README.md +265 -493
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +21 -4
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +4 -4
- data/lib/generators/rspec/generator/generator_generator.rb +24 -0
- data/lib/generators/rspec/generator/templates/generator_spec.rb +6 -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 +27 -14
- data/lib/generators/rspec/integration/integration_generator.rb +4 -4
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
- data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +6 -5
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +52 -86
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +40 -74
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +5 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +13 -12
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +26 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +0 -6
- data/lib/rspec/rails/active_record.rb +1 -1
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +47 -31
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- 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 -9
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +1 -1
- data/lib/rspec/rails/example/rails_example_group.rb +1 -2
- data/lib/rspec/rails/example/request_example_group.rb +1 -3
- data/lib/rspec/rails/example/system_example_group.rb +124 -0
- data/lib/rspec/rails/example/view_example_group.rb +47 -28
- data/lib/rspec/rails/example.rb +3 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/fixture_file_upload_support.rb +40 -0
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +64 -0
- data/lib/rspec/rails/matchers/active_job.rb +208 -18
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +8 -7
- data/lib/rspec/rails/matchers/be_new_record.rb +3 -3
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +198 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +34 -13
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +14 -14
- data/lib/rspec/rails/matchers.rb +11 -0
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +12 -13
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +2 -2
- data/lib/rspec/rails/view_rendering.rb +18 -5
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec-rails.rb +17 -11
- data.tar.gz.sig +0 -0
- metadata +57 -33
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -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 -%>
|
@@ -3,43 +3,44 @@ require "rails_helper"
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
|
5
5
|
describe "routing" do
|
6
|
-
|
7
6
|
<% unless options[:singleton] -%>
|
8
7
|
it "routes to #index" do
|
9
|
-
expect(:
|
8
|
+
expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
10
9
|
end
|
11
10
|
|
12
11
|
<% end -%>
|
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
|
+
<% end -%>
|
17
18
|
it "routes to #show" do
|
18
|
-
expect(:
|
19
|
+
expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
|
19
20
|
end
|
20
21
|
|
22
|
+
<% unless options[:api] -%>
|
21
23
|
it "routes to #edit" do
|
22
|
-
expect(:
|
24
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
23
25
|
end
|
24
26
|
|
27
|
+
<% end -%>
|
28
|
+
|
25
29
|
it "routes to #create" do
|
26
|
-
expect(:
|
30
|
+
expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
|
27
31
|
end
|
28
32
|
|
29
33
|
it "routes to #update via PUT" do
|
30
|
-
expect(:
|
34
|
+
expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
31
35
|
end
|
32
36
|
|
33
|
-
<% if Rails::VERSION::STRING > '4' -%>
|
34
37
|
it "routes to #update via PATCH" do
|
35
|
-
expect(:
|
38
|
+
expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
36
39
|
end
|
37
40
|
|
38
|
-
<% end -%>
|
39
41
|
it "routes to #destroy" do
|
40
|
-
expect(:
|
42
|
+
expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1")
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
44
45
|
end
|
45
46
|
<% 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
|
))
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
if ::Rails::VERSION::STRING >= '5.1'
|
4
|
+
module Rspec
|
5
|
+
module Generators
|
6
|
+
# @private
|
7
|
+
class SystemGenerator < Base
|
8
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
|
+
|
10
|
+
def generate_system_spec
|
11
|
+
return unless options[:system_specs]
|
12
|
+
|
13
|
+
template template_name, File.join('spec/system', class_path, filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_name
|
17
|
+
'system_spec.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
def filename
|
21
|
+
"#{table_name}_spec.rb"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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/generators/rspec.rb
CHANGED
@@ -18,12 +18,6 @@ module Rspec
|
|
18
18
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
if ::Rails::VERSION::STRING < '3.1'
|
23
|
-
def module_namespacing
|
24
|
-
yield if block_given?
|
25
|
-
end
|
26
|
-
end
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -7,7 +7,7 @@ module RSpec
|
|
7
7
|
def self.initialize_activerecord_configuration(config)
|
8
8
|
config.before :suite do
|
9
9
|
# This allows dynamic columns etc to be used on ActiveRecord models when creating instance_doubles
|
10
|
-
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks)
|
10
|
+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks) && (::RSpec::Mocks.respond_to?(:configuration))
|
11
11
|
::RSpec::Mocks.configuration.when_declaring_verifying_double do |possible_model|
|
12
12
|
target = possible_model.target
|
13
13
|
|
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
|
@@ -103,6 +50,7 @@ module RSpec
|
|
103
50
|
assertion_modules.each do |mod|
|
104
51
|
mod.public_instance_methods.each do |method|
|
105
52
|
next if method == :method_missing || method == "method_missing"
|
53
|
+
|
106
54
|
define_method(method.to_sym) do |*args, &block|
|
107
55
|
assertion_instance.send(method.to_sym, *args, &block)
|
108
56
|
end
|
@@ -198,12 +146,11 @@ module RSpec
|
|
198
146
|
# examples without exposing non-assertion methods in Test::Unit or
|
199
147
|
# Minitest.
|
200
148
|
def assertion_method_names
|
201
|
-
|
202
|
-
public_instance_methods
|
203
|
-
select do |m|
|
149
|
+
::RSpec::Rails::Assertions
|
150
|
+
.public_instance_methods
|
151
|
+
.select do |m|
|
204
152
|
m.to_s =~ /^(assert|flunk|refute)/
|
205
153
|
end
|
206
|
-
methods + test_unit_specific_methods
|
207
154
|
end
|
208
155
|
|
209
156
|
def define_assertion_delegators
|
@@ -213,18 +160,6 @@ module RSpec
|
|
213
160
|
end
|
214
161
|
end
|
215
162
|
end
|
216
|
-
|
217
|
-
# Starting on Rails 4, Minitest is the default testing framework so no
|
218
|
-
# need to add TestUnit specific methods.
|
219
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
220
|
-
def test_unit_specific_methods
|
221
|
-
[]
|
222
|
-
end
|
223
|
-
else
|
224
|
-
def test_unit_specific_methods
|
225
|
-
[:build_message]
|
226
|
-
end
|
227
|
-
end
|
228
163
|
end
|
229
164
|
|
230
165
|
class AssertionDelegator
|
@@ -25,42 +25,46 @@ module RSpec
|
|
25
25
|
#
|
26
26
|
# @api private
|
27
27
|
DIRECTORY_MAPPINGS = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
28
|
+
channel: %w[spec channels],
|
29
|
+
controller: %w[spec controllers],
|
30
|
+
helper: %w[spec helpers],
|
31
|
+
job: %w[spec jobs],
|
32
|
+
mailer: %w[spec mailers],
|
33
|
+
model: %w[spec models],
|
34
|
+
request: %w[spec (requests|integration|api)],
|
35
|
+
routing: %w[spec routing],
|
36
|
+
view: %w[spec views],
|
37
|
+
feature: %w[spec features],
|
38
|
+
system: %w[spec system],
|
39
|
+
mailbox: %w[spec mailboxes]
|
37
40
|
}
|
38
41
|
|
39
42
|
# Sets up the different example group modules for the different spec types
|
40
43
|
#
|
41
44
|
# @api private
|
42
45
|
def self.add_test_type_configurations(config)
|
43
|
-
config.include RSpec::Rails::ControllerExampleGroup, :
|
44
|
-
config.include RSpec::Rails::HelperExampleGroup, :
|
45
|
-
config.include RSpec::Rails::ModelExampleGroup, :
|
46
|
-
config.include RSpec::Rails::RequestExampleGroup, :
|
47
|
-
config.include RSpec::Rails::RoutingExampleGroup, :
|
48
|
-
config.include RSpec::Rails::ViewExampleGroup, :
|
49
|
-
config.include RSpec::Rails::FeatureExampleGroup, :
|
46
|
+
config.include RSpec::Rails::ControllerExampleGroup, type: :controller
|
47
|
+
config.include RSpec::Rails::HelperExampleGroup, type: :helper
|
48
|
+
config.include RSpec::Rails::ModelExampleGroup, type: :model
|
49
|
+
config.include RSpec::Rails::RequestExampleGroup, type: :request
|
50
|
+
config.include RSpec::Rails::RoutingExampleGroup, type: :routing
|
51
|
+
config.include RSpec::Rails::ViewExampleGroup, type: :view
|
52
|
+
config.include RSpec::Rails::FeatureExampleGroup, type: :feature
|
50
53
|
config.include RSpec::Rails::Matchers
|
54
|
+
config.include RSpec::Rails::SystemExampleGroup, type: :system
|
51
55
|
end
|
52
56
|
|
53
57
|
# @private
|
54
|
-
# rubocop:disable
|
55
|
-
def self.initialize_configuration(config)
|
58
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
|
56
59
|
config.backtrace_exclusion_patterns << /vendor\//
|
57
60
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
58
61
|
|
59
62
|
# controller settings
|
60
|
-
config.add_setting :infer_base_class_for_anonymous_controllers, :
|
63
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, default: true
|
61
64
|
|
62
65
|
# fixture support
|
63
|
-
config.add_setting :
|
66
|
+
config.add_setting :use_active_record, default: true
|
67
|
+
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
64
68
|
config.add_setting :use_instantiated_fixtures
|
65
69
|
config.add_setting :global_fixtures
|
66
70
|
config.add_setting :fixture_path
|
@@ -76,16 +80,20 @@ module RSpec
|
|
76
80
|
config.include RSpec::Rails::FixtureSupport
|
77
81
|
|
78
82
|
if ::Rails::VERSION::STRING > '5'
|
79
|
-
config.add_setting :file_fixture_path, :
|
83
|
+
config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
|
80
84
|
config.include RSpec::Rails::FileFixtureSupport
|
81
85
|
end
|
86
|
+
|
87
|
+
# Add support for fixture_path on fixture_file_upload
|
88
|
+
config.include RSpec::Rails::FixtureFileUploadSupport
|
89
|
+
|
82
90
|
# This allows us to expose `render_views` as a config option even though it
|
83
91
|
# breaks the convention of other options by using `render_views` as a
|
84
92
|
# command (i.e. `render_views = true`), where it would normally be used
|
85
93
|
# as a getter. This makes it easier for rspec-rails users because we use
|
86
94
|
# `render_views` directly in example groups, so this aligns the two APIs,
|
87
95
|
# but requires this workaround:
|
88
|
-
config.add_setting :rendering_views, :
|
96
|
+
config.add_setting :rendering_views, default: false
|
89
97
|
|
90
98
|
config.instance_exec do
|
91
99
|
def render_views=(val)
|
@@ -103,7 +111,7 @@ module RSpec
|
|
103
111
|
def infer_spec_type_from_file_location!
|
104
112
|
DIRECTORY_MAPPINGS.each do |type, dir_parts|
|
105
113
|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
106
|
-
define_derived_metadata(:
|
114
|
+
define_derived_metadata(file_path: escaped_path) do |metadata|
|
107
115
|
metadata[:type] ||= type
|
108
116
|
end
|
109
117
|
end
|
@@ -121,21 +129,29 @@ module RSpec
|
|
121
129
|
|
122
130
|
if defined?(::Rails::Controller::Testing)
|
123
131
|
[:controller, :view, :request].each do |type|
|
124
|
-
config.include ::Rails::Controller::Testing::TestProcess, :
|
125
|
-
config.include ::Rails::Controller::Testing::TemplateAssertions, :
|
126
|
-
config.include ::Rails::Controller::Testing::Integration, :
|
132
|
+
config.include ::Rails::Controller::Testing::TestProcess, type: type
|
133
|
+
config.include ::Rails::Controller::Testing::TemplateAssertions, type: type
|
134
|
+
config.include ::Rails::Controller::Testing::Integration, type: type
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
130
|
-
if
|
131
|
-
config.include RSpec::Rails::MailerExampleGroup, :
|
138
|
+
if RSpec::Rails::FeatureCheck.has_action_mailer?
|
139
|
+
config.include RSpec::Rails::MailerExampleGroup, type: :mailer
|
140
|
+
config.after { ActionMailer::Base.deliveries.clear }
|
141
|
+
end
|
142
|
+
|
143
|
+
if RSpec::Rails::FeatureCheck.has_active_job?
|
144
|
+
config.include RSpec::Rails::JobExampleGroup, type: :job
|
145
|
+
end
|
146
|
+
|
147
|
+
if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
148
|
+
config.include RSpec::Rails::ChannelExampleGroup, type: :channel
|
132
149
|
end
|
133
150
|
|
134
|
-
if
|
135
|
-
config.include RSpec::Rails::
|
151
|
+
if RSpec::Rails::FeatureCheck.has_action_mailbox?
|
152
|
+
config.include RSpec::Rails::MailboxExampleGroup, type: :mailbox
|
136
153
|
end
|
137
154
|
end
|
138
|
-
# rubocop:enable Style/MethodLength
|
139
155
|
|
140
156
|
initialize_configuration RSpec.configuration
|
141
157
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "rspec/rails/matchers/action_cable/have_streams"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# @api public
|
6
|
+
# Container module for channel spec functionality. It is only available if
|
7
|
+
# ActionCable has been loaded before it.
|
8
|
+
module ChannelExampleGroup
|
9
|
+
# @private
|
10
|
+
module ClassMethods
|
11
|
+
# These blank modules are only necessary for YARD processing. It doesn't
|
12
|
+
# handle the conditional check below very well and reports undocumented objects.
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
19
|
+
module RSpec
|
20
|
+
module Rails
|
21
|
+
# @api public
|
22
|
+
# Container module for channel spec functionality.
|
23
|
+
module ChannelExampleGroup
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
include RSpec::Rails::RailsExampleGroup
|
26
|
+
include ActionCable::Connection::TestCase::Behavior
|
27
|
+
include ActionCable::Channel::TestCase::Behavior
|
28
|
+
|
29
|
+
# Class-level DSL for channel specs.
|
30
|
+
module ClassMethods
|
31
|
+
# @private
|
32
|
+
def channel_class
|
33
|
+
(_channel_class || described_class).tap do |klass|
|
34
|
+
next if klass <= ::ActionCable::Channel::Base
|
35
|
+
|
36
|
+
raise "Described class is not a channel class.\n" \
|
37
|
+
"Specify the channel class in the `describe` statement " \
|
38
|
+
"or set it manually using `tests MyChannelClass`"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# @private
|
43
|
+
def connection_class
|
44
|
+
(_connection_class || described_class).tap do |klass|
|
45
|
+
next if klass <= ::ActionCable::Connection::Base
|
46
|
+
|
47
|
+
raise "Described class is not a connection class.\n" \
|
48
|
+
"Specify the connection class in the `describe` statement " \
|
49
|
+
"or set it manually using `tests MyConnectionClass`"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Checks that the connection attempt has been rejected.
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# expect { connect }.to have_rejected_connection
|
58
|
+
def have_rejected_connection
|
59
|
+
raise_error(::ActionCable::Connection::Authorization::UnauthorizedError)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Checks that the subscription is subscribed to at least one stream.
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# expect(subscription).to have_streams
|
66
|
+
def have_streams
|
67
|
+
check_subscribed!
|
68
|
+
|
69
|
+
RSpec::Rails::Matchers::ActionCable::HaveStream.new
|
70
|
+
end
|
71
|
+
|
72
|
+
# Checks that the channel has been subscribed to the given stream
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# expect(subscription).to have_stream_from("chat_1")
|
76
|
+
def have_stream_from(stream)
|
77
|
+
check_subscribed!
|
78
|
+
|
79
|
+
RSpec::Rails::Matchers::ActionCable::HaveStream.new(stream)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Checks that the channel has been subscribed to a stream for the given model
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# expect(subscription).to have_stream_for(user)
|
86
|
+
def have_stream_for(object)
|
87
|
+
check_subscribed!
|
88
|
+
RSpec::Rails::Matchers::ActionCable::HaveStream.new(broadcasting_for(object))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -94,9 +94,9 @@ module RSpec
|
|
94
94
|
self.routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
95
95
|
r.draw do
|
96
96
|
resources resource_name,
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
97
|
+
as: resource_as,
|
98
|
+
module: resource_module,
|
99
|
+
path: resource_path
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -159,7 +159,7 @@ module RSpec
|
|
159
159
|
#
|
160
160
|
# expect do
|
161
161
|
# bypass_rescue
|
162
|
-
# get :show, :
|
162
|
+
# get :show, id: profile.id + 1
|
163
163
|
# end.to raise_error(/403 Forbidden/)
|
164
164
|
# end
|
165
165
|
# end
|