Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save adaRn/f9d7d3d6cd310e1e3dd6fb804156eb60 to your computer and use it in GitHub Desktop.

Select an option

Save adaRn/f9d7d3d6cd310e1e3dd6fb804156eb60 to your computer and use it in GitHub Desktop.

Revisions

  1. adaRn created this gist Aug 14, 2017.
    22 changes: 22 additions & 0 deletions DatabaseCleaner cleaning database too early.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    ## Solution:

    In your `helper` change

    ```ruby
    config.after(:each) do
    DatabaseCleaner.clean
    end
    ```
    to

    ```ruby
    config.append_after(:each) do
    DatabaseCleaner.clean
    end
    ```


    ### Why this works?
    `after` is in fact an alias for `prepend_after`, which means `DatabaseCleaner.clean` will run before Capybara and its drivers terminate all connections.

    Stopping Capybara first and then cleaning the database will ensure no errors will arise from requests that Capybara's driver makes because of already cleaned database. The requests that are yielding errors don't even necessarily have to be explicitly issued by you - it's enough that one of tons of requests that a browser makes fails.