Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Created March 16, 2012 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonRowe/2049753 to your computer and use it in GitHub Desktop.
Save JonRowe/2049753 to your computer and use it in GitHub Desktop.
$:.push File.expand_path '../../', __FILE__
module ActiveRecord
class RecordNotFound < StandardError; end
end
require 'action_controller'
require 'app/controllers/application_controller'
module ControllerSpecHelpers
class FakeRequest
def parameters
@_params ||= ActiveSupport::HashWithIndifferentAccess.new
end
end
def controller
unless @_controller
@_controller = described_class.new
@_controller.stub(:render)
@_controller.stub(:redirect_to)
@_controller.request = FakeRequest.new
end
@_controller
end
def params
controller.params
end
def request
controller.request
end
end
RSpec.configure do |config|
config.include ControllerSpecHelpers, :type => :controller
end
require 'controller_bootstrap'
require 'app/controllers/example_controller'
describe ExampleController, :type => :controller do
describe '#show' do
let(:special_params) { { "key" => "values" } }
before do
(ServiceLayer ||= Class.new).stub(:perform_action)
params[:special_params] = special_params
end
subject { controller.show }
it 'uses the service layer with the params' do
ServiceLayer.should_receive(:perform_action).with special_params
subject
end
it "renders the template" do
controller.should_receive(:render).with('special_example')
subject
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment