Created
December 23, 2011 01:27
-
-
Save rafaelrosafu/1512670 to your computer and use it in GitHub Desktop.
How to fix problems using Devise, factories and Capybara + regular specs
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. For factory_girl do:
FactoryGirl.reload