rspec-rails 3.9.0 → 5.0.1
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 +212 -78
- data/README.md +27 -21
- data/lib/generators/rspec.rb +0 -6
- 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 +22 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- 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/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 +5 -4
- 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 +29 -19
- 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 +0 -48
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -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 +14 -16
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/rspec-rails.rb +13 -16
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +81 -37
- data/lib/rspec/rails/example.rb +2 -0
- 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 +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/system_example_group.rb +29 -12
- data/lib/rspec/rails/example/view_example_group.rb +38 -27
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/file_fixture_support.rb +9 -11
- data/lib/rspec/rails/fixture_file_upload_support.rb +33 -17
- data/lib/rspec/rails/fixture_support.rb +34 -32
- data/lib/rspec/rails/matchers.rb +10 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- 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_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +169 -21
- data/lib/rspec/rails/matchers/base_matcher.rb +5 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +52 -28
- data/lib/rspec/rails/matchers/have_http_status.rb +11 -7
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -0
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +12 -12
- 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 +15 -4
- metadata +49 -37
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= 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 %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
10
|
<%= output_attributes.empty? ? "" : " ))\n" -%>
|
11
11
|
end
|
@@ -16,11 +16,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
|
16
16
|
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
|
17
17
|
<% for attribute in output_attributes -%>
|
18
18
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
|
-
<% if Rails.version.to_f >= 5.1 -%>
|
20
19
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
21
|
-
<% else -%>
|
22
|
-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
23
|
-
<% end -%>
|
24
20
|
<% end -%>
|
25
21
|
end
|
26
22
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
8
8
|
<%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
|
9
9
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
10
|
-
|
10
|
+
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
11
11
|
<% end -%>
|
12
12
|
<% if !output_attributes.empty? -%>
|
13
13
|
<%= model_index == 1 ? ')' : '),' %>
|
@@ -19,7 +19,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
21
|
<% for attribute in output_attributes -%>
|
22
|
-
assert_select "tr>td", :
|
22
|
+
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
|
23
23
|
<% end -%>
|
24
24
|
end
|
25
25
|
end
|
@@ -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
|
|
@@ -15,11 +15,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
|
15
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
16
16
|
<% for attribute in output_attributes -%>
|
17
17
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
18
|
-
<% if Rails.version.to_f >= 5.1 -%>
|
19
18
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
20
|
-
<% else -%>
|
21
|
-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
22
|
-
<% end -%>
|
23
19
|
<% end -%>
|
24
20
|
end
|
25
21
|
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
<% if mountable_engine? -%>
|
18
|
+
include Engine.routes.url_helpers
|
19
|
+
<% end -%>
|
20
|
+
|
21
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
22
|
+
# adjust the attributes here as well.
|
23
|
+
let(:valid_attributes) {
|
24
|
+
skip("Add a hash of attributes valid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:invalid_attributes) {
|
28
|
+
skip("Add a hash of attributes invalid for your model")
|
29
|
+
}
|
30
|
+
|
31
|
+
<% unless options[:singleton] -%>
|
32
|
+
describe "GET /index" do
|
33
|
+
it "renders a successful response" do
|
34
|
+
<%= class_name %>.create! valid_attributes
|
35
|
+
get <%= index_helper %>_url
|
36
|
+
expect(response).to be_successful
|
37
|
+
end
|
38
|
+
end
|
39
|
+
<% end -%>
|
40
|
+
|
41
|
+
describe "GET /show" do
|
42
|
+
it "renders a successful response" do
|
43
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
44
|
+
get <%= show_helper.tr('@', '') %>
|
45
|
+
expect(response).to be_successful
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "GET /new" do
|
50
|
+
it "renders a successful response" do
|
51
|
+
get <%= new_helper %>
|
52
|
+
expect(response).to be_successful
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "GET /edit" do
|
57
|
+
it "render a successful response" do
|
58
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
59
|
+
get <%= edit_helper.tr('@','') %>
|
60
|
+
expect(response).to be_successful
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "POST /create" do
|
65
|
+
context "with valid parameters" do
|
66
|
+
it "creates a new <%= class_name %>" do
|
67
|
+
expect {
|
68
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
69
|
+
}.to change(<%= class_name %>, :count).by(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "redirects to the created <%= ns_file_name %>" do
|
73
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
74
|
+
expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", class_name+".last") %>)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with invalid parameters" do
|
79
|
+
it "does not create a new <%= class_name %>" do
|
80
|
+
expect {
|
81
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
82
|
+
}.to change(<%= class_name %>, :count).by(0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
86
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
87
|
+
expect(response).to be_successful
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "PATCH /update" do
|
93
|
+
context "with valid parameters" do
|
94
|
+
let(:new_attributes) {
|
95
|
+
skip("Add a hash of attributes valid for your model")
|
96
|
+
}
|
97
|
+
|
98
|
+
it "updates the requested <%= ns_file_name %>" do
|
99
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
100
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
101
|
+
<%= file_name %>.reload
|
102
|
+
skip("Add assertions for updated state")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "redirects to the <%= ns_file_name %>" do
|
106
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
107
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
108
|
+
<%= file_name %>.reload
|
109
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with invalid parameters" do
|
114
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
115
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
116
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
|
117
|
+
expect(response).to be_successful
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "DELETE /destroy" do
|
123
|
+
it "destroys the requested <%= ns_file_name %>" do
|
124
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
|
+
expect {
|
126
|
+
delete <%= show_helper.tr('@', '') %>
|
127
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "redirects to the <%= table_name %> list" do
|
131
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
132
|
+
delete <%= show_helper.tr('@', '') %>
|
133
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
<% 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
|
))
|
@@ -1,25 +1,23 @@
|
|
1
1
|
require 'generators/rspec'
|
2
2
|
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class_option :system_specs, :type => :boolean, :default => true, :desc => "Generate system specs"
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class SystemGenerator < Base
|
7
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
def generate_system_spec
|
10
|
+
return unless options[:system_specs]
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
template template_name, File.join('spec/system', class_path, filename)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def template_name
|
16
|
+
'system_spec.rb'
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
def filename
|
20
|
+
"#{table_name}_spec.rb"
|
23
21
|
end
|
24
22
|
end
|
25
23
|
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/rspec-rails.rb
CHANGED
@@ -7,16 +7,13 @@ module RSpec
|
|
7
7
|
# Railtie to hook into Rails.
|
8
8
|
class Railtie < ::Rails::Railtie
|
9
9
|
# As of Rails 5.1.0 you can register directories to work with `rake notes`
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
SourceAnnotationExtractor::Annotation.register_directories("spec")
|
16
|
-
end
|
10
|
+
require 'rails/source_annotation_extractor'
|
11
|
+
if ::Rails::VERSION::STRING >= '6.0'
|
12
|
+
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
|
13
|
+
else
|
14
|
+
SourceAnnotationExtractor::Annotation.register_directories("spec")
|
17
15
|
end
|
18
|
-
|
19
|
-
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
16
|
+
generators = config.app_generators
|
20
17
|
generators.integration_tool :rspec
|
21
18
|
generators.test_framework :rspec
|
22
19
|
|
@@ -31,14 +28,15 @@ module RSpec
|
|
31
28
|
# This is called after the environment has been loaded but before Rails
|
32
29
|
# sets the default for the `preview_path`
|
33
30
|
initializer "rspec_rails.action_mailer",
|
34
|
-
:
|
35
|
-
|
36
|
-
|
31
|
+
before: "action_mailer.set_configs" do |app|
|
32
|
+
setup_preview_path(app)
|
33
|
+
end
|
37
34
|
|
38
35
|
private
|
39
36
|
|
40
37
|
def setup_preview_path(app)
|
41
38
|
return unless supports_action_mailer_previews?(app.config)
|
39
|
+
|
42
40
|
options = app.config.action_mailer
|
43
41
|
config_default_preview_path(options) if config_preview_path?(options)
|
44
42
|
end
|
@@ -46,9 +44,7 @@ module RSpec
|
|
46
44
|
def config_preview_path?(options)
|
47
45
|
# We cannot use `respond_to?(:show_previews)` here as it will always
|
48
46
|
# return `true`.
|
49
|
-
if
|
50
|
-
::Rails.env.development?
|
51
|
-
elsif options.show_previews.nil?
|
47
|
+
if options.show_previews.nil?
|
52
48
|
options.show_previews = ::Rails.env.development?
|
53
49
|
else
|
54
50
|
options.show_previews
|
@@ -57,6 +53,7 @@ module RSpec
|
|
57
53
|
|
58
54
|
def config_default_preview_path(options)
|
59
55
|
return unless options.preview_path.blank?
|
56
|
+
|
60
57
|
options.preview_path = "#{::Rails.root}/spec/mailers/previews"
|
61
58
|
end
|
62
59
|
|
@@ -72,7 +69,7 @@ module RSpec
|
|
72
69
|
# not respond to the method. However, we cannot use
|
73
70
|
# `config.action_mailer.respond_to?(:preview_path)` here as it will
|
74
71
|
# always return `true`.
|
75
|
-
config.respond_to?(:action_mailer)
|
72
|
+
config.respond_to?(:action_mailer)
|
76
73
|
end
|
77
74
|
end
|
78
75
|
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
|
@@ -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
|