Skip to content

Instantly share code, notes, and snippets.

Forked from henrik/example_spec.rb
Created August 14, 2012 14:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Testing Draper decorators with real helpers, including URL helpers.
require "spec_helper"
# :draper_with_helpers is necessary for the Draper objects
# to access real helpers, including URL helpers, in the spec.
describe MyDecorator, "#foo", :draper_with_helpers do
# This is necessary for the spec itself to use URL helpers
# like some_path().
include Rails.application.routes.url_helpers
let(:item) { }
subject { }
it { should include some_path(item) }
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
# Make helpers, including link helpers, work with Draper in specs.
# NOTE: You may need to change ":all" to ":each" for this to work. See Gist comments.
config.before(:all, :draper_with_helpers) do
c =
c.request =
Draper::ViewContext.current = c.view_context
Copy link

This does not work anymore. It has no effect. Use the following:

Draper::ViewContext.test_strategy :fast do
  include Rails.application.routes.url_helpers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment