No commit activity in last 3 years
No release in over 3 years
Testing your ApplicationController with RSpec often requires using the AnonymousController and drawing custom routes. This helper does all that for you and prevents you from having to update your AnonymousController whenever you make a change to the ApplicationController.'
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

~> 3.4.0
 Project Readme

ShadowController

An RSpec helper that makes testing your rails ApplicationController a cool breeze.

Testing your ApplicationController often requires using the AnonymousController and drawing custom routes. This helper does all that for you and prevents you from having to update your AnonymousController whenever you make a change to the ApplicationController.

Installation

Add this line to your application's Gemfile:

group :development, :test do
  gem 'shadow_controller', '~> 0.1.1'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install shadow_controller -v 0.1.1

Usage

Install rspec-rails

Include ShadowController in your RSpec configure.

# spec/rails_helper.rb
RSpec.configure do |config|
  include ShadowController
end

Use the cast_shadow method in your spec

# spec/controllers/application_controller_spec.rb
require "spec_helper"

describe ApplicationController, type: :controller do
  shadow_controller

  it "..." do
    ...
  end
end

Example Use-case

# config/routes.rb
get "/resource", to: "application#redirect_somewhere"

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def redirect_somewhere
    redirect_to 'http://www.example.com'
  end
end

# spec/controllers/application_controller_spec.rb
require "spec_helper"

describe ApplicationController, type: :controller do
  shadow_controller

  it "#redirect_somewhere" do
    get :redirect_somewhere
    expect(response).to redirect_to 'http://www.example.com'
  end
end

Without the shadow_controller method (above) or extra configurations, this test would have failed with the following error

1) ApplicationController #redirect_somewhere
     Failure/Error: get :redirect_somewhere

     ActionController::UrlGenerationError:
       No route matches {:action=>"redirect_somewhere", :controller=>"application"}
     # ./spec/controllers/application_controller_spec.rb:8:in `block (2 levels) in <top (required)>'

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/milesstanfield/shadow_controller. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.