Skip to content

Commit

Permalink
README, suggest append_after to ensure proper order of capybara clean…
Browse files Browse the repository at this point in the history
…up and DC

It's best to have DatabaseCleaner.clean run AFTER capybara cleanup, in case capybara cleanup ends up triggering anything that could be interrupted by the database cleaner. 

`require 'capybara/rspec'` installs an after hook for Capybara cleanup. 

rspec after hooks are run in _reverse_ order of definition, after hooks defined last are run first. So with `require 'capybara/rspec'` at top of file, and then later manually defining an after hook for DC cleanup... DC cleanup fires before capybara's cleanup. 

Using RSpec's `append_after` instead of `after` fixes this. With so many timing issues that can go wrong with capybara, might as well eliminate one more potential one.
  • Loading branch information
jrochkind committed Dec 22, 2015
1 parent b87f003 commit 67a5ed9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.markdown
Expand Up @@ -221,9 +221,14 @@ end

### RSpec with Capybara Example

If you're using Capybara with RSpec and using an external browser (not using RackTest) you'll almost certainly need to use truncation rather than transactions for tests tagged `:js`.
If you're using Capybara with RSpec and using an external browser (not using RackTest) you'll almost certainly need to use truncation rather than transactions for tests tagged `:js`. It's also recommended to use `append_after` to ensure
DatabaseCleaner runs after rspec's after-test cleanup.

```ruby
require 'capybara/rspec'

#...

RSpec.configure do |config|

config.use_transactional_fixtures = false
Expand All @@ -237,7 +242,7 @@ RSpec.configure do |config|
DatabaseCleaner.start
end

config.after(:each) do
config.append_after(:each) do
DatabaseCleaner.clean
end

Expand Down

0 comments on commit 67a5ed9

Please sign in to comment.