Skip to content

Instantly share code, notes, and snippets.

@rafaelrosafu
Created December 23, 2011 01:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafaelrosafu/1512670 to your computer and use it in GitHub Desktop.
Save rafaelrosafu/1512670 to your computer and use it in GitHub Desktop.
How to fix problems using Devise, factories and Capybara + regular specs
# Avoid problems when running Capybara specs before regular ones, and fix the
# "Could not find a valid mapping for X". Part of the solution is to use the
# Devise test helpers as explained on link A, but then you need to clear the
# fabricated objects, as explained on link B. Here's the equivalent code when
# using the Fabrication gem
#
# A - http://stackoverflow.com/questions/4230152/mocks-arent-working-with-rspec-and-devise
# B - http://stackoverflow.com/questions/6363471/could-not-find-a-valid-mapping-for-user-only-on-second-and-successive-t
if Rails.env.development? || Rails.env.test?
ActionDispatch::Callbacks.after do
Rails.logger.debug 'Reloading fabricators'
Fabrication.clear_definitions
end
end
@shadowmaru
Copy link

Nice. For factory_girl do:

FactoryGirl.reload

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