capybara icon indicating copy to clipboard operation
capybara copied to clipboard

Capybara should not make assumptions about databases:

Open aslakhellesoy opened this issue 16 years ago • 4 comments

Fix on my no-db-knowledge branch. The commit: http://github.com/aslakhellesoy/capybara/commit/bb6051078a4ac645f607fd0003b8280f33e8c353

I have added support for DatabaseCleaner in Cucumber (enabled for @javascript, @culerity, @selenium and @no-txn tags only), which lets users enjoy the same "it just works" experience as before. -And now they can more easily opt out of DatabaseCleaner if they don't want/need it.

Previous discussion here: http://groups.google.com/group/ruby-capybara/browse_thread/thread/e43522c3e4808d95

aslakhellesoy avatar Dec 09 '09 16:12 aslakhellesoy

FYI: Here is how DatabaseCleaner is enabled in Cucumber-Rails: http://github.com/aslakhellesoy/cucumber-rails/blob/master/lib/cucumber/rails/active_record.rb

aslakhellesoy avatar Dec 09 '09 16:12 aslakhellesoy

I've made a separate file to require of you dont want to use DatabaseCleaner : http://github.com/denro/capybara/commit/db64f1b7aee95548e85ec49eefb3e5011d2a6cea

denro avatar Dec 10 '09 01:12 denro

denro: I see a few problems with your approach:

  1. If I use Sinatra+DataMapper I don't want to require 'rails' stuff.
  2. database_cleaner/cucumber is being used - which adds global hooks - bad (see below).
  3. More files that just require each other. Let's not help people do require - they know how to do that.

My fix is simpler. Simply remove 3 lines of code. The commit in my second comment shows how an equivalent setup is now moved to Cucumber-Rails. This setup (using tagged Before and After hooks) also allows DatabaseCleaner to kick in on a per-scenario basis. The current code (and dentro's) don't allow for this kind of per-scenario control.

For people using Capybara, but not Cucumber I recommend a similar approach. Let people do their own setup of DatabaseCleaner. It's just 3 lines of code anyway.

aslakhellesoy avatar Dec 10 '09 06:12 aslakhellesoy

I pulled in your change that removes the Database cleaner code.

jnicklas avatar Dec 12 '09 21:12 jnicklas