mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
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:
parent
19773bbd1c
commit
4a0e6335ef
1 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue