Created
November 10, 2012 08:12
-
-
Save weilu/4050393 to your computer and use it in GitHub Desktop.
Configure database_cleaner for a test suite that contains Capybara js 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
RSpec.configure do |config| | |
config.use_transactional_fixtures = false | |
config.before(:suite) do | |
DatabaseCleaner.clean_with :truncation | |
end | |
config.before(:each) do | |
if example.metadata[:js] | |
DatabaseCleaner.strategy = :truncation | |
else | |
DatabaseCleaner.strategy = :transaction | |
end | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note:
example.metadata
is no longer available in the config.before(:each) block from at least 3.2.0. See: https://github.com/rspec/rspec-core/blob/13c6674f8021ab7f00dc70559871169d2595cc12/Changelog.md The error message describes this best:One can get around this by using
config.before(:each) do |example|