From eb11223b233824569559a7adcaf259eec38a59c9 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 24 Jan 2013 19:32:46 -0500 Subject: [PATCH] actually write some docs --- README.md | 84 ++++++++++++++++++++------ lib/cuke-pack/support/expect_fields.rb | 1 + lib/cuke-pack/support/wait_for.rb | 4 ++ skel/config/cucumber.yml | 6 +- skel/features/support/cuke-pack.rb | 26 +++----- 5 files changed, 86 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index ef0be69..c21cdc3 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,79 @@ -# Cuke::Pack +# cuke-pack -TODO: Write a gem description +Common Cucumber setups to make things go fast and smooth. -## Installation +## Install it -Add this line to your application's Gemfile: +``` ruby +# Gemfile - gem 'cuke-pack' +gem 'cuke-pack' +``` -And then execute: +``` bash +bundle exec cuke-pack install +``` - $ bundle +This will overwrite your `config/cucumber.yml` file with one that plugs in nicely with Guard. It also adds a new config file in +`features/support/cuke-pack.rb`. -Or install it yourself as: +## Specifying the driver - $ gem install cuke-pack +If you have other Capybara drivers installed like Poltergeist of persistent_selenium, you can specify the driver as an +environment variable: -## Usage +``` bash +DRIVER=poltergeist bundle exec cucumber +``` -TODO: Write usage instructions here +## Confirming JavaScript -## Contributing +If you need to confirm an `alert()` or `confirm()`, you can do so in your step with `confirm_js`. Just replaces +`window.alert` and `window.confirm` with functions that return true. + +## Step Writer + +Enables [cucumber-step_writer](http://github.com/johnbintz/cucumber-step_writer) for you. + +## Flay your steps + +I can get duplicate code in my steps pretty quickly. Sometimes I flay them to see where the duplicates are and then I +factor out the common code. + +## Hijacking `@wip` + +I personally think the original use of `@wip` in Cucumber is silly. Why would you commit non-working +features to the source repository? So this project re-purposes `@wip` to let you focus your Cucumber test +runs on a single feature and work on it until it runs: + +### Guard + +If you're using Guard for continuous testing, install the `wip` guard: + +``` bash +bundle exec cuke-pack wip-guard +``` + +You can then use Guard to only run scenarios with the tag `@wip`: + +``` bash +bundle exec guard -g wip +``` + +### Precommit + +If you run tests before committing your code with a tool like [penchant](http://github.com/johnbintz/penchant), +you can configure your tests to run using the `precommit` profile. This one ensures that there are no +`@wip` scenarios. It also lets you skip certain features/scenarios that are tagged `@no-precommit`. Good for +turning off tests that you haven't needed to touch in a while. Just be careful with it! + +## Other things + +You can easily enable FakeFS, Mocha, and Timecop if you need them. Turn them on in `cuke-pack.rb` and then use +the right tag on your scenario. + +## Old things + +There's some stuff that is so deprecated that I'll remove it eventually, once all my other offending projects +don't use them anymore. You shouldn't use them either. -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request diff --git a/lib/cuke-pack/support/expect_fields.rb b/lib/cuke-pack/support/expect_fields.rb index a7c3462..f17170d 100644 --- a/lib/cuke-pack/support/expect_fields.rb +++ b/lib/cuke-pack/support/expect_fields.rb @@ -1,4 +1,5 @@ def expect_fields(object, *fields, &block) + $stderr.puts "expect_fields deprecated. Use semantic_rails_view_helpers instead." @__expect_stack ||= 0 @__expect_stack += 1 diff --git a/lib/cuke-pack/support/wait_for.rb b/lib/cuke-pack/support/wait_for.rb index 4f056b0..232b325 100644 --- a/lib/cuke-pack/support/wait_for.rb +++ b/lib/cuke-pack/support/wait_for.rb @@ -48,6 +48,8 @@ class WaitingForElementFailure < StandardError end def wait_for(times = MAX_TIMES, &block) + $stderr.puts "wait_for deprecated. Just use find." + 1.upto(times) do ok = false @@ -68,6 +70,8 @@ def wait_for(times = MAX_TIMES, &block) end def wait_for_not(times = MAX_TIMES, &block) + $stderr.puts "wait_for_not deprecated. Just use find." + original_time = Capybara.default_wait_time Capybara.default_wait_time = 0 diff --git a/skel/config/cucumber.yml b/skel/config/cucumber.yml index cd59005..26f104f 100644 --- a/skel/config/cucumber.yml +++ b/skel/config/cucumber.yml @@ -3,6 +3,10 @@ std_opts = "-r features --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} -f Cucumb %> default: <%= std_opts %> features wip: <%= std_opts %> --tags @wip features -precommit: FAILFAST=true <%= std_opts %> --tags ~@wip:0 features +precommit: <%= std_opts %> --tags ~@wip:0 --tags @no-precommit features + +# or enable FAILFAST to have your tests end immediately on failure +#precommit: FAILFAST=true <%= std_opts %> --tags ~@wip:0 features + cleanup: <%= std_opts %> -f Cucumber::CleanupFormatter --out unused.txt features diff --git a/skel/features/support/cuke-pack.rb b/skel/features/support/cuke-pack.rb index 30f115e..badb595 100644 --- a/skel/features/support/cuke-pack.rb +++ b/skel/features/support/cuke-pack.rb @@ -1,36 +1,28 @@ -require 'cuke-pack/support/pause' -require 'cuke-pack/support/pending' +# use confirm_js in your step to confirm all alert() and confirm() dialogs require 'cuke-pack/support/confirm_js' -require 'cuke-pack/support/expect_fields' - -Before do - # if you want pending steps to pause before marking the step as pending, - # set @pause_ok to true - - @pause_ok = false -end +# write out missing steps automatically require 'cuke-pack/support/step_writer' -require 'cuke-pack/support/wait_for' + +# fail instantly if ENV['FAILFAST'] is set require 'cuke-pack/support/failfast' # set the level of flaying on the step definitions # set it to false to skip flaying flay_level = 32 - require 'cuke-pack/support/flay' +# enable fakefs with @fakefs # require 'cuke-pack/support/fakefs' + +# enable mocha with @mocha # require 'cuke-pack/support/mocha' -# Timecop support +# Timecop support with @timecop # require 'cuke-pack/support/timecop' # Browser drivers # use with ENV['DRIVER'] +require 'cuke-pack/drivers' # require 'cuke-pack/driver/firefox' -# -# Simple rails controller/view generator -# probably only any good for me -# require 'cuke-pack/support/rails_generator'