rspec-rails 4.0.0 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +139 -50
  4. data/README.md +42 -31
  5. data/lib/generators/rspec/controller/controller_generator.rb +2 -2
  6. data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
  7. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +1 -1
  8. data/lib/generators/rspec/job/job_generator.rb +2 -1
  9. data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
  10. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  11. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  12. data/lib/generators/rspec/scaffold/scaffold_generator.rb +4 -0
  13. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -13
  14. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +20 -20
  15. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -58
  16. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -4
  17. data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -4
  18. data/lib/generators/rspec/scaffold/templates/request_spec.rb +23 -18
  19. data/lib/generators/rspec/system/system_generator.rb +14 -16
  20. data/lib/rspec/rails/configuration.rb +41 -6
  21. data/lib/rspec/rails/example/controller_example_group.rb +1 -0
  22. data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
  23. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  24. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  25. data/lib/rspec/rails/example/system_example_group.rb +5 -4
  26. data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
  27. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  28. data/lib/rspec/rails/fixture_file_upload_support.rb +32 -16
  29. data/lib/rspec/rails/fixture_support.rb +9 -12
  30. data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
  31. data/lib/rspec/rails/matchers/active_job.rb +29 -3
  32. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +33 -5
  33. data/lib/rspec/rails/matchers/have_http_status.rb +4 -4
  34. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  35. data/lib/rspec/rails/version.rb +1 -1
  36. data/lib/rspec-rails.rb +5 -7
  37. data.tar.gz.sig +0 -0
  38. metadata +37 -25
  39. metadata.gz.sig +0 -0
@@ -46,7 +46,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
46
46
  describe "GET /show" do
47
47
  it "renders a successful response" do
48
48
  <%= file_name %> = <%= class_name %>.create! valid_attributes
49
- get <%= show_helper.tr('@', '') %>, as: :json
49
+ get <%= show_helper %>, as: :json
50
50
  expect(response).to be_successful
51
51
  end
52
52
  end
@@ -56,13 +56,13 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
56
56
  it "creates a new <%= class_name %>" do
57
57
  expect {
58
58
  post <%= index_helper %>_url,
59
- params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
59
+ params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
60
60
  }.to change(<%= class_name %>, :count).by(1)
61
61
  end
62
62
 
63
- it "renders a JSON response with the new <%= ns_file_name %>" do
63
+ it "renders a JSON response with the new <%= singular_table_name %>" do
64
64
  post <%= index_helper %>_url,
65
- params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
65
+ params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
66
66
  expect(response).to have_http_status(:created)
67
67
  expect(response.content_type).to match(a_string_including("application/json"))
68
68
  end
@@ -72,15 +72,15 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
72
72
  it "does not create a new <%= class_name %>" do
73
73
  expect {
74
74
  post <%= index_helper %>_url,
75
- params: { <%= ns_file_name %>: invalid_attributes }, as: :json
75
+ params: { <%= singular_table_name %>: invalid_attributes }, as: :json
76
76
  }.to change(<%= class_name %>, :count).by(0)
77
77
  end
78
78
 
79
- it "renders a JSON response with errors for the new <%= ns_file_name %>" do
79
+ it "renders a JSON response with errors for the new <%= singular_table_name %>" do
80
80
  post <%= index_helper %>_url,
81
- params: { <%= ns_file_name %>: invalid_attributes }, headers: valid_headers, as: :json
81
+ params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
82
82
  expect(response).to have_http_status(:unprocessable_entity)
83
- expect(response.content_type).to eq("application/json")
83
+ expect(response.content_type).to match(a_string_including("application/json"))
84
84
  end
85
85
  end
86
86
  end
@@ -91,39 +91,39 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
91
91
  skip("Add a hash of attributes valid for your model")
92
92
  }
93
93
 
94
- it "updates the requested <%= ns_file_name %>" do
94
+ it "updates the requested <%= singular_table_name %>" do
95
95
  <%= file_name %> = <%= class_name %>.create! valid_attributes
96
- patch <%= show_helper.tr('@', '') %>,
97
- params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
96
+ patch <%= show_helper %>,
97
+ params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
98
98
  <%= file_name %>.reload
99
99
  skip("Add assertions for updated state")
100
100
  end
101
101
 
102
- it "renders a JSON response with the <%= ns_file_name %>" do
102
+ it "renders a JSON response with the <%= singular_table_name %>" do
103
103
  <%= file_name %> = <%= class_name %>.create! valid_attributes
104
- patch <%= show_helper.tr('@', '') %>,
105
- params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
104
+ patch <%= show_helper %>,
105
+ params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
106
106
  expect(response).to have_http_status(:ok)
107
- expect(response.content_type).to eq("application/json")
107
+ expect(response.content_type).to match(a_string_including("application/json"))
108
108
  end
109
109
  end
110
110
 
111
111
  context "with invalid parameters" do
112
- it "renders a JSON response with errors for the <%= ns_file_name %>" do
112
+ it "renders a JSON response with errors for the <%= singular_table_name %>" do
113
113
  <%= file_name %> = <%= class_name %>.create! valid_attributes
114
- patch <%= show_helper.tr('@', '') %>,
114
+ patch <%= show_helper %>,
115
115
  params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
116
116
  expect(response).to have_http_status(:unprocessable_entity)
117
- expect(response.content_type).to eq("application/json")
117
+ expect(response.content_type).to match(a_string_including("application/json"))
118
118
  end
119
119
  end
120
120
  end
121
121
 
122
122
  describe "DELETE /destroy" do
123
- it "destroys the requested <%= ns_file_name %>" do
123
+ it "destroys the requested <%= singular_table_name %>" do
124
124
  <%= file_name %> = <%= class_name %>.create! valid_attributes
125
125
  expect {
126
- delete <%= show_helper.tr('@', '') %>, headers: valid_headers, as: :json
126
+ delete <%= show_helper %>, headers: valid_headers, as: :json
127
127
  }.to change(<%= class_name %>, :count).by(-1)
128
128
  end
129
129
  end
@@ -46,11 +46,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
46
46
  describe "GET #index" do
47
47
  it "returns a success response" do
48
48
  <%= class_name %>.create! valid_attributes
49
- <% if Rails::VERSION::STRING < '5.0' -%>
50
- get :index, {}, valid_session
51
- <% else -%>
52
49
  get :index, params: {}, session: valid_session
53
- <% end -%>
54
50
  expect(response).to be_successful
55
51
  end
56
52
  end
@@ -59,22 +55,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
59
55
  describe "GET #show" do
60
56
  it "returns a success response" do
61
57
  <%= file_name %> = <%= class_name %>.create! valid_attributes
62
- <% if Rails::VERSION::STRING < '5.0' -%>
63
- get :show, {id: <%= file_name %>.to_param}, valid_session
64
- <% else -%>
65
58
  get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
66
- <% end -%>
67
59
  expect(response).to be_successful
68
60
  end
69
61
  end
70
62
 
71
63
  describe "GET #new" do
72
64
  it "returns a success response" do
73
- <% if Rails::VERSION::STRING < '5.0' -%>
74
- get :new, {}, valid_session
75
- <% else -%>
76
65
  get :new, params: {}, session: valid_session
77
- <% end -%>
78
66
  expect(response).to be_successful
79
67
  end
80
68
  end
@@ -82,11 +70,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
82
70
  describe "GET #edit" do
83
71
  it "returns a success response" do
84
72
  <%= file_name %> = <%= class_name %>.create! valid_attributes
85
- <% if Rails::VERSION::STRING < '5.0' -%>
86
- get :edit, {id: <%= file_name %>.to_param}, valid_session
87
- <% else -%>
88
73
  get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
89
- <% end -%>
90
74
  expect(response).to be_successful
91
75
  end
92
76
  end
@@ -95,31 +79,19 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
95
79
  context "with valid params" do
96
80
  it "creates a new <%= class_name %>" do
97
81
  expect {
98
- <% if Rails::VERSION::STRING < '5.0' -%>
99
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
100
- <% else -%>
101
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
102
- <% end -%>
82
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
103
83
  }.to change(<%= class_name %>, :count).by(1)
104
84
  end
105
85
 
106
- it "redirects to the created <%= ns_file_name %>" do
107
- <% if Rails::VERSION::STRING < '5.0' -%>
108
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
109
- <% else -%>
110
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
111
- <% end -%>
86
+ it "redirects to the created <%= singular_table_name %>" do
87
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
112
88
  expect(response).to redirect_to(<%= class_name %>.last)
113
89
  end
114
90
  end
115
91
 
116
92
  context "with invalid params" do
117
93
  it "returns a success response (i.e. to display the 'new' template)" do
118
- <% if Rails::VERSION::STRING < '5.0' -%>
119
- post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
120
- <% else -%>
121
- post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
122
- <% end -%>
94
+ post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
123
95
  expect(response).to be_successful
124
96
  end
125
97
  end
@@ -131,24 +103,16 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
131
103
  skip("Add a hash of attributes valid for your model")
132
104
  }
133
105
 
134
- it "updates the requested <%= ns_file_name %>" do
106
+ it "updates the requested <%= singular_table_name %>" do
135
107
  <%= file_name %> = <%= class_name %>.create! valid_attributes
136
- <% if Rails::VERSION::STRING < '5.0' -%>
137
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
138
- <% else -%>
139
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
140
- <% end -%>
108
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
141
109
  <%= file_name %>.reload
142
110
  skip("Add assertions for updated state")
143
111
  end
144
112
 
145
- it "redirects to the <%= ns_file_name %>" do
113
+ it "redirects to the <%= singular_table_name %>" do
146
114
  <%= file_name %> = <%= class_name %>.create! valid_attributes
147
- <% if Rails::VERSION::STRING < '5.0' -%>
148
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
149
- <% else -%>
150
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
151
- <% end -%>
115
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
152
116
  expect(response).to redirect_to(<%= file_name %>)
153
117
  end
154
118
  end
@@ -156,35 +120,23 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
156
120
  context "with invalid params" do
157
121
  it "returns a success response (i.e. to display the 'edit' template)" do
158
122
  <%= file_name %> = <%= class_name %>.create! valid_attributes
159
- <% if Rails::VERSION::STRING < '5.0' -%>
160
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
161
- <% else -%>
162
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
163
- <% end -%>
123
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
164
124
  expect(response).to be_successful
165
125
  end
166
126
  end
167
127
  end
168
128
 
169
129
  describe "DELETE #destroy" do
170
- it "destroys the requested <%= ns_file_name %>" do
130
+ it "destroys the requested <%= singular_table_name %>" do
171
131
  <%= file_name %> = <%= class_name %>.create! valid_attributes
172
132
  expect {
173
- <% if Rails::VERSION::STRING < '5.0' -%>
174
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
175
- <% else -%>
176
133
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
177
- <% end -%>
178
134
  }.to change(<%= class_name %>, :count).by(-1)
179
135
  end
180
136
 
181
137
  it "redirects to the <%= table_name %> list" do
182
138
  <%= file_name %> = <%= class_name %>.create! valid_attributes
183
- <% if Rails::VERSION::STRING < '5.0' -%>
184
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
185
- <% else -%>
186
139
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
187
- <% end -%>
188
140
  expect(response).to redirect_to(<%= index_helper %>_url)
189
141
  end
190
142
  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
@@ -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
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  # This spec was generated by rspec-rails when you ran the scaffold generator.
4
4
  # It demonstrates how one might use RSpec to test the controller code that
@@ -14,6 +14,11 @@
14
14
 
15
15
  <% module_namespacing do -%>
16
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
17
22
  # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
18
23
  # adjust the attributes here as well.
19
24
  let(:valid_attributes) {
@@ -37,7 +42,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
37
42
  describe "GET /show" do
38
43
  it "renders a successful response" do
39
44
  <%= file_name %> = <%= class_name %>.create! valid_attributes
40
- get <%= show_helper.tr('@', '') %>
45
+ get <%= show_helper %>
41
46
  expect(response).to be_successful
42
47
  end
43
48
  end
@@ -50,9 +55,9 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
50
55
  end
51
56
 
52
57
  describe "GET /edit" do
53
- it "render a successful response" do
58
+ it "renders a successful response" do
54
59
  <%= file_name %> = <%= class_name %>.create! valid_attributes
55
- get <%= edit_helper.tr('@','') %>
60
+ get <%= edit_helper %>
56
61
  expect(response).to be_successful
57
62
  end
58
63
  end
@@ -61,25 +66,25 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
61
66
  context "with valid parameters" do
62
67
  it "creates a new <%= class_name %>" do
63
68
  expect {
64
- post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
69
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
65
70
  }.to change(<%= class_name %>, :count).by(1)
66
71
  end
67
72
 
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") %>)
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") %>)
71
76
  end
72
77
  end
73
78
 
74
79
  context "with invalid parameters" do
75
80
  it "does not create a new <%= class_name %>" do
76
81
  expect {
77
- post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
82
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
78
83
  }.to change(<%= class_name %>, :count).by(0)
79
84
  end
80
85
 
81
86
  it "renders a successful response (i.e. to display the 'new' template)" do
82
- post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
87
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
83
88
  expect(response).to be_successful
84
89
  end
85
90
  end
@@ -91,16 +96,16 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
91
96
  skip("Add a hash of attributes valid for your model")
92
97
  }
93
98
 
94
- it "updates the requested <%= ns_file_name %>" do
99
+ it "updates the requested <%= singular_table_name %>" do
95
100
  <%= file_name %> = <%= class_name %>.create! valid_attributes
96
- patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
101
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
97
102
  <%= file_name %>.reload
98
103
  skip("Add assertions for updated state")
99
104
  end
100
105
 
101
- it "redirects to the <%= ns_file_name %>" do
106
+ it "redirects to the <%= singular_table_name %>" do
102
107
  <%= file_name %> = <%= class_name %>.create! valid_attributes
103
- patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
108
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
104
109
  <%= file_name %>.reload
105
110
  expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
106
111
  end
@@ -109,23 +114,23 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
109
114
  context "with invalid parameters" do
110
115
  it "renders a successful response (i.e. to display the 'edit' template)" do
111
116
  <%= file_name %> = <%= class_name %>.create! valid_attributes
112
- patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
117
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
113
118
  expect(response).to be_successful
114
119
  end
115
120
  end
116
121
  end
117
122
 
118
123
  describe "DELETE /destroy" do
119
- it "destroys the requested <%= ns_file_name %>" do
124
+ it "destroys the requested <%= singular_table_name %>" do
120
125
  <%= file_name %> = <%= class_name %>.create! valid_attributes
121
126
  expect {
122
- delete <%= show_helper.tr('@', '') %>
127
+ delete <%= show_helper %>
123
128
  }.to change(<%= class_name %>, :count).by(-1)
124
129
  end
125
130
 
126
131
  it "redirects to the <%= table_name %> list" do
127
132
  <%= file_name %> = <%= class_name %>.create! valid_attributes
128
- delete <%= show_helper.tr('@', '') %>
133
+ delete <%= show_helper %>
129
134
  expect(response).to redirect_to(<%= index_helper %>_url)
130
135
  end
131
136
  end
@@ -1,25 +1,23 @@
1
1
  require 'generators/rspec'
2
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"
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
- def generate_system_spec
11
- return unless options[:system_specs]
9
+ def generate_system_spec
10
+ return unless options[:system_specs]
12
11
 
13
- template template_name, File.join('spec/system', class_path, filename)
14
- end
12
+ template template_name, File.join('spec/system', class_path, filename)
13
+ end
15
14
 
16
- def template_name
17
- 'system_spec.rb'
18
- end
15
+ def template_name
16
+ 'system_spec.rb'
17
+ end
19
18
 
20
- def filename
21
- "#{table_name}_spec.rb"
22
- end
19
+ def filename
20
+ "#{table_name}_spec.rb"
23
21
  end
24
22
  end
25
23
  end
@@ -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,
@@ -27,6 +28,7 @@ module RSpec
27
28
  DIRECTORY_MAPPINGS = {
28
29
  channel: %w[spec channels],
29
30
  controller: %w[spec controllers],
31
+ generator: %w[spec generator],
30
32
  helper: %w[spec helpers],
31
33
  job: %w[spec jobs],
32
34
  mailer: %w[spec mailers],
@@ -55,7 +57,7 @@ module RSpec
55
57
  end
56
58
 
57
59
  # @private
58
- def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
60
+ def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
59
61
  config.backtrace_exclusion_patterns << /vendor\//
60
62
  config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
61
63
 
@@ -79,10 +81,8 @@ module RSpec
79
81
  # `RSpec::Rails::FixtureSupport` directly instead
80
82
  config.include RSpec::Rails::FixtureSupport
81
83
 
82
- if ::Rails::VERSION::STRING > '5'
83
- config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
84
- config.include RSpec::Rails::FileFixtureSupport
85
- end
84
+ config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
85
+ config.include RSpec::Rails::FileFixtureSupport
86
86
 
87
87
  # Add support for fixture_path on fixture_file_upload
88
88
  config.include RSpec::Rails::FixtureFileUploadSupport
@@ -105,7 +105,41 @@ module RSpec
105
105
  end
106
106
 
107
107
  def render_views?
108
- rendering_views
108
+ rendering_views?
109
+ end
110
+
111
+ undef :rendering_views? if respond_to?(:rendering_views?)
112
+ def rendering_views?
113
+ !!rendering_views
114
+ end
115
+
116
+ # Define boolean predicates rather than relying on rspec-core due
117
+ # to the bug fix in rspec/rspec-core#2736, note some of these
118
+ # predicates are a bit nonsensical, but they exist for backwards
119
+ # compatibility, we can tidy these up in `rspec-rails` 5.
120
+ undef :fixture_path? if respond_to?(:fixture_path?)
121
+ def fixture_path?
122
+ !!fixture_path
123
+ end
124
+
125
+ undef :global_fixtures? if respond_to?(:global_fixtures?)
126
+ def global_fixtures?
127
+ !!global_fixtures
128
+ end
129
+
130
+ undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
131
+ def infer_base_class_for_anonymous_controllers?
132
+ !!infer_base_class_for_anonymous_controllers
133
+ end
134
+
135
+ undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
136
+ def use_instantiated_fixtures?
137
+ !!use_instantiated_fixtures
138
+ end
139
+
140
+ undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
141
+ def use_transactional_fixtures?
142
+ !!use_transactional_fixtures
109
143
  end
110
144
 
111
145
  def infer_spec_type_from_file_location!
@@ -156,3 +190,4 @@ module RSpec
156
190
  initialize_configuration RSpec.configuration
157
191
  end
158
192
  end
193
+ # rubocop: enable Metrics/ModuleLength
@@ -176,6 +176,7 @@ module RSpec
176
176
  super
177
177
  end
178
178
  end
179
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
179
180
 
180
181
  included do
181
182
  subject { controller }
@@ -13,7 +13,7 @@ module RSpec
13
13
  def self.create_inbound_email(arg)
14
14
  case arg
15
15
  when Hash
16
- create_inbound_email_from_mail(arg)
16
+ create_inbound_email_from_mail(**arg)
17
17
  else
18
18
  create_inbound_email_from_source(arg.to_s)
19
19
  end
@@ -21,8 +21,8 @@ if defined?(ActionMailer)
21
21
 
22
22
  included do
23
23
  include ::Rails.application.routes.url_helpers
24
- options = ::Rails.configuration.action_mailer.default_url_options
25
- options&.each { |key, value| default_url_options[key] = value }
24
+ options = ::Rails.configuration.action_mailer.default_url_options || {}
25
+ options.each { |key, value| default_url_options[key] = value }
26
26
  end
27
27
 
28
28
  # Class-level DSL for mailer specs.
@@ -10,10 +10,7 @@ module RSpec
10
10
  include RSpec::Rails::Matchers::RedirectTo
11
11
  include RSpec::Rails::Matchers::RenderTemplate
12
12
  include ActionController::TemplateAssertions
13
-
14
- if ActionPack::VERSION::MAJOR >= 5
15
- include ActionDispatch::IntegrationTest::Behavior
16
- end
13
+ include ActionDispatch::IntegrationTest::Behavior
17
14
 
18
15
  # Delegates to `Rails.application`.
19
16
  def app
@@ -41,7 +41,7 @@ module RSpec
41
41
  @method_name ||= [
42
42
  self.class.name.underscore,
43
43
  RSpec.current_example.description.underscore
44
- ].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}"
44
+ ].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
45
45
  end
46
46
 
47
47
  # Delegates to `Rails.application`.
@@ -96,8 +96,8 @@ module RSpec
96
96
  end
97
97
  end
98
98
 
99
- def driven_by(*args, &blk)
100
- @driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
99
+ def driven_by(driver, **driver_options, &blk)
100
+ @driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
101
101
  end
102
102
 
103
103
  before do
@@ -114,7 +114,8 @@ module RSpec
114
114
  original_after_teardown.bind(self).call
115
115
  ensure
116
116
  myio = $stdout
117
- RSpec.current_example.metadata[:extra_failure_lines] = myio.string
117
+ myio.rewind
118
+ RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
118
119
  $stdout = orig_stdout
119
120
  end
120
121
  end
@@ -1,7 +1,10 @@
1
1
  RSpec.configure do |rspec|
2
2
  # Delay this in order to give users a chance to configure `expect_with`...
3
3
  rspec.before(:suite) do
4
- if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
4
+ if defined?(RSpec::Matchers) &&
5
+ RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax
6
+ RSpec::Matchers.configuration.syntax.include?(:should) &&
7
+ defined?(ActiveRecord::Associations)
5
8
  RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
6
9
  end
7
10
  end
@@ -1,16 +1,14 @@
1
- if ::Rails::VERSION::STRING > '5'
2
- require 'active_support/testing/file_fixtures'
1
+ require 'active_support/testing/file_fixtures'
3
2
 
4
- module RSpec
5
- module Rails
6
- # @private
7
- module FileFixtureSupport
8
- extend ActiveSupport::Concern
9
- include ActiveSupport::Testing::FileFixtures
3
+ module RSpec
4
+ module Rails
5
+ # @private
6
+ module FileFixtureSupport
7
+ extend ActiveSupport::Concern
8
+ include ActiveSupport::Testing::FileFixtures
10
9
 
11
- included do
12
- self.file_fixture_path = RSpec.configuration.file_fixture_path
13
- end
10
+ included do
11
+ self.file_fixture_path = RSpec.configuration.file_fixture_path
14
12
  end
15
13
  end
16
14
  end