From a9d5f05c483424298d61c753a9d5492f5ef39945 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 25 Apr 2012 09:29:52 -0400 Subject: [PATCH] initial stuff --- .gitignore | 17 ++++++++++ Gemfile | 4 +++ LICENSE | 22 +++++++++++++ README.md | 29 +++++++++++++++++ Rakefile | 2 ++ bin/cuke-pack | 23 +++++++++++++ cuke-pack.gemspec | 23 +++++++++++++ lib/cucumber/cleanup_formatter.rb | 25 +++++++++++++++ lib/cuke-pack.rb | 2 ++ lib/cuke-pack/support/failfast.rb | 7 ++++ lib/cuke-pack/support/flay.rb | 18 +++++++++++ lib/cuke-pack/support/pause.rb | 8 +++++ lib/cuke-pack/support/pending.rb | 10 ++++++ lib/cuke-pack/support/step_writer.rb | 13 ++++++++ lib/cuke-pack/support/wait_for.rb | 48 ++++++++++++++++++++++++++++ lib/cuke-pack/version.rb | 3 ++ skel/config/cucumber.yml | 8 +++++ skel/features/support/cuke-pack.rb | 20 ++++++++++++ 18 files changed, 282 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/cuke-pack create mode 100644 cuke-pack.gemspec create mode 100644 lib/cucumber/cleanup_formatter.rb create mode 100644 lib/cuke-pack.rb create mode 100644 lib/cuke-pack/support/failfast.rb create mode 100644 lib/cuke-pack/support/flay.rb create mode 100644 lib/cuke-pack/support/pause.rb create mode 100644 lib/cuke-pack/support/pending.rb create mode 100644 lib/cuke-pack/support/step_writer.rb create mode 100644 lib/cuke-pack/support/wait_for.rb create mode 100644 lib/cuke-pack/version.rb create mode 100644 skel/config/cucumber.yml create mode 100644 skel/features/support/cuke-pack.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1429c36 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in cuke-pack.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87b491e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 John Bintz + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef0be69 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Cuke::Pack + +TODO: Write a gem description + +## Installation + +Add this line to your application's Gemfile: + + gem 'cuke-pack' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install cuke-pack + +## Usage + +TODO: Write usage instructions here + +## Contributing + +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/Rakefile b/Rakefile new file mode 100644 index 0000000..f57ae68 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/bin/cuke-pack b/bin/cuke-pack new file mode 100755 index 0000000..d634769 --- /dev/null +++ b/bin/cuke-pack @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby + +require 'thor' + +module CukePack + class CLI < Thor + include Thor::Actions + + def self.source_root + File.expand_path('../../skel', __FILE__) + end + + desc "install", "Install CukePack into the current directory" + def install + directory '.', '.' + end + + default_task :install + end +end + +CukePack::CLI.start + diff --git a/cuke-pack.gemspec b/cuke-pack.gemspec new file mode 100644 index 0000000..9375896 --- /dev/null +++ b/cuke-pack.gemspec @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/cuke-pack/version', __FILE__) + +Gem::Specification.new do |gem| + gem.authors = ["John Bintz"] + gem.email = ["john@coswellproductions.com"] + gem.description = %q{Stuff I use for Cucumber} + gem.summary = %q{Stuff I use for Cucumber} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "cuke-pack" + gem.require_paths = ["lib"] + gem.version = CukePack::VERSION + + gem.add_dependency 'cucumber' + gem.add_dependency 'cucumber-step_writer' + gem.add_dependency 'thor' + gem.add_dependency 'flay' +end + diff --git a/lib/cucumber/cleanup_formatter.rb b/lib/cucumber/cleanup_formatter.rb new file mode 100644 index 0000000..60bbf2f --- /dev/null +++ b/lib/cucumber/cleanup_formatter.rb @@ -0,0 +1,25 @@ +require 'cucumber/formatter/ansicolor' + +module Cucumber + class CleanupFormatter + include Cucumber::Formatter::ANSIColor + + def initialize(step_mother, path_or_io, options) + @step_mother = step_mother + end + + def after_features(features) + defs = @step_mother.unmatched_step_definitions + + if !defs.empty? + $stdout.puts yellow("The following steps are unused:") + $stdout.puts + + defs.each do |step| + $stdout.puts yellow(step.file_colon_line) + end + end + end + end +end + diff --git a/lib/cuke-pack.rb b/lib/cuke-pack.rb new file mode 100644 index 0000000..1be7f66 --- /dev/null +++ b/lib/cuke-pack.rb @@ -0,0 +1,2 @@ +require "cuke-pack/version" +require 'cucumber/cleanup_formatter' diff --git a/lib/cuke-pack/support/failfast.rb b/lib/cuke-pack/support/failfast.rb new file mode 100644 index 0000000..8f1721d --- /dev/null +++ b/lib/cuke-pack/support/failfast.rb @@ -0,0 +1,7 @@ +After do |scenario| + if ENV['FAILFAST'] && scenario.failed? + $stderr.puts "Test failed, quitting..." + + Cucumber.wants_to_quit = true + end +end diff --git a/lib/cuke-pack/support/flay.rb b/lib/cuke-pack/support/flay.rb new file mode 100644 index 0000000..14a8183 --- /dev/null +++ b/lib/cuke-pack/support/flay.rb @@ -0,0 +1,18 @@ +# run flay on your cucumber steps after a successful run. prevent bloat and +# promote reusability! + +flay_exception = nil +flay_level = 32 if flay_level = nil + # set me to a minimum sane level. don't go nuts refactoring! + # code should be cleaner when you're done, not become spaghetti. + +After do |s| + flay_exception ||= s.exception +end + +at_exit do + if flay_level + system %{flay -m #{flay_level} features/step_definitions/**/*.rb} if !flay_exception + end +end + diff --git a/lib/cuke-pack/support/pause.rb b/lib/cuke-pack/support/pause.rb new file mode 100644 index 0000000..0a772ab --- /dev/null +++ b/lib/cuke-pack/support/pause.rb @@ -0,0 +1,8 @@ +def pause + if @pause_ok + $stdout.puts "Paused. Press [ Return ] to continue." + $stdin.getc + $stdout.puts "Resuming..." + end +end + diff --git a/lib/cuke-pack/support/pending.rb b/lib/cuke-pack/support/pending.rb new file mode 100644 index 0000000..d032b1e --- /dev/null +++ b/lib/cuke-pack/support/pending.rb @@ -0,0 +1,10 @@ +module Cucumber::RbSupport::RbWorld + alias :_pending :pending + + def pending + pause + + _pending + end +end + diff --git a/lib/cuke-pack/support/step_writer.rb b/lib/cuke-pack/support/step_writer.rb new file mode 100644 index 0000000..39a09f8 --- /dev/null +++ b/lib/cuke-pack/support/step_writer.rb @@ -0,0 +1,13 @@ +require 'cucumber/step_writer' + +Cucumber::StepWriter.after_write do |dir| + %w{open xdg-open}.each do |cmd| + %x{which #{cmd}} + + if $?.exitstatus + system %{#{cmd} #{dir}} + break + end + end +end + diff --git a/lib/cuke-pack/support/wait_for.rb b/lib/cuke-pack/support/wait_for.rb new file mode 100644 index 0000000..181382b --- /dev/null +++ b/lib/cuke-pack/support/wait_for.rb @@ -0,0 +1,48 @@ +MAX_TIMES = 20 +WAIT_TIME = 0.1 + +def wait_for(times = MAX_TIMES) + 1.upto(times) do + ok = false + + begin + ok = yield + rescue Capybara::ElementNotFound, Capybara::Driver::Webkit::Node::ElementNotDisplayedError + ok = false + end + + if ok + return + else + sleep WAIT_TIME + end + end + + raise StandardError.new("Failed") +end + +def wait_for_not(times = MAX_TIMES) + original_time = Capybara.default_wait_time + Capybara.default_wait_time = 0 + + 1.upto(times) do + ok = false + + begin + yield + rescue Capybara::Driver::Webkit::NodeNotAttachedError, Capybara::ElementNotFound + ok = true + end + + if ok + Capybara.default_wait_time = original_time + + return + else + sleep WAIT_TIME + end + end + + raise StandardError.new('Timed out') +end + diff --git a/lib/cuke-pack/version.rb b/lib/cuke-pack/version.rb new file mode 100644 index 0000000..1fff857 --- /dev/null +++ b/lib/cuke-pack/version.rb @@ -0,0 +1,3 @@ +module CukePack + VERSION = "0.0.1" +end diff --git a/skel/config/cucumber.yml b/skel/config/cucumber.yml new file mode 100644 index 0000000..cd59005 --- /dev/null +++ b/skel/config/cucumber.yml @@ -0,0 +1,8 @@ +<% +std_opts = "-r features --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} -f Cucumber::StepWriter --out features/step_definitions --strict" +%> +default: <%= std_opts %> features +wip: <%= std_opts %> --tags @wip features +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 new file mode 100644 index 0000000..b9d9998 --- /dev/null +++ b/skel/features/support/cuke-pack.rb @@ -0,0 +1,20 @@ +require 'cuke-pack/support/pause' +require 'cuke-pack/support/pending' + +Before do + # if you want pending steps to pause before marking the step as pending, + # set @pause_ok to true + + @pause_ok = false +end + +require 'cuke-pack/support/step_writer' +require 'cuke-pack/support/wait_for' +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' +