Skip to content

Add cuke feature explaining custom routes #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions features/controller_specs/anonymous_controller.feature
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,45 @@ Feature: anonymous controller
"""
When I run `rspec spec`
Then the examples should all pass


Scenario: draw custom routes for anonymous controllers
Given a file named "spec/controllers/application_controller_spec.rb" with:
"""ruby
require "spec_helper"

describe ApplicationController do
controller do

def custom
render :text => "custom called"
end
end

describe "a custom route in an anonymous controllers" do

it "is not supported by default" do
expect { get :custom }.to raise_error(ActionController::RoutingError)
expect { get :custom, :custom_id => 13 }.to raise_error(ActionController::RoutingError)
end

context "with custom routes drawn in the spec" do
it "is supported with no params" do
routes.draw { get "custom" => "anonymous#custom" }
get :custom
expect(response.body).to eq "custom called"
end

it "is supported with custom params" do
routes.draw { get "custom" => "anonymous#custom" }
get :custom
expect(response.body).to eq "custom called"
end

end

end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of this would be:

ApplicationController
  custom
    does not work by default
    when custom routes are drawn
      works
    when a route is drawn with custom parameters
      accepts custom parameters

I think it would read better like this (or similar):

a custom route in an anonymous controllers
  is not supported by default
  with custom routes drawn in the spec
    is supported with no params
    is supported with custom params

Note that this moves the code in before hooks right into the examples, but that's fine in this case because there is no duplication. WDYT?

"""
When I run `rspec spec`
Then the examples should all pass