Skip to content
Browse files

cleanup after #891

  • Loading branch information...
1 parent 3e37de9 commit 143e3cdae859f4efeff140bb0d45423a61f3298b @JonRowe JonRowe committed Dec 25, 2013
View
378 features/controller_specs/anonymous_controller.feature
@@ -122,34 +122,34 @@ Feature: anonymous controller
Scenario: get name and controller_name from the described class
Given a file named "spec/controllers/get_name_and_controller_name_from_described_class_spec.rb" with:
- """ruby
- require "spec_helper"
-
- class ApplicationController < ActionController::Base; end
- class FoosController < ApplicationController; end
-
- describe "FoosController controller_name" do
- controller FoosController do
- def index
- @name = self.class.name
- @controller_name = controller_name
- render :text => "Hello World"
+ """ruby
+ require "spec_helper"
+
+ class ApplicationController < ActionController::Base; end
+ class FoosController < ApplicationController; end
+
+ describe "FoosController controller_name" do
+ controller FoosController do
+ def index
+ @name = self.class.name
+ @controller_name = controller_name
+ render :text => "Hello World"
+ end
end
- end
- before do
- get :index
- end
+ before do
+ get :index
+ end
- it "gets the class name as described" do
- expect(assigns[:name]).to eq('FoosController')
- end
+ it "gets the class name as described" do
+ expect(assigns[:name]).to eq('FoosController')
+ end
- it "gets the controller_name as described" do
- expect(assigns[:controller_name]).to eq('foos')
+ it "gets the controller_name as described" do
+ expect(assigns[:controller_name]).to eq('foos')
+ end
end
- end
- """
+ """
When I run `rspec spec`
Then the examples should all pass
@@ -186,251 +186,251 @@ Feature: anonymous controller
Scenario: anonymous controllers only create resource routes
Given a file named "spec/controllers/application_controller_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe ApplicationController do
- controller do
- def index
- render :text => "index called"
- end
+ """ruby
+ require "spec_helper"
- def create
- render :text => "create called"
- end
+ describe ApplicationController do
+ controller do
+ def index
+ render :text => "index called"
+ end
- def new
- render :text => "new called"
- end
+ def create
+ render :text => "create called"
+ end
- def show
- render :text => "show called"
- end
+ def new
+ render :text => "new called"
+ end
- def edit
- render :text => "edit called"
- end
+ def show
+ render :text => "show called"
+ end
- def update
- render :text => "update called"
- end
+ def edit
+ render :text => "edit called"
+ end
- def destroy
- render :text => "destroy called"
- end
+ def update
+ render :text => "update called"
+ end
- def willerror
- render :text => "will not render"
- end
- end
+ def destroy
+ render :text => "destroy called"
+ end
- describe "#index" do
- it "responds to GET" do
- get :index
- expect(response.body).to eq "index called"
+ def willerror
+ render :text => "will not render"
+ end
end
- it "also responds to POST" do
- post :index
- expect(response.body).to eq "index called"
- end
+ describe "#index" do
+ it "responds to GET" do
+ get :index
+ expect(response.body).to eq "index called"
+ end
- it "also responds to PUT" do
- put :index
- expect(response.body).to eq "index called"
- end
+ it "also responds to POST" do
+ post :index
+ expect(response.body).to eq "index called"
+ end
- it "also responds to DELETE" do
- delete :index
- expect(response.body).to eq "index called"
- end
- end
+ it "also responds to PUT" do
+ put :index
+ expect(response.body).to eq "index called"
+ end
- describe "#create" do
- it "responds to POST" do
- post :create
- expect(response.body).to eq "create called"
+ it "also responds to DELETE" do
+ delete :index
+ expect(response.body).to eq "index called"
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :create)
+ describe "#create" do
+ it "responds to POST" do
+ post :create
expect(response.body).to eq "create called"
end
- end
- end
- describe "#new" do
- it "responds to GET" do
- get :new
- expect(response.body).to eq "new called"
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :create)
+ expect(response.body).to eq "create called"
+ end
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :new)
+ describe "#new" do
+ it "responds to GET" do
+ get :new
expect(response.body).to eq "new called"
end
- end
- end
-
- describe "#edit" do
- it "responds to GET" do
- get :edit, :id => "anyid"
- expect(response.body).to eq "edit called"
- end
- it "requires the :id parameter" do
- expect { get :edit }.to raise_error(ActionController::RoutingError)
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :new)
+ expect(response.body).to eq "new called"
+ end
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :edit, {:id => "anyid"})
+ describe "#edit" do
+ it "responds to GET" do
+ get :edit, :id => "anyid"
expect(response.body).to eq "edit called"
end
- end
- end
- describe "#show" do
- it "responds to GET" do
- get :show, :id => "anyid"
- expect(response.body).to eq "show called"
- end
+ it "requires the :id parameter" do
+ expect { get :edit }.to raise_error(ActionController::RoutingError)
+ end
- it "requires the :id parameter" do
- expect { get :show }.to raise_error(ActionController::RoutingError)
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :edit, {:id => "anyid"})
+ expect(response.body).to eq "edit called"
+ end
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :show, {:id => "anyid"})
+ describe "#show" do
+ it "responds to GET" do
+ get :show, :id => "anyid"
expect(response.body).to eq "show called"
end
- end
- end
- describe "#update" do
- it "responds to PUT" do
- put :update, :id => "anyid"
- expect(response.body).to eq "update called"
- end
+ it "requires the :id parameter" do
+ expect { get :show }.to raise_error(ActionController::RoutingError)
+ end
- it "requires the :id parameter" do
- expect { put :update }.to raise_error(ActionController::RoutingError)
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :show, {:id => "anyid"})
+ expect(response.body).to eq "show called"
+ end
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :update, {:id => "anyid"})
+ describe "#update" do
+ it "responds to PUT" do
+ put :update, :id => "anyid"
expect(response.body).to eq "update called"
end
- end
- end
- describe "#destroy" do
- it "responds to DELETE" do
- delete :destroy, :id => "anyid"
- expect(response.body).to eq "destroy called"
- end
+ it "requires the :id parameter" do
+ expect { put :update }.to raise_error(ActionController::RoutingError)
+ end
- it "requires the :id parameter" do
- expect { delete :destroy }.to raise_error(ActionController::RoutingError)
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :update, {:id => "anyid"})
+ expect(response.body).to eq "update called"
+ end
+ end
end
- # And the rest...
- %w{get post put delete}.each do |calltype|
- it "responds to #{calltype}" do
- send(calltype, :destroy, {:id => "anyid"})
+ describe "#destroy" do
+ it "responds to DELETE" do
+ delete :destroy, :id => "anyid"
expect(response.body).to eq "destroy called"
end
+
+ it "requires the :id parameter" do
+ expect { delete :destroy }.to raise_error(ActionController::RoutingError)
+ end
+
+ # And the rest...
+ %w{get post put delete}.each do |calltype|
+ it "responds to #{calltype}" do
+ send(calltype, :destroy, {:id => "anyid"})
+ expect(response.body).to eq "destroy called"
+ end
+ end
end
- end
- describe "#willerror" do
- it "cannot be called" do
- expect { get :willerror }.to raise_error(ActionController::RoutingError)
+ describe "#willerror" do
+ it "cannot be called" do
+ expect { get :willerror }.to raise_error(ActionController::RoutingError)
+ end
end
end
- end
- """
+ """
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"
+ """ruby
+ require "spec_helper"
- describe ApplicationController do
- controller do
- def custom
- render :text => "custom called"
+ describe ApplicationController do
+ controller do
+ def custom
+ render :text => "custom called"
+ end
end
- end
- specify "a custom action can be requested if routes are drawn manually" do
- routes.draw { get "custom" => "anonymous#custom" }
+ specify "a custom action can be requested if routes are drawn manually" do
+ routes.draw { get "custom" => "anonymous#custom" }
- get :custom
- expect(response.body).to eq "custom called"
+ get :custom
+ expect(response.body).to eq "custom called"
+ end
end
- end
- """
+ """
When I run `rspec spec`
Then the examples should all pass
Scenario: draw custom routes for defined controllers
Given a file named "spec/controllers/application_controller_spec.rb" with:
- """ruby
- require "spec_helper"
+ """ruby
+ require "spec_helper"
- class FoosController < ApplicationController; end
+ class FoosController < ApplicationController; end
- describe ApplicationController do
- controller FoosController do
- def custom
- render :text => "custom called"
+ describe ApplicationController do
+ controller FoosController do
+ def custom
+ render :text => "custom called"
+ end
end
- end
- specify "a custom action can be requested if routes are drawn manually" do
- routes.draw { get "custom" => "foos#custom" }
+ specify "a custom action can be requested if routes are drawn manually" do
+ routes.draw { get "custom" => "foos#custom" }
- get :custom
- expect(response.body).to eq "custom called"
+ get :custom
+ expect(response.body).to eq "custom called"
+ end
end
- end
- """
+ """
When I run `rspec spec`
Then the examples should all pass
Scenario: refer to application routes in the controller under test
Given a file named "spec/controllers/application_controller_spec.rb" with:
- """ruby
- require "spec_helper"
+ """ruby
+ require "spec_helper"
- Rails.application.routes.draw do
- match "/login" => "sessions#new", :as => "login", :via => "get"
- end
+ Rails.application.routes.draw do
+ match "/login" => "sessions#new", :as => "login", :via => "get"
+ end
- describe ApplicationController do
- controller do
- def index
- redirect_to login_url
+ describe ApplicationController do
+ controller do
+ def index
+ redirect_to login_url
+ end
end
- end
- it "redirects to the login page" do
- get :index
- expect(response).to redirect_to("/login")
+ it "redirects to the login page" do
+ get :index
+ expect(response).to redirect_to("/login")
+ end
end
- end
- """
+ """
When I run `rspec spec`
Then the examples should all pass
View
1 lib/rspec/rails/example/controller_example_group.rb
@@ -98,7 +98,6 @@ def routes(&blk)
self.routes = blk.call
end
end
-
end
attr_reader :controller, :routes
View
6 spec/rspec/rails/example/controller_example_group_spec.rb
@@ -98,7 +98,7 @@ module RSpec::Rails
end
describe "controller name" do
- let(:controller_class) { group.metadata[:example_group][:described_class]}
+ let(:controller_class) { group.metadata[:example_group][:described_class] }
it "sets the name as AnonymousController if it's anonymous" do
group.controller { }
@@ -107,12 +107,12 @@ module RSpec::Rails
it "sets the name according to defined controller if it is not anonymous" do
stub_const "FoosController", Class.new(::ApplicationController)
- group.controller(FoosController){ }
+ group.controller(FoosController) { }
expect(controller_class.name).to eq "FoosController"
end
it "sets name as AnonymousController if defined as ApplicationController" do
- group.controller(ApplicationController){ }
+ group.controller(ApplicationController) { }
expect(controller_class.name).to eq "AnonymousController"
end
end

0 comments on commit 143e3cd

Please sign in to comment.
Something went wrong with that request. Please try again.