cuke-pack/bin/cuke-pack

90 lines
1.7 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'thor'
require 'builder'
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
desc "wip-guard", "Add the WIP guard to your Guardfile"
def wip_guard
FileUtils.touch 'Guardfile'
append_file 'Guardfile', <<-RB
# added by cuke-pack
group :wip do
guard 'cucumber', :env => :cucumber, :cli => '-p wip' do
watch(%r{^features/.+\.feature$})
watch(%r{^(app|lib).*}) { 'features' }
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)\.rb$}) { 'features' }
end
end
RB
end
desc "screenshots DIR", "Start a screenshot server"
method_options %w{port -p} => 4432
def screenshots(dir = "features/screenshots")
require 'rack'
Rack::Handler.default.run(ScreenshotsApp.new(dir), :Port => options[:port])
end
default_task :install
end
end
class ScreenshotsApp
def initialize(dir)
@dir = dir
end
def call(env)
by_file = {}
Dir[@dir + '/**/*.png'].each do |file|
file = file.gsub(%r{^#{@dir}/}, '')
parts = file.split('/')
browser = parts.shift
name = parts.join('/')
by_file[name] ||= []
by_file[name] << browser
end
output = Builder::XmlMarkup.new
output.html {
output.head {
output.title("Screenshots")
}
output.body {
by_file.each do |name, browsers|
end
}
}
[ 200, {}, [ output.to_s ] ]
end
end
CukePack::CLI.start