Add documentation for RSpec with Capybara

Note: I could have used an around(:each) block as in the ordinary RSpec
example but there's currently an open issue that might affect many users:
https://github.com/DatabaseCleaner/database_cleaner/issues/273
This commit is contained in:
tgaff 2015-06-21 16:45:51 -07:00
parent 19773bbd1c
commit 4a0e6335ef

View file

@ -219,6 +219,32 @@ RSpec.configure do |config|
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`.
```ruby
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
config.after(:each)
DatabaseCleaner.clean
end
end
```
### Minitest Example
```ruby