-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows metadata to override the type of Rails spec
[Fixes #801]
- Loading branch information
Showing
3 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Feature: Directory Structure | ||
|
||
Specs are usually placed in a canonical directory structure that describes | ||
their purpose. | ||
|
||
* Model specs reside in the `spec/models` directory | ||
* Controller specs reside in the `spec/controllers` directory | ||
* Request specs reside in the `spec/requests` directory | ||
* Feature specs reside in the `spec/features` directory | ||
* View specs reside in the `spec/views` directory | ||
* Helper specs reside in the `spec/helpers` directory | ||
* Mailer specs reside in the `spec/mailers` directory | ||
* Routing specs reside in the `spec/routing` directory | ||
|
||
If you follow this directory structure, RSpec will automatically include the | ||
correct test support functions for each type of test. | ||
|
||
Application developers are free to use a different directory structure, but | ||
will need to specify the types manually by adding a `:type` metadata key (for | ||
example, `describe WidgetsController, :type => :controller`) | ||
|
||
Scenario: Specs in the `spec/controllers` directory automatically tagged as controller specs | ||
Given a file named "spec/controllers/widgets_controller_spec.rb" with: | ||
"""ruby | ||
require "spec_helper" | ||
describe WidgetsController do | ||
it "responds successfully" do | ||
get :index | ||
expect(response.status).to eq(200) | ||
end | ||
end | ||
""" | ||
When I run `rspec spec` | ||
Then the example should pass | ||
|
||
Scenario: Specs in other directories must have their types specified manually | ||
Given a file named "spec/functional/widgets_controller_spec.rb" with: | ||
"""ruby | ||
require "spec_helper" | ||
describe WidgetsController, :type => :controller do | ||
it "responds successfully" do | ||
get :index | ||
expect(response.status).to eq(200) | ||
end | ||
end | ||
""" | ||
When I run `rspec spec` | ||
Then the example should pass | ||
|
||
Scenario: Specs in canonical directories can override their types | ||
Given a file named "spec/routing/duckduck_routing_spec.rb" with: | ||
"""ruby | ||
require "spec_helper" | ||
Rails.application.routes.draw do | ||
get "/example" => redirect("http://example.com") | ||
end | ||
# Due to limitations in the Rails routing test framework, routes that | ||
# perform redirects must actually be tested via request specs | ||
describe "/example", :type => :request do | ||
it "redirects to example.com" do | ||
get "/example" | ||
expect(response).to redirect_to("http://example.com") | ||
end | ||
end | ||
""" | ||
When I run `rspec spec` | ||
Then the example should pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters