initial stuff

This commit is contained in:
John Bintz 2012-04-25 09:29:52 -04:00
commit a9d5f05c48
18 changed files with 282 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -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

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in cuke-pack.gemspec
gemspec

22
LICENSE Normal file
View File

@ -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.

29
README.md Normal file
View File

@ -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

2
Rakefile Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"

23
bin/cuke-pack Executable file
View File

@ -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

23
cuke-pack.gemspec Normal file
View File

@ -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

View File

@ -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

2
lib/cuke-pack.rb Normal file
View File

@ -0,0 +1,2 @@
require "cuke-pack/version"
require 'cucumber/cleanup_formatter'

View File

@ -0,0 +1,7 @@
After do |scenario|
if ENV['FAILFAST'] && scenario.failed?
$stderr.puts "Test failed, quitting..."
Cucumber.wants_to_quit = true
end
end

View File

@ -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

View File

@ -0,0 +1,8 @@
def pause
if @pause_ok
$stdout.puts "Paused. Press [ Return ] to continue."
$stdin.getc
$stdout.puts "Resuming..."
end
end

View File

@ -0,0 +1,10 @@
module Cucumber::RbSupport::RbWorld
alias :_pending :pending
def pending
pause
_pending
end
end

View File

@ -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

View File

@ -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

3
lib/cuke-pack/version.rb Normal file
View File

@ -0,0 +1,3 @@
module CukePack
VERSION = "0.0.1"
end

8
skel/config/cucumber.yml Normal file
View File

@ -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

View File

@ -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'