improves Cucumber documentation in README

This commit is contained in:
Josh Rendek 2011-11-21 18:46:56 -07:00 committed by Ben Mabey
parent 2447c3cd12
commit c7794ad165
1 changed files with 33 additions and 2 deletions

View File

@ -70,7 +70,7 @@ strategy the remaining time. To accomplish this you can say:
# then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
</pre>
Example usage with RSpec:
h3. RSpec Example
<pre>
RSpec.configure do |config|
@ -91,7 +91,38 @@ RSpec.configure do |config|
end
</pre>
For use in Cucumber please see the section below.
h3. Cucumber Example
Add this to your features/support/env.rb file:
<pre>
begin
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
</pre>
A good idea is to create the before and after hooks to use the DatabaseCleaner.start and DatabaseCleaner.clean methods.
Inside features/support/hooks.rb:
<pre>
Before do
DatabaseCleaner.start
end
After do |scenario|
DatabaseCleaner.clean
end
</pre>
This should cover the basics of tear down between scenarios and keeping your database clean.
For more examples see the section "Why?"
h2. Common Errors
In rare cases DatabaseCleaner will encounter errors that it will log. By default it uses STDOUT set to the ERROR level but you can configure this to use whatever Logger you desire. Here's an example of using the Rails.logger in env.rb: