Created
March 16, 2012 11:54
-
-
Save JonRowe/2049753 to your computer and use it in GitHub Desktop.
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
$:.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 |
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
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