Skip to content

Commit ab36146

Browse files
authored
Merge pull request #2804 from rspec/comment-out-infer-spect-type-by-default
Comment out `infer_spec_type_from_file_location!` in generated helper.
2 parents 124cbcb + 3487e0f commit ab36146

File tree

8 files changed

+38
-34
lines changed

8 files changed

+38
-34
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Enhancements:
55

66
* Improve implicit description for ActionCable matchers `have_broadcasted_to` /
77
`have_broadcast`. (Simon Fish, #2795)
8+
* Comment out `infer_spec_type_from_file_location!` in newly generated
9+
`rails_helper.rb` files. (Jon Rowe, #2804)
810

911
Bug Fixes:
1012

features/matchers/redirect_to_matcher.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: `redirect_to` matcher
1212
"""ruby
1313
require "rails_helper"
1414
15-
RSpec.describe WidgetsController do
15+
RSpec.describe WidgetsController , type: :controller do
1616
1717
describe "#create" do
1818
subject { post :create, :params => { :widget => { :name => "Foo" } } }

features/matchers/render_template_matcher.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Feature: `render_template` matcher
1414
"""ruby
1515
require "rails_helper"
1616
17-
RSpec.describe GadgetsController do
17+
RSpec.describe GadgetsController , type: :controller do
1818
describe "GET #index" do
1919
subject { get :index }
2020
@@ -38,7 +38,7 @@ Feature: `render_template` matcher
3838
"""ruby
3939
require "rails_helper"
4040
41-
RSpec.describe GadgetsController do
41+
RSpec.describe GadgetsController , type: :controller do
4242
describe "GET #index" do
4343
subject { get :index }
4444
@@ -60,7 +60,7 @@ Feature: `render_template` matcher
6060
"""ruby
6161
require "rails_helper"
6262
63-
RSpec.describe "gadgets/index" do
63+
RSpec.describe "gadgets/index" , type: :view do
6464
it "renders the index template" do
6565
assign(:gadgets, [Gadget.create!])
6666
render

features/matchers/send_email_matcher.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: `send_email` matcher
1616
"""ruby
1717
require "rails_helper"
1818
19-
RSpec.describe NotificationsMailer do
19+
RSpec.describe NotificationsMailer , type: :mailer do
2020
it "checks email sending by multiple params" do
2121
expect {
2222
NotificationsMailer.signup.deliver_now
@@ -36,7 +36,7 @@ Feature: `send_email` matcher
3636
"""ruby
3737
require "rails_helper"
3838
39-
RSpec.describe NotificationsMailer do
39+
RSpec.describe NotificationsMailer , type: :mailer do
4040
it "checks email sending by one param only" do
4141
expect {
4242
NotificationsMailer.signup.deliver_now
@@ -54,7 +54,7 @@ Feature: `send_email` matcher
5454
"""ruby
5555
require "rails_helper"
5656
57-
RSpec.describe NotificationsMailer do
57+
RSpec.describe NotificationsMailer , type: :mailer do
5858
it "checks email not sent" do
5959
expect {
6060
NotificationsMailer.signup.deliver_now

features/view_specs/inferred_controller_path.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: View specs infer controller's path and action
55
"""ruby
66
require "rails_helper"
77
8-
RSpec.describe "widgets/new" do
8+
RSpec.describe "widgets/new" , type: :view do
99
it "infers the controller path" do
1010
expect(controller.request.path_parameters[:controller]).to eq("widgets")
1111
expect(controller.controller_path).to eq("widgets")
@@ -20,7 +20,7 @@ Feature: View specs infer controller's path and action
2020
"""ruby
2121
require "rails_helper"
2222
23-
RSpec.describe "widgets/new" do
23+
RSpec.describe "widgets/new" , type: :view do
2424
it "infers the controller action" do
2525
expect(controller.request.path_parameters[:action]).to eq("new")
2626
end
@@ -34,7 +34,7 @@ Feature: View specs infer controller's path and action
3434
"""ruby
3535
require "rails_helper"
3636
37-
RSpec.describe "widgets/_form" do
37+
RSpec.describe "widgets/_form" , type: :view do
3838
it "includes a link to new" do
3939
expect(controller.request.path_parameters[:action]).to be_nil
4040
end

features/view_specs/stub_template.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Using `stub_template`
88
"""ruby
99
require "rails_helper"
1010
11-
RSpec.describe "gadgets/list" do
11+
RSpec.describe "gadgets/list" , type: :view do
1212
it "renders the gadget partial for each gadget" do
1313
assign(:gadgets, [
1414
double(:name => "First"),
@@ -34,7 +34,7 @@ Feature: Using `stub_template`
3434
"""ruby
3535
require "rails_helper"
3636
37-
RSpec.describe "gadgets/edit" do
37+
RSpec.describe "gadgets/edit" , type: :view do
3838
before(:each) do
3939
@gadget = assign(:gadget, Gadget.create!)
4040
end

features/view_specs/view_spec.feature

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Feature: View specs
2727
"""ruby
2828
require "rails_helper"
2929
30-
RSpec.describe "widgets/index" do
30+
RSpec.describe "widgets/index" , type: :view do
3131
it "displays all the widgets" do
3232
assign(:widgets, [
3333
Widget.create!(:name => "slicer"),
@@ -49,7 +49,7 @@ Feature: View specs
4949
"""ruby
5050
require "rails_helper"
5151
52-
RSpec.describe "widgets/index" do
52+
RSpec.describe "widgets/index" , type: :view do
5353
5454
context "with 2 widgets" do
5555
before(:each) do
@@ -76,7 +76,7 @@ Feature: View specs
7676
"""ruby
7777
require "rails_helper"
7878
79-
RSpec.describe "rendering the widget template" do
79+
RSpec.describe "rendering the widget template" , type: :view do
8080
it "displays the widget" do
8181
assign(:widget, Widget.create!(:name => "slicer"))
8282
@@ -98,7 +98,7 @@ Feature: View specs
9898
"""ruby
9999
require "rails_helper"
100100
101-
RSpec.describe "rendering the widget template" do
101+
RSpec.describe "rendering the widget template" , type: :view do
102102
context "with the inventory layout" do
103103
it "displays the widget" do
104104
assign(:widget, Widget.create!(:name => "slicer"))
@@ -126,15 +126,15 @@ Feature: View specs
126126
"""ruby
127127
require "rails_helper"
128128
129-
RSpec.describe "widgets/widget.html.erb" do
129+
RSpec.describe "widgets/widget.html.erb" , type: :view do
130130
it "renders the HTML template" do
131131
render
132132
133133
expect(rendered).to match /HTML/
134134
end
135135
end
136136
137-
RSpec.describe "widgets/widget.xml.erb" do
137+
RSpec.describe "widgets/widget.xml.erb" , type: :view do
138138
it "renders the XML template" do
139139
render
140140
@@ -158,7 +158,7 @@ Feature: View specs
158158
"""ruby
159159
require "rails_helper"
160160
161-
RSpec.describe "widgets/index" do
161+
RSpec.describe "widgets/index" , type: :view do
162162
it "displays the widget" do
163163
widget = Widget.create!(:name => "slicer")
164164
@@ -180,7 +180,7 @@ Feature: View specs
180180
"""ruby
181181
require "rails_helper"
182182
183-
RSpec.describe "rendering locals in a partial" do
183+
RSpec.describe "rendering locals in a partial" , type: :view do
184184
it "displays the widget" do
185185
widget = Widget.create!(:name => "slicer")
186186
@@ -202,7 +202,7 @@ Feature: View specs
202202
"""ruby
203203
require "rails_helper"
204204
205-
RSpec.describe "rendering locals in a partial" do
205+
RSpec.describe "rendering locals in a partial" , type: :view do
206206
it "displays the widget" do
207207
widget = Widget.create!(:name => "slicer")
208208
@@ -224,7 +224,7 @@ Feature: View specs
224224
"""ruby
225225
require "rails_helper"
226226
227-
RSpec.describe "rendering text directly" do
227+
RSpec.describe "rendering text directly" , type: :view do
228228
it "displays the given text" do
229229
230230
render :plain => "This is directly rendered"
@@ -255,7 +255,7 @@ Feature: View specs
255255
"""ruby
256256
require 'rails_helper'
257257
258-
RSpec.describe 'secrets/index' do
258+
RSpec.describe 'secrets/index' , type: :view do
259259
before do
260260
allow(view).to receive(:admin?).and_return(true)
261261
end
@@ -274,7 +274,7 @@ Feature: View specs
274274
"""ruby
275275
require "rails_helper"
276276
277-
RSpec.describe "controller.request.path_parameters" do
277+
RSpec.describe "controller.request.path_parameters" , type: :view do
278278
it "matches the Rails environment by using symbols for keys" do
279279
[:controller, :action].each { |k| expect(controller.request.path_parameters.keys).to include(k) }
280280
end
@@ -288,7 +288,7 @@ Feature: View specs
288288
"""ruby
289289
require "rails_helper"
290290
291-
RSpec.describe "widgets/index" do
291+
RSpec.describe "widgets/index" , type: :view do
292292
it "has a request.fullpath that is defined" do
293293
expect(controller.request.fullpath).to eq widgets_path
294294
end
@@ -302,7 +302,7 @@ Feature: View specs
302302
"""ruby
303303
require "rails_helper"
304304
305-
RSpec.describe "widgets/show" do
305+
RSpec.describe "widgets/show" , type: :view do
306306
it "displays the widget with id: 1" do
307307
widget = Widget.create!(:name => "slicer")
308308
controller.extra_params = { :id => widget.id }

lib/generators/rspec/install/templates/spec/rails_helper.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,22 @@
6767
# config.use_transactional_fixtures = true
6868
6969
<% end -%>
70-
# RSpec Rails can automatically mix in different behaviours to your tests
71-
# based on their file location, for example enabling you to call `get` and
72-
# `post` in specs under `spec/controllers`.
70+
# RSpec Rails uses metadata to mix in different behaviours to your tests,
71+
# for example enabling you to call `get` and `post` in request specs. e.g.:
7372
#
74-
# You can disable this behaviour by removing the line below, and instead
75-
# explicitly tag your specs with their type, e.g.:
76-
#
77-
# RSpec.describe UsersController, type: :controller do
73+
# RSpec.describe UsersController, type: :request do
7874
# # ...
7975
# end
8076
#
8177
# The different available types are documented in the features, such as in
8278
# https://rspec.info/features/7-0/rspec-rails
83-
config.infer_spec_type_from_file_location!
79+
#
80+
# You can also this infer these behaviours automatically by location, e.g.
81+
# /spec/models would pull in the same behaviour as `type: :model` but this
82+
# behaviour is considered legacy and will be removed in a future version.
83+
#
84+
# To enable this behaviour uncomment the line below.
85+
# config.infer_spec_type_from_file_location!
8486
8587
# Filter lines from Rails gems in backtraces.
8688
config.filter_rails_from_backtrace!

0 commit comments

Comments
 (0)