rspec-rails 4.0.0.beta2 → 6.1.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/Capybara.md +5 -54
- data/Changelog.md +352 -86
- data/README.md +76 -65
- 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 +24 -7
- 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 +3 -3
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +3 -3
- data/lib/generators/rspec/helper/helper_generator.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +23 -6
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +27 -21
- data/lib/generators/rspec/integration/integration_generator.rb +13 -6
- data/lib/generators/rspec/job/job_generator.rb +2 -1
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +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 +4 -4
- 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 +7 -7
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +10 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +33 -21
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -49
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +25 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -9
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -6
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +153 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- data/lib/generators/rspec/view/view_generator.rb +4 -4
- data/lib/generators/rspec.rb +16 -5
- data/lib/rspec/rails/adapters.rb +21 -76
- data/lib/rspec/rails/configuration.rb +112 -38
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +5 -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 +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +9 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/system_example_group.rb +80 -14
- data/lib/rspec/rails/example/view_example_group.rb +40 -28
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +15 -22
- data/lib/rspec/rails/file_fixture_support.rb +11 -10
- data/lib/rspec/rails/fixture_file_upload_support.rb +20 -15
- data/lib/rspec/rails/fixture_support.rb +65 -34
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +173 -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 +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +171 -24
- data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +81 -27
- data/lib/rspec/rails/matchers/have_http_status.rb +12 -12
- 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/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +11 -0
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -17
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +0 -18
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +16 -14
- data/lib/rspec-rails.rb +19 -20
- data.tar.gz.sig +0 -0
- metadata +53 -40
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- /data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
@@ -2,25 +2,25 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
5
|
-
|
6
|
-
|
5
|
+
let(:<%= singular_table_name %>) {
|
6
|
+
<%= 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
|
+
<%= " )\n" unless output_attributes.empty? -%>
|
11
|
+
}
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
assign(:<%= singular_table_name %>, <%= singular_table_name %>)
|
11
15
|
end
|
12
16
|
|
13
17
|
it "renders the edit <%= ns_file_name %> form" do
|
14
18
|
render
|
15
19
|
|
16
|
-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(
|
20
|
+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
|
17
21
|
<% for attribute in output_attributes -%>
|
18
22
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
|
-
<% if Rails.version.to_f >= 5.1 -%>
|
20
23
|
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
24
|
<% end -%>
|
25
25
|
end
|
26
26
|
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 ? ')' : '),' %>
|
@@ -18,8 +18,9 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
18
18
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
|
+
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
|
21
22
|
<% for attribute in output_attributes -%>
|
22
|
-
assert_select
|
23
|
+
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
|
23
24
|
<% end -%>
|
24
25
|
end
|
25
26
|
end
|
@@ -3,9 +3,9 @@ require 'rails_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_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,153 @@
|
|
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
|
+
# This should return the minimal set of attributes required to create a valid
|
22
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
23
|
+
# adjust the attributes here as well.
|
24
|
+
let(:valid_attributes) {
|
25
|
+
skip("Add a hash of attributes valid for your model")
|
26
|
+
}
|
27
|
+
|
28
|
+
let(:invalid_attributes) {
|
29
|
+
skip("Add a hash of attributes invalid for your model")
|
30
|
+
}
|
31
|
+
|
32
|
+
<% unless options[:singleton] -%>
|
33
|
+
describe "GET /index" do
|
34
|
+
it "renders a successful response" do
|
35
|
+
<%= class_name %>.create! valid_attributes
|
36
|
+
get <%= index_helper %>_url
|
37
|
+
expect(response).to be_successful
|
38
|
+
end
|
39
|
+
end
|
40
|
+
<% end -%>
|
41
|
+
|
42
|
+
describe "GET /show" do
|
43
|
+
it "renders a successful response" do
|
44
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
45
|
+
get <%= show_helper %>
|
46
|
+
expect(response).to be_successful
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "GET /new" do
|
51
|
+
it "renders a successful response" do
|
52
|
+
get <%= new_helper %>
|
53
|
+
expect(response).to be_successful
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "GET /edit" do
|
58
|
+
it "renders a successful response" do
|
59
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
60
|
+
get <%= edit_helper %>
|
61
|
+
expect(response).to be_successful
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "POST /create" do
|
66
|
+
context "with valid parameters" do
|
67
|
+
it "creates a new <%= class_name %>" do
|
68
|
+
expect {
|
69
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
70
|
+
}.to change(<%= class_name %>, :count).by(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "redirects to the created <%= singular_table_name %>" do
|
74
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
75
|
+
expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with invalid parameters" do
|
80
|
+
it "does not create a new <%= class_name %>" do
|
81
|
+
expect {
|
82
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
83
|
+
}.to change(<%= class_name %>, :count).by(0)
|
84
|
+
end
|
85
|
+
|
86
|
+
<% if Rails.version.to_f < 7.0 %>
|
87
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
88
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
89
|
+
expect(response).to be_successful
|
90
|
+
end
|
91
|
+
<% else %>
|
92
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
93
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
94
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
95
|
+
end
|
96
|
+
<% end %>
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "PATCH /update" do
|
101
|
+
context "with valid parameters" do
|
102
|
+
let(:new_attributes) {
|
103
|
+
skip("Add a hash of attributes valid for your model")
|
104
|
+
}
|
105
|
+
|
106
|
+
it "updates the requested <%= singular_table_name %>" do
|
107
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
108
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
109
|
+
<%= file_name %>.reload
|
110
|
+
skip("Add assertions for updated state")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "redirects to the <%= singular_table_name %>" do
|
114
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
115
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
116
|
+
<%= file_name %>.reload
|
117
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "with invalid parameters" do
|
122
|
+
<% if Rails.version.to_f < 7.0 %>
|
123
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
124
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
126
|
+
expect(response).to be_successful
|
127
|
+
end
|
128
|
+
<% else %>
|
129
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
130
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
131
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
132
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
133
|
+
end
|
134
|
+
<% end %>
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "DELETE /destroy" do
|
139
|
+
it "destroys the requested <%= singular_table_name %>" do
|
140
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
141
|
+
expect {
|
142
|
+
delete <%= show_helper %>
|
143
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "redirects to the <%= table_name %> list" do
|
147
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
148
|
+
delete <%= show_helper %>
|
149
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
<% 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
|
@@ -3,9 +3,9 @@ require 'rails_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
|
6
|
+
assign(:<%= singular_table_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, target_path('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,17 +4,17 @@ 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
|
-
empty_directory
|
12
|
+
empty_directory target_path("views", file_path)
|
13
13
|
|
14
14
|
actions.each do |action|
|
15
15
|
@action = action
|
16
16
|
template 'view_spec.rb',
|
17
|
-
|
17
|
+
target_path("views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/generators/rspec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
+
require 'rspec/core'
|
2
3
|
require 'rspec/rails/feature_check'
|
3
4
|
|
4
5
|
# @private
|
5
|
-
# Weirdly named generators namespace (should be `RSpec`) for
|
6
|
+
# Weirdly named generators namespace (should be `RSpec`) for compatibility with
|
6
7
|
# rails loading.
|
7
8
|
module Rspec
|
8
9
|
# @private
|
@@ -19,10 +20,20 @@ module Rspec
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# @private
|
24
|
+
# Load configuration from RSpec to ensure `--default-path` is set
|
25
|
+
def self.configuration
|
26
|
+
@configuration ||=
|
27
|
+
begin
|
28
|
+
configuration = RSpec.configuration
|
29
|
+
options = RSpec::Core::ConfigurationOptions.new({})
|
30
|
+
options.configure(configuration)
|
31
|
+
configuration
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def target_path(*paths)
|
36
|
+
File.join(self.class.configuration.default_path, *paths)
|
26
37
|
end
|
27
38
|
end
|
28
39
|
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
|
@@ -247,5 +181,16 @@ module RSpec
|
|
247
181
|
#
|
248
182
|
# @private
|
249
183
|
TestUnitAssertionAdapter = MinitestAssertionAdapter
|
184
|
+
|
185
|
+
# @private
|
186
|
+
module TaggedLoggingAdapter
|
187
|
+
private
|
188
|
+
# Vendored from activesupport/lib/active_support/testing/tagged_logging.rb
|
189
|
+
# This implements the tagged_logger method where it is expected, but
|
190
|
+
# doesn't call `name` or set it up like Rails does.
|
191
|
+
def tagged_logger
|
192
|
+
@tagged_logger ||= (defined?(Rails.logger) && Rails.logger)
|
193
|
+
end
|
194
|
+
end
|
250
195
|
end
|
251
196
|
end
|