aslakhellesoy-cucumber 0.1.99.4 → 0.1.99.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -1
- data/Manifest.txt +2 -10
- data/cucumber.yml +1 -0
- data/examples/cs/README.textile +1 -0
- data/examples/cs/Rakefile +12 -0
- data/examples/cs/compile.bat +1 -0
- data/examples/cs/features/addition.feature +16 -0
- data/examples/cs/features/step_definitons/calculator_steps.rb +19 -0
- data/examples/cs/src/demo/Calculator.cs +20 -0
- data/examples/dos_line_endings/Rakefile +6 -0
- data/examples/dos_line_endings/features/dos_line_endings.feature +9 -0
- data/examples/i18n/README.textile +18 -0
- data/examples/i18n/Rakefile +32 -0
- data/examples/i18n/ar/Rakefile +6 -0
- data/examples/i18n/ar/features/addition.feature +17 -0
- data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +28 -0
- data/examples/i18n/ar/lib/calculator.rb +10 -0
- data/examples/i18n/da/Rakefile +6 -0
- data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +24 -0
- data/examples/i18n/da/features/summering.feature +17 -0
- data/examples/i18n/da/lib/kalkulator.rb +11 -0
- data/examples/i18n/de/Rakefile +6 -0
- data/examples/i18n/de/features/addition.feature +16 -0
- data/examples/i18n/de/features/division.feature +9 -0
- data/examples/i18n/de/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/de/lib/calculator.rb +14 -0
- data/examples/i18n/en/Rakefile +6 -0
- data/examples/i18n/en/features/addition.feature +16 -0
- data/examples/i18n/en/features/division.feature +9 -0
- data/examples/i18n/en/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/en/lib/calculator.rb +14 -0
- data/examples/i18n/es/Rakefile +6 -0
- data/examples/i18n/es/features/adicion.feature +17 -0
- data/examples/i18n/es/features/step_definitons/calculador_steps.rb +24 -0
- data/examples/i18n/es/lib/calculador.rb +11 -0
- data/examples/i18n/et/Rakefile +6 -0
- data/examples/i18n/et/features/liitmine.feature +17 -0
- data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +24 -0
- data/examples/i18n/et/lib/kalkulaator.rb +10 -0
- data/examples/i18n/fi/Rakefile +6 -0
- data/examples/i18n/fi/features/jakolasku.feature +9 -0
- data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +24 -0
- data/examples/i18n/fi/features/yhteenlasku.feature +16 -0
- data/examples/i18n/fi/lib/laskin.rb +14 -0
- data/examples/i18n/fr/Rakefile +6 -0
- data/examples/i18n/fr/features/addition.feature +15 -0
- data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +27 -0
- data/examples/i18n/fr/lib/calculatrice.rb +10 -0
- data/examples/i18n/id/Rakefile +6 -0
- data/examples/i18n/id/features/addition.feature +16 -0
- data/examples/i18n/id/features/division.feature +9 -0
- data/examples/i18n/id/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/id/lib/calculator.rb +14 -0
- data/examples/i18n/it/Rakefile +6 -0
- data/examples/i18n/it/features/somma.feature +10 -0
- data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +24 -0
- data/examples/i18n/it/lib/calcolatrice.rb +11 -0
- data/examples/i18n/ja/README.txt +5 -0
- data/examples/i18n/ja/Rakefile +6 -0
- data/examples/i18n/ja/features/addition.feature +16 -0
- data/examples/i18n/ja/features/division.feature +9 -0
- data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/ja/lib/calculator.rb +14 -0
- data/examples/i18n/ko/Rakefile +6 -0
- data/examples/i18n/ko/features/addition.feature +16 -0
- data/examples/i18n/ko/features/division.feature +10 -0
- data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/ko/lib/calculator.rb +14 -0
- data/examples/i18n/lt/Rakefile +6 -0
- data/examples/i18n/lt/features/addition.feature +17 -0
- data/examples/i18n/lt/features/division.feature +9 -0
- data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/lt/lib/calculator.rb +14 -0
- data/examples/i18n/no/Rakefile +6 -0
- data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +24 -0
- data/examples/i18n/no/features/summering.feature +18 -0
- data/examples/i18n/no/lib/kalkulator.rb +11 -0
- data/examples/i18n/pt/Rakefile +6 -0
- data/examples/i18n/pt/features/adicao.feature +10 -0
- data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +24 -0
- data/examples/i18n/pt/lib/calculadora.rb +10 -0
- data/examples/i18n/ro/Rakefile +6 -0
- data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/ro/features/suma.feature +10 -0
- data/examples/i18n/ro/lib/calculator.rb +11 -0
- data/examples/i18n/se/Rakefile +6 -0
- data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +24 -0
- data/examples/i18n/se/features/summering.feature +17 -0
- data/examples/i18n/se/lib/kalkulator.rb +11 -0
- data/examples/i18n/zh-CN/Rakefile +6 -0
- data/examples/i18n/zh-CN/features/addition.feature +17 -0
- data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +26 -0
- data/examples/i18n/zh-CN/lib/calculator.rb +10 -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/step_definitons/hello_steps.rb +25 -0
- data/examples/java/features/step_definitons/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/jbehave/README.textile +17 -0
- data/examples/jbehave/features/support/env.rb +7 -0
- data/examples/jbehave/features/trading.feature +24 -0
- data/examples/jbehave/pom.xml +48 -0
- data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/converters/TraderConverter.java +32 -0
- data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Stock.java +42 -0
- data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Trader.java +29 -0
- data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/persistence/TraderPersister.java +22 -0
- data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/scenarios/TraderSteps.java +65 -0
- data/examples/selenium/Rakefile +6 -0
- data/examples/selenium/features/search.feature +9 -0
- data/examples/selenium/features/step_definitons/stories_steps.rb +40 -0
- data/examples/self_test/README.textile +6 -0
- data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
- data/examples/self_test/features/lots_of_undefined.feature +8 -0
- data/examples/self_test/features/outline_sample.feature +15 -0
- data/examples/self_test/features/sample.feature +16 -0
- data/examples/self_test/features/step_definitions/sample_steps.rb +25 -0
- data/examples/test_unit/Rakefile +6 -0
- data/examples/test_unit/features/step_definitions/test_unit_steps.rb +26 -0
- data/examples/test_unit/features/test_unit.feature +9 -0
- data/examples/tickets/Rakefile +11 -0
- data/examples/tickets/cucumber.yml +2 -0
- data/examples/tickets/features/lib/eatting_machine.rb +18 -0
- data/examples/tickets/features/lib/pantry.rb +20 -0
- data/examples/tickets/features/scenario_outline.feature +95 -0
- data/examples/tickets/features/step_definitons/scenario_outline_steps.rb +42 -0
- data/examples/tickets/features/step_definitons/tickets_steps.rb +60 -0
- data/examples/tickets/features/tickets.feature +28 -0
- data/examples/watir/README.textile +16 -0
- data/examples/watir/Rakefile +6 -0
- data/examples/watir/features/search.feature +9 -0
- data/examples/watir/features/step_definitons/search_steps.rb +24 -0
- data/examples/watir/features/support/env.rb +32 -0
- data/features/cucumber_cli.feature +331 -0
- data/features/cucumber_cli_outlines.feature +90 -0
- data/features/report_called_undefined_steps.feature +32 -0
- data/features/step_definitions/cucumber_steps.rb +31 -0
- data/features/step_definitions/extra_steps.rb +2 -0
- data/features/support/env.rb +7 -0
- data/gem_tasks/deployment.rake +11 -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 +10 -0
- data/gem_tasks/rspec.rake +35 -0
- data/gem_tasks/yard.rake +8 -0
- data/lib/autotest/cucumber.rb +6 -0
- data/lib/autotest/cucumber_mixin.rb +124 -0
- data/lib/autotest/cucumber_rails.rb +6 -0
- data/lib/autotest/cucumber_rails_rspec.rb +6 -0
- data/lib/autotest/cucumber_rspec.rb +6 -0
- data/lib/autotest/discover.rb +9 -0
- data/lib/cucumber.rb +72 -0
- data/lib/cucumber/ast.rb +27 -0
- data/lib/cucumber/ast/comment.rb +26 -0
- data/lib/cucumber/ast/examples.rb +22 -0
- data/lib/cucumber/ast/feature.rb +60 -0
- data/lib/cucumber/ast/features.rb +39 -0
- data/lib/cucumber/ast/filter.rb +22 -0
- data/lib/cucumber/ast/outline_table.rb +49 -0
- data/lib/cucumber/ast/py_string.rb +52 -0
- data/lib/cucumber/ast/scenario.rb +95 -0
- data/lib/cucumber/ast/scenario_outline.rb +83 -0
- data/lib/cucumber/ast/step.rb +139 -0
- data/lib/cucumber/ast/table.rb +214 -0
- data/lib/cucumber/ast/tags.rb +33 -0
- data/lib/cucumber/ast/visitor.rb +93 -0
- data/lib/cucumber/broadcaster.rb +15 -0
- data/lib/cucumber/cli.rb +414 -0
- data/lib/cucumber/core_ext/exception.rb +53 -0
- data/lib/cucumber/core_ext/instance_exec.rb +54 -0
- data/lib/cucumber/core_ext/proc.rb +33 -0
- data/lib/cucumber/core_ext/string.rb +48 -0
- data/lib/cucumber/formatter.rb +1 -0
- data/lib/cucumber/formatter/ansicolor.rb +106 -0
- data/lib/cucumber/formatter/console.rb +116 -0
- data/lib/cucumber/formatter/pretty.rb +158 -0
- data/lib/cucumber/formatter/profile.rb +77 -0
- data/lib/cucumber/formatter/progress.rb +68 -0
- data/lib/cucumber/formatter/rerun.rb +35 -0
- data/lib/cucumber/formatters/unicode.rb +2 -0
- data/lib/cucumber/jbehave.rb +104 -0
- data/lib/cucumber/languages.yml +314 -0
- data/lib/cucumber/parser.rb +24 -0
- data/lib/cucumber/parser/basic.rb +0 -0
- data/lib/cucumber/parser/feature.rb +1351 -0
- data/lib/cucumber/parser/feature.tt +160 -0
- data/lib/cucumber/parser/i18n.tt +27 -0
- data/lib/cucumber/parser/table.rb +396 -0
- data/lib/cucumber/parser/table.tt +53 -0
- data/lib/cucumber/parser/treetop_ext.rb +67 -0
- data/lib/cucumber/platform.rb +18 -0
- data/lib/cucumber/rails/rspec.rb +5 -0
- data/lib/cucumber/rails/world.rb +73 -0
- data/lib/cucumber/rake/task.rb +106 -0
- data/lib/cucumber/step_definition.rb +87 -0
- data/lib/cucumber/step_mother.rb +164 -0
- data/lib/cucumber/version.rb +10 -0
- data/pretty.txt +486 -0
- data/rails_generators/cucumber/USAGE +11 -0
- data/rails_generators/cucumber/cucumber_generator.rb +31 -0
- data/rails_generators/cucumber/templates/cucumber +8 -0
- data/rails_generators/cucumber/templates/cucumber.rake +7 -0
- data/rails_generators/cucumber/templates/env.rb +16 -0
- data/rails_generators/cucumber/templates/paths.rb +12 -0
- data/rails_generators/cucumber/templates/webrat_steps.rb +99 -0
- data/rails_generators/feature/USAGE +12 -0
- data/rails_generators/feature/feature_generator.rb +36 -0
- data/rails_generators/feature/templates/feature.erb +31 -0
- data/rails_generators/feature/templates/steps.erb +24 -0
- data/spec/cucumber/ast/feature_factory.rb +54 -0
- data/spec/cucumber/ast/feature_spec.rb +60 -0
- data/spec/cucumber/ast/py_string_spec.rb +40 -0
- data/spec/cucumber/ast/scenario_outline_spec.rb +64 -0
- data/spec/cucumber/ast/scenario_spec.rb +82 -0
- data/spec/cucumber/ast/step_spec.rb +45 -0
- data/spec/cucumber/ast/table_spec.rb +81 -0
- data/spec/cucumber/broadcaster_spec.rb +14 -0
- data/spec/cucumber/cli_spec.rb +416 -0
- data/spec/cucumber/core_ext/proc_spec.rb +37 -0
- data/spec/cucumber/core_ext/string_spec.rb +42 -0
- data/spec/cucumber/formatter/ansicolor_spec.rb +35 -0
- data/spec/cucumber/formatter/html/cucumber.css +37 -0
- data/spec/cucumber/formatter/html/cucumber.js +13 -0
- data/spec/cucumber/formatter/html/index.html +45 -0
- data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
- data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
- data/spec/cucumber/formatters/profile_formatter_spec.rb +198 -0
- data/spec/cucumber/parser/feature_parser_spec.rb +247 -0
- data/spec/cucumber/parser/table_parser_spec.rb +48 -0
- data/spec/cucumber/rails/stubs/mini_rails.rb +18 -0
- data/spec/cucumber/rails/stubs/test_help.rb +1 -0
- data/spec/cucumber/rails/world_spec.rb +11 -0
- data/spec/cucumber/sell_cucumbers.feature +19 -0
- data/spec/cucumber/step_definition_spec.rb +62 -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/empty_scenario_outline.feature +3 -0
- data/spec/cucumber/treetop_parser/fit_scenario.feature +8 -0
- data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
- data/spec/cucumber/treetop_parser/invalid_scenario_outlines.feature +7 -0
- data/spec/cucumber/treetop_parser/multiline_steps.feature +17 -0
- data/spec/cucumber/treetop_parser/multiple_tables.feature +27 -0
- data/spec/cucumber/treetop_parser/scenario_outline.feature +16 -0
- data/spec/cucumber/treetop_parser/spaces.feature +12 -0
- data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
- data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
- data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
- data/spec/cucumber/world/pending_spec.rb +47 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +21 -0
- metadata +7 -1
data/lib/cucumber/cli.rb
ADDED
@@ -0,0 +1,414 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'cucumber'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'cucumber/parser'
|
5
|
+
require 'cucumber/formatter'
|
6
|
+
|
7
|
+
module Cucumber
|
8
|
+
class YmlLoadError < StandardError; end
|
9
|
+
|
10
|
+
class CLI
|
11
|
+
class << self
|
12
|
+
def step_mother=(step_mother)
|
13
|
+
@step_mother = step_mother
|
14
|
+
@step_mother.extend(StepMother)
|
15
|
+
@step_mother.snippet_generator = StepDefinition
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute(args)
|
19
|
+
parse(args).execute!(@step_mother)
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse(args)
|
23
|
+
cli = new
|
24
|
+
cli.parse_options!(args)
|
25
|
+
cli
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :options, :paths
|
30
|
+
FORMATS = %w{pretty profile progress rerun}
|
31
|
+
DEFAULT_FORMAT = 'pretty'
|
32
|
+
|
33
|
+
def initialize(out_stream = STDOUT, error_stream = STDERR)
|
34
|
+
@out_stream = out_stream
|
35
|
+
|
36
|
+
@error_stream = error_stream
|
37
|
+
@paths = []
|
38
|
+
@options = {
|
39
|
+
:strict => false,
|
40
|
+
:require => nil,
|
41
|
+
:lang => 'en',
|
42
|
+
:dry_run => false,
|
43
|
+
:formats => {},
|
44
|
+
:excludes => [],
|
45
|
+
:tags => [],
|
46
|
+
:scenario_names => []
|
47
|
+
}
|
48
|
+
@active_format = DEFAULT_FORMAT
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_options!(args)
|
52
|
+
@args = args
|
53
|
+
return parse_args_from_profile('default') if args.empty?
|
54
|
+
args.extend(OptionParser::Arguable)
|
55
|
+
|
56
|
+
args.options do |opts|
|
57
|
+
opts.banner = ["Usage: cucumber [options] [[FILE[:LINE[:LINE]*]] | [FILES|DIRS]]", "",
|
58
|
+
"Examples:",
|
59
|
+
"cucumber examples/i18n/en/features",
|
60
|
+
"cucumber --language it examples/i18n/it/features/somma.feature:6:98:113", "", ""
|
61
|
+
].join("\n")
|
62
|
+
opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR",
|
63
|
+
"Require files before executing the features. If this",
|
64
|
+
"option is not specified, all *.rb files that are",
|
65
|
+
"siblings or below the features will be loaded auto-",
|
66
|
+
"matically. Automatic loading is disabled when this",
|
67
|
+
"option is specified, and all loading becomes explicit.",
|
68
|
+
"Files under directories named \"support\" are always",
|
69
|
+
"loaded first.",
|
70
|
+
"This option can be specified multiple times.") do |v|
|
71
|
+
@options[:require] ||= []
|
72
|
+
@options[:require] << v
|
73
|
+
end
|
74
|
+
opts.on("-l LANG", "--language LANG",
|
75
|
+
"Specify language for features (Default: #{@options[:lang]})",
|
76
|
+
%{Run with "--language help" to see all languages},
|
77
|
+
%{Run with "--language LANG help" to list keywords for LANG}) do |v|
|
78
|
+
if v == 'help'
|
79
|
+
list_languages
|
80
|
+
elsif args==['help']
|
81
|
+
list_keywords(v)
|
82
|
+
else
|
83
|
+
@options[:lang] = v
|
84
|
+
end
|
85
|
+
end
|
86
|
+
opts.on("-f FORMAT", "--format FORMAT",
|
87
|
+
"How to format features (Default: #{DEFAULT_FORMAT})",
|
88
|
+
"Available formats: #{FORMATS.join(", ")}",
|
89
|
+
"You can also provide your own formatter classes as long",
|
90
|
+
"as they have been previously required using --require or",
|
91
|
+
"if they are in the folder structure such that cucumber",
|
92
|
+
"will require them automatically.",
|
93
|
+
"This option can be specified multiple times.") do |v|
|
94
|
+
@options[:formats][v] = @out_stream
|
95
|
+
@active_format = v
|
96
|
+
end
|
97
|
+
opts.on("-o", "--out FILE",
|
98
|
+
"Write output to a file instead of STDOUT. This option",
|
99
|
+
"applies to the previously specified --format, or the",
|
100
|
+
"default format if no format is specified.") do |v|
|
101
|
+
@options[:formats][@active_format] = v
|
102
|
+
end
|
103
|
+
opts.on("-t TAGS", "--tags TAGS",
|
104
|
+
"Only execute the features or scenarios with the specified tags.",
|
105
|
+
"TAGS must be comma-separated without spaces.") do |v|
|
106
|
+
@options[:tags] = v.split(",")
|
107
|
+
end
|
108
|
+
opts.on("-s SCENARIO", "--scenario SCENARIO",
|
109
|
+
"Only execute the scenario with the given name. If this option",
|
110
|
+
"is given more than once, run all the specified scenarios.") do |v|
|
111
|
+
@options[:scenario_names] << v
|
112
|
+
end
|
113
|
+
opts.on("-e", "--exclude PATTERN", "Don't run feature files matching PATTERN") do |v|
|
114
|
+
@options[:excludes] << v
|
115
|
+
end
|
116
|
+
opts.on("-p", "--profile PROFILE", "Pull commandline arguments from cucumber.yml.") do |v|
|
117
|
+
parse_args_from_profile(v)
|
118
|
+
end
|
119
|
+
opts.on("-c", "--[no-]color",
|
120
|
+
"Whether or not to use ANSI color in the output. Cucumber decides",
|
121
|
+
"based on your platform and the output destination if not specified.") do |v|
|
122
|
+
Term::ANSIColor.coloring = v
|
123
|
+
end
|
124
|
+
opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.",
|
125
|
+
"Implies --quiet.") do
|
126
|
+
@options[:dry_run] = true
|
127
|
+
@quiet = true
|
128
|
+
end
|
129
|
+
opts.on("-a", "--autoformat DIRECTORY",
|
130
|
+
"Reformats (pretty prints) feature files and write them to DIRECTORY.",
|
131
|
+
"Be careful if you choose to overwrite the originals.",
|
132
|
+
"Implies --dry-run --formatter pretty.") do |directory|
|
133
|
+
@options[:autoformat] = directory
|
134
|
+
Term::ANSIColor.coloring = false
|
135
|
+
@options[:dry_run] = true
|
136
|
+
@quiet = true
|
137
|
+
end
|
138
|
+
opts.on("-m", "--[no-]multiline",
|
139
|
+
"Don't print multiline strings and tables under steps.") do |v|
|
140
|
+
@options[:source] = v
|
141
|
+
end
|
142
|
+
opts.on("-n", "--[no-]source",
|
143
|
+
"Don't show the file and line of the step definition with the steps.") do |v|
|
144
|
+
@options[:source] = v
|
145
|
+
end
|
146
|
+
opts.on("-i", "--[no-]snippets", "Don't show the snippets for pending steps.") do |v|
|
147
|
+
@options[:snippets] = v
|
148
|
+
end
|
149
|
+
opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") do
|
150
|
+
@quiet = true
|
151
|
+
end
|
152
|
+
opts.on("-b", "--backtrace", "Show full backtrace for all errors.") do
|
153
|
+
Exception.cucumber_full_backtrace = true
|
154
|
+
end
|
155
|
+
opts.on("--strict", "Fail if there are any undefined steps.") do
|
156
|
+
@options[:strict] = true
|
157
|
+
end
|
158
|
+
opts.on("-v", "--verbose", "Show the files and features loaded.") do
|
159
|
+
@options[:verbose] = true
|
160
|
+
end
|
161
|
+
opts.on_tail("--version", "Show version.") do
|
162
|
+
@out_stream.puts VERSION::STRING
|
163
|
+
Kernel.exit
|
164
|
+
end
|
165
|
+
opts.on_tail("--help", "You're looking at it.") do
|
166
|
+
@out_stream.puts opts.help
|
167
|
+
Kernel.exit
|
168
|
+
end
|
169
|
+
end.parse!
|
170
|
+
|
171
|
+
@options[:formats]['pretty'] = @out_stream if @options[:formats].empty?
|
172
|
+
|
173
|
+
@options[:snippets] = true if !@quiet && @options[:snippets].nil?
|
174
|
+
@options[:source] = true if !@quiet && @options[:source].nil?
|
175
|
+
|
176
|
+
# Whatever is left after option parsing is the FILE arguments
|
177
|
+
@paths += args
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def execute!(step_mother)
|
182
|
+
Cucumber.load_language(@options[:lang])
|
183
|
+
require_files
|
184
|
+
enable_diffing
|
185
|
+
features = load_plain_text_features
|
186
|
+
|
187
|
+
visitor = build_formatter_broadcaster(step_mother)
|
188
|
+
visitor.options = @options
|
189
|
+
visitor.visit_features(features)
|
190
|
+
|
191
|
+
failure = features.steps[:failed].any? || (@options[:strict] && features.steps[:undefined].length)
|
192
|
+
Kernel.exit(failure ? 1 : 0)
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def cucumber_yml
|
198
|
+
return @cucumber_yml if @cucumber_yml
|
199
|
+
unless File.exist?('cucumber.yml')
|
200
|
+
raise(YmlLoadError,"cucumber.yml was not found. Please refer to cucumber's documentaion on defining profiles in cucumber.yml. You must define a 'default' profile to use the cucumber command without any arguments.\nType 'cucumber --help' for usage.\n")
|
201
|
+
end
|
202
|
+
|
203
|
+
require 'yaml'
|
204
|
+
begin
|
205
|
+
@cucumber_yml = YAML::load(IO.read('cucumber.yml'))
|
206
|
+
rescue Exception => e
|
207
|
+
raise(YmlLoadError,"cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentaion on correct profile usage.\n")
|
208
|
+
end
|
209
|
+
|
210
|
+
if @cucumber_yml.nil? || !@cucumber_yml.is_a?(Hash)
|
211
|
+
raise(YmlLoadError,"cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentaion on correct profile usage.\n")
|
212
|
+
end
|
213
|
+
|
214
|
+
return @cucumber_yml
|
215
|
+
end
|
216
|
+
|
217
|
+
def parse_args_from_profile(profile)
|
218
|
+
unless cucumber_yml.has_key?(profile)
|
219
|
+
return(exit_with_error <<-END_OF_ERROR)
|
220
|
+
Could not find profile: '#{profile}'
|
221
|
+
|
222
|
+
Defined profiles in cucumber.yml:
|
223
|
+
* #{cucumber_yml.keys.join("\n * ")}
|
224
|
+
END_OF_ERROR
|
225
|
+
end
|
226
|
+
|
227
|
+
args_from_yml = cucumber_yml[profile] || ''
|
228
|
+
|
229
|
+
if !args_from_yml.is_a?(String)
|
230
|
+
exit_with_error "Profiles must be defined as a String. The '#{profile}' profile was #{args_from_yml.inspect} (#{args_from_yml.class}).\n"
|
231
|
+
elsif args_from_yml =~ /^\s*$/
|
232
|
+
exit_with_error "The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml.\n"
|
233
|
+
else
|
234
|
+
parse_options!(args_from_yml.split(' '))
|
235
|
+
end
|
236
|
+
|
237
|
+
rescue YmlLoadError => e
|
238
|
+
exit_with_error(e.message)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Requires files - typically step files and ruby feature files.
|
242
|
+
def require_files
|
243
|
+
verbose_log("Ruby files required:")
|
244
|
+
files_to_require.each do |lib|
|
245
|
+
begin
|
246
|
+
require lib
|
247
|
+
verbose_log(" * #{lib}")
|
248
|
+
rescue LoadError => e
|
249
|
+
e.message << "\nFailed to load #{lib}"
|
250
|
+
raise e
|
251
|
+
end
|
252
|
+
end
|
253
|
+
verbose_log("\n")
|
254
|
+
end
|
255
|
+
|
256
|
+
def files_to_require
|
257
|
+
requires = @options[:require] || feature_dirs
|
258
|
+
files = requires.map do |path|
|
259
|
+
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
|
260
|
+
File.directory?(path) ? Dir["#{path}/**/*.rb"] : path
|
261
|
+
end.flatten.uniq
|
262
|
+
files.sort { |a,b| (b =~ %r{/support/} || -1) <=> (a =~ %r{/support/} || -1) }
|
263
|
+
end
|
264
|
+
|
265
|
+
def feature_files
|
266
|
+
potential_feature_files = @paths.map do |path|
|
267
|
+
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
|
268
|
+
path = path.chomp('/')
|
269
|
+
File.directory?(path) ? Dir["#{path}/**/*.feature"] : path
|
270
|
+
end.flatten.uniq
|
271
|
+
|
272
|
+
@options[:excludes].each do |exclude|
|
273
|
+
potential_feature_files.reject! do |path|
|
274
|
+
path =~ /#{Regexp.escape(exclude)}/
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
potential_feature_files
|
279
|
+
end
|
280
|
+
|
281
|
+
def feature_dirs
|
282
|
+
feature_files.map{|f| File.directory?(f) ? f : File.dirname(f)}.uniq
|
283
|
+
end
|
284
|
+
|
285
|
+
def load_plain_text_features
|
286
|
+
filter = Ast::Filter.new(@options)
|
287
|
+
features = Ast::Features.new(filter)
|
288
|
+
parser = Parser::FeatureParser.new
|
289
|
+
|
290
|
+
verbose_log("Features:")
|
291
|
+
feature_files.each do |f|
|
292
|
+
features.add_feature(parser.parse_file(f))
|
293
|
+
verbose_log(" * #{f}")
|
294
|
+
end
|
295
|
+
verbose_log("\n"*2)
|
296
|
+
features
|
297
|
+
end
|
298
|
+
|
299
|
+
def build_formatter_broadcaster(step_mother)
|
300
|
+
return Formatter::Pretty.new(step_mother, nil, @options) if @options[:autoformat]
|
301
|
+
formatters = @options[:formats].map do |format, out|
|
302
|
+
if String === out # file name
|
303
|
+
out = File.open(out, Cucumber.file_mode('w'))
|
304
|
+
at_exit do
|
305
|
+
out.flush
|
306
|
+
out.close
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
case format
|
311
|
+
when 'pretty'
|
312
|
+
Formatter::Pretty.new(step_mother, out, @options)
|
313
|
+
when 'progress'
|
314
|
+
Formatter::Progress.new(step_mother, out, @options)
|
315
|
+
when 'profile'
|
316
|
+
Formatter::Profile.new(step_mother, out, @options)
|
317
|
+
when 'rerun'
|
318
|
+
Formatter::Rerun.new(step_mother, out, @options)
|
319
|
+
else
|
320
|
+
begin
|
321
|
+
formatter_class = constantize(format)
|
322
|
+
formatter_class.new(step_mother, out, @options)
|
323
|
+
rescue Exception => e
|
324
|
+
exit_with_error("Error creating formatter: #{format}", e)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
Broadcaster.new(formatters)
|
329
|
+
end
|
330
|
+
|
331
|
+
def constantize(camel_cased_word)
|
332
|
+
names = camel_cased_word.split('::')
|
333
|
+
names.shift if names.empty? || names.first.empty?
|
334
|
+
|
335
|
+
constant = Object
|
336
|
+
names.each do |name|
|
337
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
338
|
+
end
|
339
|
+
constant
|
340
|
+
end
|
341
|
+
|
342
|
+
def verbose_log(string)
|
343
|
+
@out_stream.puts(string) if @options[:verbose]
|
344
|
+
end
|
345
|
+
|
346
|
+
def exit_with_help
|
347
|
+
parse_options!(%w{--help})
|
348
|
+
end
|
349
|
+
|
350
|
+
def exit_with_error(error_message, e=nil)
|
351
|
+
@error_stream.puts(error_message)
|
352
|
+
if e
|
353
|
+
@error_stream.puts("#{e.message} (#{e.class})")
|
354
|
+
@error_stream.puts(e.backtrace.join("\n"))
|
355
|
+
end
|
356
|
+
Kernel.exit 1
|
357
|
+
end
|
358
|
+
|
359
|
+
def enable_diffing
|
360
|
+
if defined?(::Spec)
|
361
|
+
require 'spec/expectations/differs/default'
|
362
|
+
options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
|
363
|
+
::Spec::Expectations.differ = ::Spec::Expectations::Differs::Default.new(options)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def list_languages
|
368
|
+
raw = Cucumber::LANGUAGES.keys.sort.map do |lang|
|
369
|
+
[lang, Cucumber::LANGUAGES[lang]['name'], Cucumber::LANGUAGES[lang]['native']]
|
370
|
+
end
|
371
|
+
print_lang_table(raw, {:check_lang=>true})
|
372
|
+
end
|
373
|
+
|
374
|
+
def list_keywords(lang)
|
375
|
+
unless Cucumber::LANGUAGES[lang]
|
376
|
+
exit_with_error("No language with key #{v}")
|
377
|
+
end
|
378
|
+
raw = Cucumber::KEYWORD_KEYS.map do |key|
|
379
|
+
[key, Cucumber::LANGUAGES[lang][key]]
|
380
|
+
end
|
381
|
+
print_lang_table(raw, {})
|
382
|
+
end
|
383
|
+
|
384
|
+
def print_lang_table(raw, options)
|
385
|
+
table = Ast::Table.new(raw)
|
386
|
+
formatter = Formatter::Pretty.new(nil, @out_stream, options, '')
|
387
|
+
|
388
|
+
def formatter.visit_table_row(table_row, status)
|
389
|
+
@col = 1
|
390
|
+
super
|
391
|
+
end
|
392
|
+
|
393
|
+
def formatter.visit_table_cell_value(value, width, status)
|
394
|
+
if @col == 1
|
395
|
+
if(@options[:check_lang])
|
396
|
+
@incomplete = Cucumber.language_complete?(value)
|
397
|
+
end
|
398
|
+
status = :comment
|
399
|
+
elsif @incomplete
|
400
|
+
status = :failed
|
401
|
+
end
|
402
|
+
|
403
|
+
@col += 1
|
404
|
+
super(value, width, status)
|
405
|
+
end
|
406
|
+
|
407
|
+
formatter.indent = 0
|
408
|
+
formatter.visit_multiline_arg(table, :passed)
|
409
|
+
Kernel.exit
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
Cucumber::CLI.step_mother = self
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Exception extension that tweaks Exception backtraces:
|
2
|
+
#
|
3
|
+
# * The line of the failing .feature line is appended to the backtrace
|
4
|
+
# * The line that calls #cucumber_instance_exec is replaced with the StepDefinition's regexp
|
5
|
+
# * Non intersting lines are stripped out
|
6
|
+
#
|
7
|
+
# The result is that backtraces look like this:
|
8
|
+
#
|
9
|
+
# features/step_definitions/the_step_definition.rb:in `/some step/'
|
10
|
+
# features/the_feature_file.feature:41:in `Given some step'
|
11
|
+
#
|
12
|
+
# or if the exception is raised in the tested code:
|
13
|
+
#
|
14
|
+
# lib/myapp/some_file.rb:in `/some_method/'
|
15
|
+
# lib/myapp/some_other_file.rb:in `/some_other_method/'
|
16
|
+
# features/step_definitions/the_step_definition.rb:in `/some step/'
|
17
|
+
# features/the_feature_file.feature:41:in `Given some step'
|
18
|
+
#
|
19
|
+
# All backtrace munging can be turned off with the <tt>--backtrace</tt> switch
|
20
|
+
#
|
21
|
+
class Exception
|
22
|
+
CUCUMBER_FILTER_PATTERNS = [
|
23
|
+
/vendor\/rails|lib\/cucumber|lib\/rspec|gems\//
|
24
|
+
]
|
25
|
+
|
26
|
+
INSTANCE_EXEC_OFFSET = (Cucumber::RUBY_1_9 || Cucumber::JRUBY) ? -3 : -4
|
27
|
+
|
28
|
+
def self.cucumber_full_backtrace=(v)
|
29
|
+
@@cucumber_full_backtrace = v
|
30
|
+
end
|
31
|
+
self.cucumber_full_backtrace = false
|
32
|
+
|
33
|
+
# Strips the backtrace from +line+ and down
|
34
|
+
def self.cucumber_strip_backtrace!(backtrace, instance_exec_invocation_line, pseudo_method)
|
35
|
+
return if @@cucumber_full_backtrace
|
36
|
+
|
37
|
+
instance_exec_pos = backtrace.index(instance_exec_invocation_line)
|
38
|
+
if instance_exec_pos
|
39
|
+
replacement_line = instance_exec_pos + INSTANCE_EXEC_OFFSET
|
40
|
+
backtrace[replacement_line].gsub!(/`.*'/, "`#{pseudo_method}'") if pseudo_method
|
41
|
+
backtrace[replacement_line+1..-1] = nil
|
42
|
+
|
43
|
+
backtrace.compact!
|
44
|
+
else
|
45
|
+
# This happens with rails, because they screw up the backtrace
|
46
|
+
# before we get here (injecting erb stacktrace and such)
|
47
|
+
end
|
48
|
+
|
49
|
+
backtrace.reject! do |line|
|
50
|
+
CUCUMBER_FILTER_PATTERNS.detect{|p| line =~ p}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|