Skip to content

Commit 211f526

Browse files
committed
Merge pull request #1190 from rspec/update_request_docs
manually tag request specs to aid users
2 parents b9027c1 + eabf9bc commit 211f526

18 files changed

+67
-57
lines changed

features/controller_specs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Controller specs live in `spec/controllers` or any example group with
2-
`:type => :controller`.
1+
Controller specs are marked by `:type => :controller` or if you have set
2+
`config.infer_spec_type_from_file_location!` by placing them in `spec/controllers`.
33

44
A controller spec is an RSpec wrapper for a Rails functional test
55
([ActionController::TestCase::Behavior](https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb)).

features/controller_specs/anonymous_controller.feature

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Feature: anonymous controller
2020
c.infer_base_class_for_anonymous_controllers = false
2121
end
2222

23-
RSpec.describe BaseController do
23+
RSpec.describe BaseController, :type => :controller do
2424
controller do
2525
def index; end
2626

@@ -48,7 +48,7 @@ Feature: anonymous controller
4848
end
4949
end
5050
51-
RSpec.describe ApplicationController do
51+
RSpec.describe ApplicationController, :type => :controller do
5252
controller do
5353
def index
5454
raise ApplicationController::AccessDenied
@@ -86,7 +86,7 @@ Feature: anonymous controller
8686
end
8787
end
8888
89-
RSpec.describe ApplicationControllerSubclass do
89+
RSpec.describe ApplicationControllerSubclass, :type => :controller do
9090
controller(ApplicationControllerSubclass) do
9191
def index
9292
raise ApplicationController::AccessDenied
@@ -113,7 +113,7 @@ Feature: anonymous controller
113113
114114
class ApplicationControllerSubclass < ApplicationController; end
115115
116-
RSpec.describe ApplicationControllerSubclass do
116+
RSpec.describe ApplicationControllerSubclass, :type => :controller do
117117
controller do
118118
def index
119119
render :text => "Hello World"
@@ -136,7 +136,7 @@ Feature: anonymous controller
136136
class ApplicationController < ActionController::Base; end
137137
class FoosController < ApplicationController; end
138138
139-
RSpec.describe "FoosController controller_name" do
139+
RSpec.describe "FoosController controller_name", :type => :controller do
140140
controller FoosController do
141141
def index
142142
@name = self.class.name
@@ -175,7 +175,7 @@ Feature: anonymous controller
175175
end
176176
end
177177
178-
RSpec.describe ApplicationController do
178+
RSpec.describe ApplicationController, :type => :controller do
179179
controller do
180180
def index
181181
render :nothing => true
@@ -197,7 +197,7 @@ Feature: anonymous controller
197197
"""ruby
198198
require "rails_helper"
199199
200-
RSpec.describe ApplicationController do
200+
RSpec.describe ApplicationController, :type => :controller do
201201
controller do
202202
def index
203203
render :text => "index called"
@@ -375,7 +375,7 @@ Feature: anonymous controller
375375
"""ruby
376376
require "rails_helper"
377377
378-
RSpec.describe ApplicationController do
378+
RSpec.describe ApplicationController, :type => :controller do
379379
controller do
380380
def custom
381381
render :text => "custom called"
@@ -400,7 +400,7 @@ Feature: anonymous controller
400400
401401
class FoosController < ApplicationController; end
402402
403-
RSpec.describe ApplicationController do
403+
RSpec.describe ApplicationController, :type => :controller do
404404
controller FoosController do
405405
def custom
406406
render :text => "custom called"
@@ -430,7 +430,7 @@ Feature: anonymous controller
430430
end
431431
end
432432
433-
RSpec.describe TopLevel::InnerSpace::FoosController do
433+
RSpec.describe TopLevel::InnerSpace::FoosController, :type => :controller do
434434
controller do
435435
def index
436436
@name = self.class.name
@@ -466,7 +466,7 @@ Feature: anonymous controller
466466
match "/login" => "sessions#new", :as => "login", :via => "get"
467467
end
468468
469-
RSpec.describe ApplicationController do
469+
RSpec.describe ApplicationController, :type => :controller do
470470
controller do
471471
def index
472472
redirect_to login_url

features/controller_specs/bypass_rescue.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Feature: bypass rescue
3030
3131
require 'controllers/gadgets_controller_spec_context'
3232
33-
RSpec.describe GadgetsController do
33+
RSpec.describe GadgetsController, :type => :controller do
3434
before do
3535
def controller.index
3636
raise AccessDenied
@@ -55,7 +55,7 @@ Feature: bypass rescue
5555
5656
require 'controllers/gadgets_controller_spec_context'
5757
58-
RSpec.describe GadgetsController do
58+
RSpec.describe GadgetsController, :type => :controller do
5959
before do
6060
def controller.index
6161
raise AccessDenied

features/controller_specs/controller_spec.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: controller spec
55
"""ruby
66
require "rails_helper"
77
8-
RSpec.describe WidgetsController do
8+
RSpec.describe WidgetsController, :type => :controller do
99
describe "GET index" do
1010
it "has a 200 status code" do
1111
get :index
@@ -24,7 +24,7 @@ Feature: controller spec
2424
2525
RSpec.configure {|c| c.before { expect(controller).not_to be_nil }}
2626
27-
RSpec.describe WidgetsController do
27+
RSpec.describe WidgetsController, :type => :controller do
2828
describe "GET index" do
2929
it "doesn't matter" do
3030
end
@@ -46,7 +46,7 @@ Feature: controller spec
4646
4747
RSpec.configure {|c| c.include MyHelper }
4848
49-
RSpec.describe WidgetsController do
49+
RSpec.describe WidgetsController, :type => :controller do
5050
let(:my_variable) { 'is a value' }
5151
5252
describe 'something' do

features/controller_specs/engine_routes.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Feature: engine routes for controllers
3434
end
3535
end
3636
37-
RSpec.describe MyEngine::WidgetsController do
37+
RSpec.describe MyEngine::WidgetsController, :type => :controller do
3838
routes { MyEngine::Engine.routes }
3939
4040
it "redirects to a random widget" do

features/controller_specs/isolation_from_views.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: views are stubbed by default
1212
"""ruby
1313
require "rails_helper"
1414
15-
RSpec.describe WidgetsController do
15+
RSpec.describe WidgetsController, :type => :controller do
1616
describe "index" do
1717
it "renders the index template" do
1818
get :index
@@ -35,7 +35,7 @@ Feature: views are stubbed by default
3535
"""ruby
3636
require "rails_helper"
3737
38-
RSpec.describe WidgetsController do
38+
RSpec.describe WidgetsController, :type => :controller do
3939
describe "index" do
4040
it "renders the 'new' template" do
4141
get :index
@@ -52,7 +52,7 @@ Feature: views are stubbed by default
5252
"""ruby
5353
require "rails_helper"
5454
55-
RSpec.describe ThingsController do
55+
RSpec.describe ThingsController, :type => :controller do
5656
describe "custom_action" do
5757
it "renders an empty custom_action template" do
5858
controller.prepend_view_path 'app/views'
@@ -72,7 +72,7 @@ Feature: views are stubbed by default
7272
"""ruby
7373
require "rails_helper"
7474
75-
RSpec.describe ThingsController do
75+
RSpec.describe ThingsController, :type => :controller do
7676
render_views
7777
7878
it "renders the real custom_action template" do

features/controller_specs/render_views.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: render_views
88
"""ruby
99
require "rails_helper"
1010
11-
RSpec.describe WidgetsController do
11+
RSpec.describe WidgetsController, :type => :controller do
1212
render_views
1313
1414
describe "GET index" do
@@ -27,7 +27,7 @@ Feature: render_views
2727
"""ruby
2828
require "rails_helper"
2929
30-
RSpec.describe WidgetsController do
30+
RSpec.describe WidgetsController, :type => :controller do
3131
context "with render_views" do
3232
render_views
3333
@@ -101,7 +101,7 @@ Feature: render_views
101101
require "rails_helper"
102102
require "support/render_views"
103103
104-
RSpec.describe WidgetsController do
104+
RSpec.describe WidgetsController, :type => :controller do
105105
describe "GET index" do
106106
it "renders the index template" do
107107
get :index

features/feature_specs/feature_spec.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Feature: feature spec
55
through an application. They should drive the application only via its
66
external interface, usually web pages.
77

8+
Feature specs are marked by `:type => :feature` or if you have set
9+
`config.infer_spec_type_from_file_location!` by placing them in `spec/features`.
10+
811
Feature specs require the [capybara](http://github.com/jnicklas/capybara)
912
gem, version 2.2.0 or later (we recommend 2.3.0 or later to avoid some
1013
deprecation warnings). Refer to the [capybara API
@@ -14,7 +17,8 @@ Feature: feature spec
1417
The `feature` and `scenario` DSL correspond to `describe` and `it`,
1518
respectively. These methods are simply aliases that allow feature specs to
1619
read more as [customer tests](http://c2.com/cgi/wiki?CustomerTest) and
17-
[acceptance tests](http://c2.com/cgi/wiki?AcceptanceTest).
20+
[acceptance tests](http://c2.com/cgi/wiki?AcceptanceTest). They set
21+
`:type => :feature` automatically for you.
1822

1923
Scenario: specify creating a Widget by driving the application with capybara
2024
Given a file named "spec/features/widget_management_spec.rb" with:

features/helper_specs/helper_spec.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: helper spec
22

3-
Helper specs live in `spec/helpers`, or any example group with `:type =>
4-
:helper`.
3+
Helper specs are marked by `:type => :helper` or if you have set
4+
`config.infer_spec_type_from_file_location!` by placing them in `spec/helpers`.
55

66
Helper specs expose a `helper` object, which includes the helper module being
77
specified, the `ApplicationHelper` module (if there is one) and all of the
@@ -18,7 +18,7 @@ Feature: helper spec
1818
"""ruby
1919
require "rails_helper"
2020
21-
RSpec.describe ApplicationHelper do
21+
RSpec.describe ApplicationHelper, :type => :helper do
2222
describe "#page_title" do
2323
it "returns the default title" do
2424
expect(helper.page_title).to eq("RSpec is your friend")
@@ -42,7 +42,7 @@ Feature: helper spec
4242
"""ruby
4343
require "rails_helper"
4444
45-
RSpec.describe ApplicationHelper do
45+
RSpec.describe ApplicationHelper, :type => :helper do
4646
describe "#page_title" do
4747
it "returns the instance variable" do
4848
assign(:title, "My Title")
@@ -67,7 +67,7 @@ Feature: helper spec
6767
"""ruby
6868
require "rails_helper"
6969
70-
RSpec.describe WidgetsHelper do
70+
RSpec.describe WidgetsHelper, :type => :helper do
7171
describe "#widget_title" do
7272
it "includes the app name" do
7373
assign(:title, "This Widget")
@@ -100,7 +100,7 @@ Feature: helper spec
100100
"""ruby
101101
require "rails_helper"
102102
103-
RSpec.describe WidgetsHelper do
103+
RSpec.describe WidgetsHelper, :type => :helper do
104104
describe "#link_to_widget" do
105105
it "links to a widget using its name" do
106106
widget = Widget.create!(:name => "This Widget")

features/mailer_specs/url_helpers.feature

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Feature: URL helpers in mailer examples
22

3+
Mailer specs are marked by `:type => :mailer` or if you have set
4+
`config.infer_spec_type_from_file_location!` by placing them in `spec/mailer`.
5+
36
Scenario: using URL helpers with default options
47
Given a file named "config/initializers/mailer_defaults.rb" with:
58
"""ruby
@@ -9,7 +12,7 @@ Feature: URL helpers in mailer examples
912
"""ruby
1013
require 'rails_helper'
1114
12-
RSpec.describe Notifications do
15+
RSpec.describe Notifications, :type => :mailer do
1316
it 'should have access to URL helpers' do
1417
expect { gadgets_url }.not_to raise_error
1518
end
@@ -27,7 +30,7 @@ Feature: URL helpers in mailer examples
2730
"""ruby
2831
require 'rails_helper'
2932
30-
RSpec.describe Notifications do
33+
RSpec.describe Notifications, :type => :mailer do
3134
it 'should have access to URL helpers' do
3235
expect { gadgets_url :host => 'example.com' }.not_to raise_error
3336
expect { gadgets_url }.to raise_error

features/model_specs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Model specs live in `spec/models` or any example group with
2-
`:type => :model`.
1+
Model specs are marked by `:type => :model` or if you have set
2+
`config.infer_spec_type_from_file_location!` by placing them in `spec/models`.
33

44
A model spec is a thin wrapper for an ActiveSupport::TestCase, and includes all
55
of the behavior and assertions that it provides, in addition to RSpec's own
@@ -9,7 +9,7 @@ behavior and expectations.
99

1010
require "rails_helper"
1111

12-
RSpec.describe Post do
12+
RSpec.describe Post, :type => :model do
1313
context "with 2 or more comments" do
1414
it "orders them in reverse chronologically" do
1515
post = Post.create!

features/model_specs/transactional_examples.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature: transactional examples
1010
"""ruby
1111
require "rails_helper"
1212
13-
RSpec.describe Widget do
13+
RSpec.describe Widget, :type => :model do
1414
it "has none to begin with" do
1515
expect(Widget.count).to eq 0
1616
end
@@ -37,7 +37,7 @@ Feature: transactional examples
3737
c.use_transactional_examples = true
3838
end
3939
40-
RSpec.describe Widget do
40+
RSpec.describe Widget, :type => :model do
4141
it "has none to begin with" do
4242
expect(Widget.count).to eq 0
4343
end
@@ -65,7 +65,7 @@ Feature: transactional examples
6565
c.order = "defined"
6666
end
6767
68-
RSpec.describe Widget do
68+
RSpec.describe Widget, :type => :model do
6969
it "has none to begin with" do
7070
expect(Widget.count).to eq 0
7171
end
@@ -90,7 +90,7 @@ Feature: transactional examples
9090
"""ruby
9191
require "rails_helper"
9292
93-
RSpec.describe Thing do
93+
RSpec.describe Thing, :type => :model do
9494
fixtures :things
9595
it "fixture method defined" do
9696
things(:one)

features/request_specs/request_spec.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Feature: request spec
44
designed to drive behavior through the full stack, including routing
55
(provided by Rails) and without stubbing (that's up to you).
66

7+
Request specs are marked by `:type => :request` or if you have set
8+
`config.infer_spec_type_from_file_location!` by placing them in `spec/requests`.
9+
710
With request specs, you can:
811

912
* specify a single request
@@ -28,7 +31,7 @@ Feature: request spec
2831
"""ruby
2932
require "rails_helper"
3033
31-
RSpec.describe "Widget management" do
34+
RSpec.describe "Widget management", :type => :request do
3235
3336
it "creates a Widget and redirects to the Widget's page" do
3437
get "/widgets/new"

features/routing_specs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Routing specs live in the `spec/routing` directory, or any example group with
2-
`:type => :routing`.
1+
Routing specs are marked by `:type => :routing` or if you have set
2+
`config.infer_spec_type_from_file_location!` by placing them in `spec/routing`.
33

44
Simple apps with nothing but standard RESTful routes won't get much value from
55
routing specs, but they can provide significant value when used to specify

0 commit comments

Comments
 (0)