Created
          May 18, 2012 23:06 
        
      - 
      
 - 
        
Save mattbrictson/2728030 to your computer and use it in GitHub Desktop.  
    Faster Capybara Specs
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | gem 'database_cleaner', group: :test | 
  
    
      This file contains hidden or 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(:each) do | |
| DatabaseCleaner.strategy = if example.metadata[:js] | |
| :truncation | |
| else | |
| :transaction | |
| end | |
| DatabaseCleaner.start | |
| end | |
| config.after(:each) do | |
| DatabaseCleaner.clean | |
| end | |
| end | 
Thanks, his is great! I experimented with every way I could think of to put the transaction strategy into only the needed tests, but didn't realize there was this example.metadata[:js] trick. This should definitely be put into the docs for database_cleaner on github.
Man, this is super helpful! Just reduced by tests from 1 minute 8 seconds to 18 seconds! Thans so much :-D
This also fixed some other issues rspec+capybara-webkit was having as well. Thanks!
Cool!! Thanks!
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
More information in this blog post: http://blog.55minutes.com/2012/05/faster-capybara-specs/