cucumber 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +152 -0
- data/README.txt +42 -0
- data/Rakefile +4 -0
- data/TODO.txt +26 -0
- data/bin/cucumber +4 -0
- data/config/hoe.rb +69 -0
- data/config/requirements.rb +15 -0
- data/cucumber.yml +1 -0
- data/examples/calculator/Rakefile +6 -0
- data/examples/calculator/cucumber.yml +1 -0
- data/examples/calculator/features/addition.feature +16 -0
- data/examples/calculator/features/division.feature +10 -0
- data/examples/calculator/features/steps/calculator_steps.rb +31 -0
- data/examples/calculator/lib/calculator.rb +16 -0
- data/examples/calculator_ruby_features/Rakefile +6 -0
- data/examples/calculator_ruby_features/features/addition.rb +23 -0
- data/examples/calculator_ruby_features/features/steps/calculator_steps.rb +43 -0
- data/examples/calculatrice_francaise_avec_soit_scenario/Rakefile +6 -0
- data/examples/calculatrice_francaise_avec_soit_scenario/features/addition.feature +13 -0
- data/examples/calculatrice_francaise_avec_soit_scenario/features/calculatrice_steps.rb +31 -0
- data/examples/cs/README.textile +22 -0
- data/examples/cs/Rakefile +12 -0
- data/examples/cs/features/hello.feature +11 -0
- data/examples/cs/features/steps/hello_steps.rb +25 -0
- data/examples/cs/features/steps/tree_steps.rb +14 -0
- data/examples/cs/features/tree.feature +9 -0
- data/examples/cs/src/Hello.cs +18 -0
- data/examples/danish_calculator/Rakefile +6 -0
- data/examples/danish_calculator/features/steps/kalkulator_steps.rb +22 -0
- data/examples/danish_calculator/features/summering.feature +17 -0
- data/examples/danish_calculator/lib/kalkulator.rb +11 -0
- data/examples/estonian_calculator/Rakefile +6 -0
- data/examples/estonian_calculator/features/kalkulaator_steps.rb +35 -0
- data/examples/estonian_calculator/features/liitmine.feature +16 -0
- data/examples/java/README.textile +22 -0
- data/examples/java/Rakefile +12 -0
- data/examples/java/features/hello.feature +11 -0
- data/examples/java/features/steps/hello_steps.rb +25 -0
- data/examples/java/features/steps/tree_steps.rb +14 -0
- data/examples/java/features/tree.feature +9 -0
- data/examples/java/src/cucumber/demo/Hello.java +16 -0
- data/examples/norwegian_calculator/Rakefile +6 -0
- data/examples/norwegian_calculator/features/steps/kalkulator_steps.rb +22 -0
- data/examples/norwegian_calculator/features/summering.feature +17 -0
- data/examples/norwegian_calculator/lib/kalkulator.rb +11 -0
- data/examples/portuguese_calculator/Rakefile +6 -0
- data/examples/portuguese_calculator/features/adicao.feature +10 -0
- data/examples/portuguese_calculator/features/calculadora_steps.rb +31 -0
- data/examples/selenium/Rakefile +6 -0
- data/examples/selenium/features/search.feature +9 -0
- data/examples/selenium/features/steps/stories_steps.rb +41 -0
- data/examples/spanish_calculator/Rakefile +6 -0
- data/examples/spanish_calculator/features/adicion.feature +17 -0
- data/examples/spanish_calculator/features/steps/calculador_steps.rb +22 -0
- data/examples/spanish_calculator/lib/Calculador.rb +11 -0
- data/examples/tickets/Rakefile +4 -0
- data/examples/tickets/features/steps/tickets_steps.rb +5 -0
- data/examples/tickets/features/tickets.feature +7 -0
- data/examples/watir/Rakefile +6 -0
- data/examples/watir/features/search.feature +9 -0
- data/examples/watir/features/steps/stories_steps.rb +51 -0
- data/features/see_features.feature +8 -0
- data/features/steps/features_steps.rb +9 -0
- data/gem_tasks/deployment.rake +34 -0
- data/gem_tasks/environment.rake +7 -0
- data/gem_tasks/features.rake +6 -0
- data/gem_tasks/fix_cr_lf.rake +10 -0
- data/gem_tasks/flog.rake +4 -0
- data/gem_tasks/gemspec.rake +6 -0
- data/gem_tasks/rspec.rake +21 -0
- data/gem_tasks/treetop.rake +27 -0
- data/generators/cucumber/cucumber_generator.rb +27 -0
- data/generators/cucumber/templates/common_webrat.rb +51 -0
- data/generators/cucumber/templates/cucumber +2 -0
- data/generators/cucumber/templates/cucumber.rake +7 -0
- data/generators/cucumber/templates/env.rb +8 -0
- data/generators/feature/feature_generator.rb +17 -0
- data/generators/feature/templates/feature.erb +27 -0
- data/generators/feature/templates/steps.erb +22 -0
- data/lib/cucumber.rb +32 -0
- data/lib/cucumber/cli.rb +163 -0
- data/lib/cucumber/core_ext/proc.rb +43 -0
- data/lib/cucumber/core_ext/string.rb +22 -0
- data/lib/cucumber/executor.rb +120 -0
- data/lib/cucumber/formatters.rb +1 -0
- data/lib/cucumber/formatters/ansicolor.rb +90 -0
- data/lib/cucumber/formatters/cucumber.css +132 -0
- data/lib/cucumber/formatters/cucumber.js +11 -0
- data/lib/cucumber/formatters/html_formatter.rb +125 -0
- data/lib/cucumber/formatters/jquery.js +32 -0
- data/lib/cucumber/formatters/pretty_formatter.rb +126 -0
- data/lib/cucumber/formatters/progress_formatter.rb +42 -0
- data/lib/cucumber/languages.yml +83 -0
- data/lib/cucumber/rails/rspec.rb +12 -0
- data/lib/cucumber/rails/world.rb +75 -0
- data/lib/cucumber/rake/task.rb +75 -0
- data/lib/cucumber/step_methods.rb +45 -0
- data/lib/cucumber/step_mother.rb +82 -0
- data/lib/cucumber/tree.rb +18 -0
- data/lib/cucumber/tree/feature.rb +53 -0
- data/lib/cucumber/tree/features.rb +21 -0
- data/lib/cucumber/tree/given_scenario.rb +13 -0
- data/lib/cucumber/tree/scenario.rb +110 -0
- data/lib/cucumber/tree/step.rb +123 -0
- data/lib/cucumber/tree/table.rb +26 -0
- data/lib/cucumber/tree/top_down_visitor.rb +23 -0
- data/lib/cucumber/treetop_parser/feature.treetop.erb +159 -0
- data/lib/cucumber/treetop_parser/feature_da.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_de.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_en.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_es.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_et.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_fr.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_no.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_parser.rb +32 -0
- data/lib/cucumber/treetop_parser/feature_pt.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_ru.rb +1214 -0
- data/lib/cucumber/treetop_parser/feature_se.rb +1214 -0
- data/lib/cucumber/version.rb +9 -0
- data/script/console +10 -0
- data/script/console.cmd +1 -0
- data/script/destroy +14 -0
- data/script/destroy.cmd +1 -0
- data/script/generate +14 -0
- data/script/generate.cmd +1 -0
- data/script/txt2html +74 -0
- data/script/txt2html.cmd +1 -0
- data/setup.rb +1585 -0
- data/spec/cucumber/cli_spec.rb +36 -0
- data/spec/cucumber/core_ext/proc_spec.rb +39 -0
- data/spec/cucumber/core_ext/string_spec.rb +34 -0
- data/spec/cucumber/executor_spec.rb +131 -0
- data/spec/cucumber/formatters/ansicolor_spec.rb +23 -0
- data/spec/cucumber/formatters/features.html +269 -0
- data/spec/cucumber/formatters/html_formatter_spec.rb +59 -0
- data/spec/cucumber/formatters/pretty_formatter_spec.rb +17 -0
- data/spec/cucumber/formatters/progress_formatter_spec.rb +44 -0
- data/spec/cucumber/sell_cucumbers.feature +9 -0
- data/spec/cucumber/step_mother_spec.rb +53 -0
- data/spec/cucumber/tree/scenario_spec.rb +15 -0
- data/spec/cucumber/treetop_parser/empty_feature.feature +4 -0
- data/spec/cucumber/treetop_parser/empty_scenario.feature +9 -0
- data/spec/cucumber/treetop_parser/feature_parser_spec.rb +73 -0
- data/spec/cucumber/treetop_parser/fit_scenario.feature +7 -0
- data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
- data/spec/cucumber/treetop_parser/multiple_tables.feature +27 -0
- data/spec/cucumber/treetop_parser/spaces.feature +10 -0
- data/spec/cucumber/treetop_parser/with_comments.feature +6 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +23 -0
- metadata +259 -0
data/gem_tasks/flog.rake
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'spec'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'spec'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'spec/rake/spectask'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
puts <<-EOS
|
|
11
|
+
To use rspec for testing you must install rspec gem:
|
|
12
|
+
gem install rspec
|
|
13
|
+
EOS
|
|
14
|
+
exit(0)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Run the specs under spec/models"
|
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class FeatureCompiler
|
|
2
|
+
def compile
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require 'erb'
|
|
5
|
+
tt = PLATFORM =~ /mswin|mingw/ ? 'tt.bat' : 'tt'
|
|
6
|
+
|
|
7
|
+
template = ERB.new(IO.read(File.dirname(__FILE__) + '/../lib/cucumber/treetop_parser/feature.treetop.erb'))
|
|
8
|
+
langs = YAML.load_file(File.dirname(__FILE__) + '/../lib/cucumber/languages.yml')
|
|
9
|
+
|
|
10
|
+
langs.each do |lang, words|
|
|
11
|
+
grammar_file = File.dirname(__FILE__) + "/../lib/cucumber/treetop_parser/feature_#{lang}.treetop"
|
|
12
|
+
grammar = template.result(binding)
|
|
13
|
+
File.open(grammar_file, "wb") do |io|
|
|
14
|
+
io.write(grammar)
|
|
15
|
+
end
|
|
16
|
+
sh "#{tt} #{grammar_file}"
|
|
17
|
+
FileUtils.rm(grammar_file)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
namespace :treetop do
|
|
23
|
+
desc 'Compile the grammar for all languages in languages.yml'
|
|
24
|
+
task :compile do
|
|
25
|
+
FeatureCompiler.new.compile
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
|
|
3
|
+
# This generator bootstraps a Rails project for use with Cucumber
|
|
4
|
+
class CucumberGenerator < Rails::Generator::Base
|
|
5
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
|
6
|
+
Config::CONFIG['ruby_install_name'])
|
|
7
|
+
def manifest
|
|
8
|
+
record do |m|
|
|
9
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
|
10
|
+
|
|
11
|
+
m.directory 'features/steps'
|
|
12
|
+
m.file 'env.rb', 'features/steps/env.rb'
|
|
13
|
+
m.file 'common_webrat.rb', 'features/steps/common_webrat.rb'
|
|
14
|
+
|
|
15
|
+
m.directory 'lib/tasks'
|
|
16
|
+
m.file 'cucumber.rake', 'lib/tasks/cucumber.rake'
|
|
17
|
+
m.file 'cucumber', 'script/cucumber', script_options
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def banner
|
|
24
|
+
"Usage: #{$0} cucumber"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Commonly used webrat steps
|
|
2
|
+
# http://github.com/brynary/webrat
|
|
3
|
+
|
|
4
|
+
When /^I press "(.*)"$/ do |button|
|
|
5
|
+
clicks_button(button)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
When /^I follow "(.*)"$/ do |link|
|
|
9
|
+
clicks_link(link)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
|
|
13
|
+
fills_in(field, :with => value)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
When /^I select "(.*)" from "(.*)"$/ do |field, value|
|
|
17
|
+
selects(field, :with => value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
When /^I check "(.*)"$/ do |field|
|
|
21
|
+
checks(field)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
When /^I uncheck "(.*)"$/ do |field|
|
|
25
|
+
unchecks(field)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
When /^I choose "(.*)"$/ do |field|
|
|
29
|
+
chooses(field)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
|
|
33
|
+
attaches_file(field, path)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
When /^I go to (.*)$/ do |page|
|
|
37
|
+
visits case page
|
|
38
|
+
when "the home page"
|
|
39
|
+
"/"
|
|
40
|
+
else
|
|
41
|
+
raise "Can't find mapping from \"#{page}\" to a path"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
Then /^I should see "(.*)"$/ do |text|
|
|
46
|
+
response.body.should =~ /#{text}/m
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Then /^I should not see "(.*)"$/ do |text|
|
|
50
|
+
response.body.should_not =~ /#{text}/m
|
|
51
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
|
|
4
|
+
require 'cucumber/rails/world'
|
|
5
|
+
Cucumber::Rails.use_transactional_fixtures
|
|
6
|
+
|
|
7
|
+
# Comment out the next line if you're not using RSpec's matchers (should / should_not) in your steps.
|
|
8
|
+
require 'cucumber/rails/rspec'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This generator bootstraps a Rails project for use with Cucumber
|
|
2
|
+
class FeatureGenerator < Rails::Generator::NamedBase
|
|
3
|
+
def manifest
|
|
4
|
+
record do |m|
|
|
5
|
+
m.directory 'features/steps'
|
|
6
|
+
m.template 'feature.erb', "features/manage_#{plural_name}.feature"
|
|
7
|
+
m.template 'steps.erb', "features/steps/#{singular_name}_steps.rb"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
protected
|
|
12
|
+
|
|
13
|
+
def banner
|
|
14
|
+
"Usage: #{$0} cucumber"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Feature: Manage <%= plural_name %>
|
|
2
|
+
In order to keep track of <%= plural_name %>
|
|
3
|
+
A <%= singular_name %> mechanic
|
|
4
|
+
Should be able to manage several <%= plural_name %>
|
|
5
|
+
|
|
6
|
+
Scenario: Register new <%= singular_name %>
|
|
7
|
+
Given I am on the new <%= singular_name %> page
|
|
8
|
+
<% keyword = 'When' -%>
|
|
9
|
+
<% args.each do |arg| -%>
|
|
10
|
+
<%= keyword %> I fill in "<%= arg.humanize %>" with "My <%= singular_name %> <%= arg %>"
|
|
11
|
+
<% keyword = 'And' -%>
|
|
12
|
+
<% end -%>
|
|
13
|
+
And I press "Create"
|
|
14
|
+
<% keyword = 'Then' -%>
|
|
15
|
+
<% args.each do |arg| -%>
|
|
16
|
+
<%= keyword %> I should see "My <%= singular_name %> <%= arg %>"
|
|
17
|
+
<% keyword = 'And' -%>
|
|
18
|
+
<% end -%>
|
|
19
|
+
|
|
20
|
+
Scenario: Delete <%= singular_name %>
|
|
21
|
+
Given there are 4 <%= plural_name %>
|
|
22
|
+
When I delete the first <%= singular_name %>
|
|
23
|
+
Then there should be 3 <%= plural_name %> left
|
|
24
|
+
|
|
25
|
+
| initial | after |
|
|
26
|
+
| 100 | 99 |
|
|
27
|
+
| 1 | 0 |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Given /I am on the new <%= singular_name %> page/ do
|
|
2
|
+
visits "/<%= plural_name %>/new"
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
Given /there are (\d+) <%= plural_name %>/ do |n|
|
|
6
|
+
<%= class_name %>.transaction do
|
|
7
|
+
<%= class_name %>.destroy_all
|
|
8
|
+
n.to_i.times do |n|
|
|
9
|
+
<%= class_name %>.create! :name => "<%= class_name %> #{n}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
When /I delete the first <%= singular_name %>/ do
|
|
15
|
+
visits <%= plural_name %>_url
|
|
16
|
+
clicks_link "Destroy"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Then /there should be (\d+) <%= plural_name %> left/ do |n|
|
|
20
|
+
<%= class_name %>.count.should == n.to_i
|
|
21
|
+
response.should have_tag("table tr", n.to_i + 1) # There is a header row too
|
|
22
|
+
end
|
data/lib/cucumber.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'treetop/runtime'
|
|
5
|
+
require 'treetop/ruby_extensions'
|
|
6
|
+
require 'cucumber/version'
|
|
7
|
+
require 'cucumber/step_methods'
|
|
8
|
+
require 'cucumber/tree'
|
|
9
|
+
require 'cucumber/executor'
|
|
10
|
+
require 'cucumber/step_mother'
|
|
11
|
+
require 'cucumber/formatters'
|
|
12
|
+
require 'cucumber/treetop_parser/feature_parser'
|
|
13
|
+
require 'cucumber/cli'
|
|
14
|
+
|
|
15
|
+
module Cucumber
|
|
16
|
+
class << self
|
|
17
|
+
attr_reader :language
|
|
18
|
+
|
|
19
|
+
def load_language(lang)
|
|
20
|
+
@language = config[lang]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def languages
|
|
24
|
+
config.keys.sort
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def config
|
|
28
|
+
require 'yaml'
|
|
29
|
+
@config ||= YAML.load_file(File.dirname(__FILE__) + '/cucumber/languages.yml')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/cucumber/cli.rb
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
require 'cucumber'
|
|
3
|
+
|
|
4
|
+
module Cucumber
|
|
5
|
+
class CLI
|
|
6
|
+
class << self
|
|
7
|
+
attr_writer :step_mother, :features
|
|
8
|
+
|
|
9
|
+
def execute
|
|
10
|
+
@execute_called = true
|
|
11
|
+
parse(ARGV).execute!(@step_mother, @features)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def execute_called?
|
|
15
|
+
@execute_called
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def parse(args)
|
|
19
|
+
cli = new
|
|
20
|
+
cli.parse_options!(args)
|
|
21
|
+
cli
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
attr_reader :options
|
|
26
|
+
FORMATS = %w{pretty progress html}
|
|
27
|
+
|
|
28
|
+
def initialize
|
|
29
|
+
@paths = []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def parse_options!(args)
|
|
33
|
+
return parse_args_from_profile('default') if args.empty?
|
|
34
|
+
args.extend(OptionParser::Arguable)
|
|
35
|
+
|
|
36
|
+
@options = { :require => nil, :lang => 'en', :format => 'pretty', :dry_run => false }
|
|
37
|
+
args.options do |opts|
|
|
38
|
+
opts.banner = "Usage: cucumber [options] FILES|DIRS"
|
|
39
|
+
opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", "Require files before executing the features.",
|
|
40
|
+
"If this option is not specified, all *.rb files that",
|
|
41
|
+
"are siblings or below the features will be autorequired") do |v|
|
|
42
|
+
@options[:require] ||= []
|
|
43
|
+
@options[:require] << v
|
|
44
|
+
end
|
|
45
|
+
opts.on("-l LINE", "--line LINE", "Only execute the scenario at the given line") do |v|
|
|
46
|
+
@options[:line] = v
|
|
47
|
+
end
|
|
48
|
+
opts.on("-a LANG", "--language LANG", "Specify language for features (Default: #{@options[:lang]})",
|
|
49
|
+
"Available languages: #{Cucumber.languages.join(", ")}") do |v|
|
|
50
|
+
@options[:lang] = v
|
|
51
|
+
end
|
|
52
|
+
opts.on("-f FORMAT", "--format FORMAT", "How to format features (Default: #{@options[:format]})",
|
|
53
|
+
"Available formats: #{FORMATS.join(", ")}") do |v|
|
|
54
|
+
unless FORMATS.index(v)
|
|
55
|
+
STDERR.puts "Invalid format: #{v}\n"
|
|
56
|
+
STDERR.puts opts.help
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
59
|
+
@options[:format] = v
|
|
60
|
+
end
|
|
61
|
+
opts.on("-p=PROFILE", "--profile=PROFILE", "Pull commandline arguments from cucumber.yml.") do |v|
|
|
62
|
+
parse_args_from_profile(v)
|
|
63
|
+
end
|
|
64
|
+
opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.") do
|
|
65
|
+
@options[:dry_run] = true
|
|
66
|
+
end
|
|
67
|
+
opts.on_tail("--version", "Show version") do
|
|
68
|
+
puts VERSION::STRING
|
|
69
|
+
exit
|
|
70
|
+
end
|
|
71
|
+
opts.on_tail("--help", "You're looking at it") do
|
|
72
|
+
puts opts.help
|
|
73
|
+
exit
|
|
74
|
+
end
|
|
75
|
+
end.parse!
|
|
76
|
+
|
|
77
|
+
# Whatever is left after option parsing is the FILE arguments
|
|
78
|
+
@paths += args
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def parse_args_from_profile(profile)
|
|
82
|
+
require 'yaml'
|
|
83
|
+
cucumber_yml = YAML::load(IO.read('cucumber.yml'))
|
|
84
|
+
args_from_yml = cucumber_yml[profile]
|
|
85
|
+
raise "Expected to find a String, got #{args_from_yml.inspect}. cucumber.yml:\n#{cucumber_yml}" unless String === args_from_yml
|
|
86
|
+
parse_options!(args_from_yml.split(' '))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def execute!(step_mother, features)
|
|
90
|
+
Cucumber.load_language(@options[:lang])
|
|
91
|
+
$executor = Executor.new(formatter(step_mother), step_mother)
|
|
92
|
+
require_files
|
|
93
|
+
load_plain_text_features(features)
|
|
94
|
+
$executor.line = @options[:line].to_i if @options[:line]
|
|
95
|
+
$executor.visit_features(features)
|
|
96
|
+
exit 1 if $executor.failed
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
# Requires files - typically step files and ruby feature files.
|
|
102
|
+
def require_files
|
|
103
|
+
ARGV.clear # Shut up RSpec
|
|
104
|
+
require "cucumber/treetop_parser/feature_#{@options[:lang]}"
|
|
105
|
+
require "cucumber/treetop_parser/feature_parser"
|
|
106
|
+
|
|
107
|
+
requires = @options[:require] || feature_dirs
|
|
108
|
+
libs = requires.map do |path|
|
|
109
|
+
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
|
|
110
|
+
File.directory?(path) ? Dir["#{path}/**/*.rb"] : path
|
|
111
|
+
end.flatten.uniq
|
|
112
|
+
libs.each do |lib|
|
|
113
|
+
begin
|
|
114
|
+
require lib
|
|
115
|
+
rescue LoadError => e
|
|
116
|
+
e.message << "\nFailed to load #{lib}"
|
|
117
|
+
raise e
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def feature_files
|
|
123
|
+
@paths.map do |path|
|
|
124
|
+
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
|
|
125
|
+
File.directory?(path) ? Dir["#{path}/**/*.feature"] : path
|
|
126
|
+
end.flatten.uniq
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def feature_dirs
|
|
130
|
+
feature_files.map{|f| File.directory?(f) ? f : File.dirname(f)}.uniq
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def load_plain_text_features(features)
|
|
134
|
+
parser = TreetopParser::FeatureParser.new
|
|
135
|
+
|
|
136
|
+
feature_files.each do |f|
|
|
137
|
+
features << parser.parse_feature(f)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def formatter(step_mother)
|
|
142
|
+
case @options[:format]
|
|
143
|
+
when 'pretty'
|
|
144
|
+
Formatters::PrettyFormatter.new(STDOUT)
|
|
145
|
+
when 'progress'
|
|
146
|
+
Formatters::ProgressFormatter.new(STDOUT)
|
|
147
|
+
when 'html'
|
|
148
|
+
Formatters::HtmlFormatter.new(STDOUT, step_mother)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
extend Cucumber::StepMethods
|
|
156
|
+
Cucumber::CLI.step_mother = step_mother
|
|
157
|
+
|
|
158
|
+
extend(Cucumber::Tree)
|
|
159
|
+
Cucumber::CLI.features = features
|
|
160
|
+
|
|
161
|
+
at_exit do
|
|
162
|
+
Cucumber::CLI.execute unless Cucumber::CLI.execute_called?
|
|
163
|
+
end
|