kosmas58-cucumber 0.1.99.22 → 0.1.99.23
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +525 -0
- data/License.txt +20 -0
- data/Manifest.txt +322 -0
- data/README.txt +25 -0
- data/Rakefile +8 -0
- data/bin/cucumber +6 -0
- data/config/hoe.rb +76 -0
- data/config/requirements.rb +15 -0
- 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 +16 -0
- data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +24 -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 +16 -0
- data/examples/i18n/es/features/step_definitons/calculador_steps.rb +21 -0
- data/examples/i18n/es/lib/calculador.rb +14 -0
- data/examples/i18n/et/Rakefile +6 -0
- data/examples/i18n/et/features/liitmine.feature +16 -0
- data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +24 -0
- data/examples/i18n/et/lib/kalkulaator.rb +14 -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 +17 -0
- data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +25 -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/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 +17 -0
- data/examples/i18n/no/features/summering.feature +18 -0
- data/examples/i18n/no/features/support/env.rb +6 -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/ru/Rakefile +6 -0
- data/examples/i18n/ru/features/addition.feature +10 -0
- data/examples/i18n/ru/features/consecutive_calculations.feature +16 -0
- data/examples/i18n/ru/features/division.feature +15 -0
- data/examples/i18n/ru/features/step_definitons/calculator_steps.rb +19 -0
- data/examples/i18n/ru/features/support/env.rb +6 -0
- data/examples/i18n/ru/features/support/world.rb +7 -0
- data/examples/i18n/ru/lib/calculator.rb +24 -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/i18n/zh-TW/Rakefile +6 -0
- data/examples/i18n/zh-TW/features/addition.feature +16 -0
- data/examples/i18n/zh-TW/features/division.feature +10 -0
- data/examples/i18n/zh-TW/features/step_definitons/calculator_steps.rb +24 -0
- data/examples/i18n/zh-TW/lib/calculator.rb +14 -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/self_test/README.textile +6 -0
- data/examples/self_test/Rakefile +6 -0
- data/examples/self_test/features/background/failing_background.feature +10 -0
- data/examples/self_test/features/background/failing_background_after_success.feature +11 -0
- data/examples/self_test/features/background/multiline_args_background.feature +32 -0
- data/examples/self_test/features/background/passing_background.feature +10 -0
- data/examples/self_test/features/background/pending_background.feature +10 -0
- data/examples/self_test/features/background/scenario_outline_failing_background.feature +16 -0
- data/examples/self_test/features/background/scenario_outline_passing_background.feature +16 -0
- data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
- data/examples/self_test/features/failing_expectation.feature +4 -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 +19 -0
- data/examples/self_test/features/step_definitions/sample_steps.rb +64 -0
- data/examples/self_test/features/support/env.rb +1 -0
- data/examples/self_test/features/support/tag_count_formatter.rb +25 -0
- data/examples/sinatra/Rakefile +6 -0
- data/examples/sinatra/app.rb +14 -0
- data/examples/sinatra/features/add.feature +11 -0
- data/examples/sinatra/features/step_definitions/add_steps.rb +15 -0
- data/examples/sinatra/features/support/env.rb +20 -0
- data/examples/sinatra/views/add.erb +5 -0
- data/examples/sinatra/views/layout.erb +8 -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/172.feature +28 -0
- data/examples/tickets/features/177/1.feature +29 -0
- data/examples/tickets/features/177/2.feature +21 -0
- data/examples/tickets/features/177/3.feature +18 -0
- data/examples/tickets/features/180.feature +7 -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/background.feature +223 -0
- data/features/cucumber_cli.feature +366 -0
- data/features/cucumber_cli_diff_disabled.feature +45 -0
- data/features/cucumber_cli_outlines.feature +90 -0
- data/features/custom_formatter.feature +11 -0
- data/features/report_called_undefined_steps.feature +32 -0
- data/features/step_definitions/cucumber_steps.rb +30 -0
- data/features/step_definitions/extra_steps.rb +2 -0
- data/features/support/env.rb +8 -0
- data/gem_tasks/deployment.rake +11 -0
- data/gem_tasks/environment.rake +7 -0
- data/gem_tasks/features.rake +9 -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/jar.rake +67 -0
- data/gem_tasks/rspec.rake +38 -0
- data/gem_tasks/yard.rake +8 -0
- data/lib/autotest/cucumber.rb +6 -0
- data/lib/autotest/cucumber_mixin.rb +125 -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 +71 -0
- data/lib/cucumber/ast.rb +29 -0
- data/lib/cucumber/ast/background.rb +88 -0
- data/lib/cucumber/ast/comment.rb +26 -0
- data/lib/cucumber/ast/examples.rb +26 -0
- data/lib/cucumber/ast/feature.rb +66 -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 +103 -0
- data/lib/cucumber/ast/scenario_outline.rb +92 -0
- data/lib/cucumber/ast/step.rb +161 -0
- data/lib/cucumber/ast/steps.rb +13 -0
- data/lib/cucumber/ast/table.rb +290 -0
- data/lib/cucumber/ast/tags.rb +40 -0
- data/lib/cucumber/ast/visitor.rb +109 -0
- data/lib/cucumber/broadcaster.rb +15 -0
- data/lib/cucumber/cli/configuration.rb +356 -0
- data/lib/cucumber/cli/language_help_formatter.rb +59 -0
- data/lib/cucumber/cli/main.rb +107 -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 +103 -0
- data/lib/cucumber/formatter/color_io.rb +23 -0
- data/lib/cucumber/formatter/console.rb +119 -0
- data/lib/cucumber/formatter/cucumber.css +55 -0
- data/lib/cucumber/formatter/cucumber.sass +49 -0
- data/lib/cucumber/formatter/html.rb +126 -0
- data/lib/cucumber/formatter/pretty.rb +167 -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/formatter/unicode.rb +35 -0
- data/lib/cucumber/formatters/unicode.rb +2 -0
- data/lib/cucumber/jbehave.rb +102 -0
- data/lib/cucumber/languages.yml +374 -0
- data/lib/cucumber/parser.rb +43 -0
- data/lib/cucumber/parser/basic.rb +0 -0
- data/lib/cucumber/parser/feature.rb +1490 -0
- data/lib/cucumber/parser/feature.tt +188 -0
- data/lib/cucumber/parser/i18n.tt +31 -0
- data/lib/cucumber/parser/table.rb +402 -0
- data/lib/cucumber/parser/table.tt +59 -0
- data/lib/cucumber/parser/treetop_ext.rb +75 -0
- data/lib/cucumber/platform.rb +18 -0
- data/lib/cucumber/rails/rspec.rb +8 -0
- data/lib/cucumber/rails/world.rb +73 -0
- data/lib/cucumber/rake/task.rb +146 -0
- data/lib/cucumber/step_definition.rb +94 -0
- data/lib/cucumber/step_mother.rb +194 -0
- data/lib/cucumber/version.rb +10 -0
- data/rails_generators/cucumber/USAGE +14 -0
- data/rails_generators/cucumber/cucumber_generator.rb +75 -0
- data/rails_generators/cucumber/templates/cucumber +8 -0
- data/rails_generators/cucumber/templates/cucumber.rake +20 -0
- data/rails_generators/cucumber/templates/env.rb +17 -0
- data/rails_generators/cucumber/templates/paths.rb +19 -0
- data/rails_generators/cucumber/templates/webrat_steps.rb +115 -0
- data/rails_generators/feature/USAGE +15 -0
- data/rails_generators/feature/feature_generator.rb +60 -0
- data/rails_generators/feature/templates/feature.erb +31 -0
- data/rails_generators/feature/templates/steps.erb +24 -0
- data/spec/cucumber/ast/background_spec.rb +58 -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 +139 -0
- data/spec/cucumber/ast/tags_spec.rb +35 -0
- data/spec/cucumber/broadcaster_spec.rb +14 -0
- data/spec/cucumber/cli/configuration_spec.rb +268 -0
- data/spec/cucumber/cli/main_spec.rb +204 -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/color_io_spec.rb +26 -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 +281 -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 +70 -0
- data/spec/cucumber/step_mother_spec.rb +73 -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 +329 -9
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'cucumber/step_definition'
|
2
|
+
require 'cucumber/core_ext/instance_exec'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
class Undefined < StandardError
|
6
|
+
attr_reader :step_name
|
7
|
+
|
8
|
+
def initialize(step_name)
|
9
|
+
super %{Undefined step: "#{step_name}"}
|
10
|
+
@step_name = step_name
|
11
|
+
end
|
12
|
+
Cucumber::EXCEPTION_STATUS[self] = :undefined
|
13
|
+
end
|
14
|
+
|
15
|
+
class Pending < StandardError
|
16
|
+
Cucumber::EXCEPTION_STATUS[self] = :pending
|
17
|
+
end
|
18
|
+
|
19
|
+
# Raised when a step matches 2 or more StepDefinition
|
20
|
+
class Ambiguous < StandardError
|
21
|
+
def initialize(step_name, step_definitions)
|
22
|
+
message = "Ambiguous match of \"#{step_name}\":\n\n"
|
23
|
+
message << step_definitions.map{|sd| sd.to_backtrace_line}.join("\n")
|
24
|
+
message << "\n\n"
|
25
|
+
super(message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Raised when 2 or more StepDefinition have the same Regexp
|
30
|
+
class Redundant < StandardError
|
31
|
+
def initialize(step_def_1, step_def_2)
|
32
|
+
message = "Multiple step definitions have the same Regexp:\n\n"
|
33
|
+
message << step_def_1.to_backtrace_line << "\n"
|
34
|
+
message << step_def_2.to_backtrace_line << "\n\n"
|
35
|
+
super(message)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# This is the main interface for registering step definitions, which is done
|
40
|
+
# from <tt>*_steps.rb</tt> files. This module is included right at the top-level
|
41
|
+
# so #register_step_definition (and more interestingly - its aliases) are
|
42
|
+
# available from the top-level.
|
43
|
+
module StepMother
|
44
|
+
attr_writer :snippet_generator
|
45
|
+
attr_writer :options
|
46
|
+
|
47
|
+
# Registers a new StepDefinition. This method is aliased
|
48
|
+
# to <tt>Given</tt>, <tt>When</tt> and <tt>Then</tt>.
|
49
|
+
#
|
50
|
+
# See Cucumber#alias_steps for details on how to
|
51
|
+
# create your own aliases.
|
52
|
+
#
|
53
|
+
# The +&proc+ gets executed in the context of a <tt>world</tt>
|
54
|
+
# object, which is defined by #World. A new <tt>world</tt>
|
55
|
+
# object is created for each scenario and is shared across
|
56
|
+
# step definitions within that scenario.
|
57
|
+
def register_step_definition(regexp, &proc)
|
58
|
+
step_definition = StepDefinition.new(regexp, &proc)
|
59
|
+
step_definitions.each do |already|
|
60
|
+
raise Redundant.new(already, step_definition) if already.match(regexp)
|
61
|
+
end
|
62
|
+
step_definitions << step_definition
|
63
|
+
step_definition
|
64
|
+
end
|
65
|
+
|
66
|
+
def world(scenario, prior_world = nil, &proc)
|
67
|
+
world = prior_world || new_world
|
68
|
+
begin
|
69
|
+
(@before_procs ||= []).each do |proc|
|
70
|
+
world.cucumber_instance_exec(false, 'Before', scenario, &proc)
|
71
|
+
end
|
72
|
+
yield world
|
73
|
+
ensure
|
74
|
+
(@after_procs ||= []).each do |proc|
|
75
|
+
world.cucumber_instance_exec(false, 'After', scenario, &proc)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Registers a Before proc. You can call this method as many times as you
|
81
|
+
# want (typically from ruby scripts under <tt>support</tt>).
|
82
|
+
def Before(&proc)
|
83
|
+
(@before_procs ||= []) << proc
|
84
|
+
end
|
85
|
+
|
86
|
+
def After(&proc)
|
87
|
+
(@after_procs ||= []) << proc
|
88
|
+
end
|
89
|
+
|
90
|
+
# Registers a World proc. You can call this method as many times as you
|
91
|
+
# want (typically from ruby scripts under <tt>support</tt>).
|
92
|
+
def World(&proc)
|
93
|
+
(@world_procs ||= []) << proc
|
94
|
+
end
|
95
|
+
|
96
|
+
# Creates a new world instance
|
97
|
+
def new_world #:nodoc:
|
98
|
+
world = Object.new
|
99
|
+
(@world_procs ||= []).each do |proc|
|
100
|
+
world = proc.call(world)
|
101
|
+
end
|
102
|
+
|
103
|
+
world.extend(WorldMethods)
|
104
|
+
world.__cucumber_step_mother = self
|
105
|
+
|
106
|
+
world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
|
107
|
+
world
|
108
|
+
end
|
109
|
+
|
110
|
+
# Looks up the StepDefinition that matches +step_name+
|
111
|
+
def step_definition(step_name) #:nodoc:
|
112
|
+
found = step_definitions.select do |step_definition|
|
113
|
+
step_definition.match(step_name)
|
114
|
+
end
|
115
|
+
raise Undefined.new(step_name) if found.empty?
|
116
|
+
found = best_matches(step_name, found) if found.size > 1 && options[:guess]
|
117
|
+
raise Ambiguous.new(step_name, found) if found.size > 1
|
118
|
+
found[0]
|
119
|
+
end
|
120
|
+
|
121
|
+
def best_matches(step_name, step_definitions)
|
122
|
+
top_group_score = step_definitions.map {|s| s.match(step_name).captures.length }.sort.last
|
123
|
+
top_groups = step_definitions.select {|s| s.match(step_name).captures.length == top_group_score }
|
124
|
+
if top_groups.size > 1
|
125
|
+
shortest_capture_length = top_groups.map {|s| s.match(step_name).captures.inject(0) {|sum, c| sum + c.length } }.sort.first
|
126
|
+
top_groups.select {|s| s.match(step_name).captures.inject(0) {|sum, c| sum + c.length } == shortest_capture_length }
|
127
|
+
else
|
128
|
+
top_groups
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def step_definitions
|
133
|
+
@step_definitions ||= []
|
134
|
+
end
|
135
|
+
|
136
|
+
def snippet_text(step_keyword, step_name)
|
137
|
+
@snippet_generator.snippet_text(step_keyword, step_name)
|
138
|
+
end
|
139
|
+
|
140
|
+
def print_step_definitions(out)
|
141
|
+
step_definitions.each do |step_definition|
|
142
|
+
indent = max_step_definition_length - step_definition.text_length
|
143
|
+
out.puts(step_definition.to_s(indent))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def max_step_definition_length
|
150
|
+
@max_step_definition_length ||= step_definitions.map{|step_definition| step_definition.text_length}.max
|
151
|
+
end
|
152
|
+
|
153
|
+
def options
|
154
|
+
@options || {}
|
155
|
+
end
|
156
|
+
|
157
|
+
module WorldMethods #:nodoc:
|
158
|
+
attr_writer :__cucumber_step_mother, :__cucumber_current_step
|
159
|
+
|
160
|
+
# Call a step from within a step definition
|
161
|
+
def __cucumber_invoke(name, *multiline_arguments)
|
162
|
+
begin
|
163
|
+
# TODO: Very similar to code in Step. Refactor. Get back StepInvocation?
|
164
|
+
# Make more similar to JBehave?
|
165
|
+
step_definition = @__cucumber_step_mother.step_definition(name)
|
166
|
+
matched_args = step_definition.matched_args(name)
|
167
|
+
args = (matched_args + multiline_arguments)
|
168
|
+
step_definition.execute(name, self, *args)
|
169
|
+
rescue Exception => e
|
170
|
+
@__cucumber_current_step.exception = e
|
171
|
+
raise e
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def table(text, file=nil, line=0)
|
176
|
+
@table_parser ||= Parser::TableParser.new
|
177
|
+
@table_parser.parse_or_fail(text.strip, file, line)
|
178
|
+
end
|
179
|
+
|
180
|
+
def pending(message = "TODO")
|
181
|
+
if block_given?
|
182
|
+
begin
|
183
|
+
yield
|
184
|
+
rescue Exception => e
|
185
|
+
raise Pending.new(message)
|
186
|
+
end
|
187
|
+
raise Pending.new("Expected pending '#{message}' to fail. No Error was raised. No longer pending?")
|
188
|
+
else
|
189
|
+
raise Pending.new(message)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Description:
|
2
|
+
Sets up Cucumber in your Rails project. After running this generator you will
|
3
|
+
get a new rake task called features.
|
4
|
+
|
5
|
+
This also generates the necessary files in the features directory.
|
6
|
+
|
7
|
+
Also see the feature generator, which you can use to generate skeletons
|
8
|
+
for new features.
|
9
|
+
|
10
|
+
If you set the language option, then a subdirectory features/[language] will be generated instead.
|
11
|
+
Now your are able to use features in different languages.
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
`./script/generate cucumber`
|
@@ -0,0 +1,75 @@
|
|
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
|
+
|
8
|
+
attr_reader :language
|
9
|
+
attr_accessor :framework
|
10
|
+
|
11
|
+
def initialize(runtime_args, runtime_options = {})
|
12
|
+
super
|
13
|
+
@features_path = "features"
|
14
|
+
end
|
15
|
+
|
16
|
+
def manifest
|
17
|
+
if options[:language]
|
18
|
+
@language = options[:language]
|
19
|
+
set_language(@language)
|
20
|
+
end
|
21
|
+
record do |m|
|
22
|
+
m.directory File.join(@features_path, "step_definitions")
|
23
|
+
if @language
|
24
|
+
m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "paths.rb")
|
25
|
+
m.file File.join(@language, "webrat_steps.rb"), File.join(@features_path, "step_definitions", "webrat_steps.rb")
|
26
|
+
else
|
27
|
+
m.file "webrat_steps.rb", File.join(@features_path, "step_definitions", "webrat_steps.rb")
|
28
|
+
m.file "paths.rb", "features/support/paths.rb"
|
29
|
+
end
|
30
|
+
m.directory "features/support"
|
31
|
+
m.file "env.rb", "features/support/env.rb"
|
32
|
+
|
33
|
+
m.directory "lib/tasks"
|
34
|
+
m.template "cucumber.rake", "lib/tasks/cucumber.rake"
|
35
|
+
|
36
|
+
m.file "cucumber", "script/cucumber", {
|
37
|
+
:chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def framework
|
43
|
+
options[:framework] || :rspec
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def banner
|
49
|
+
"Usage: #{$0} cucumber"
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_options!(opt)
|
53
|
+
opt.separator ""
|
54
|
+
opt.separator "Options:"
|
55
|
+
opt.on("-l", "--language=lang", String, "Use a [language] subdirectoy in /features.") { |v| options[:language] = v }
|
56
|
+
end
|
57
|
+
|
58
|
+
# Load up the transations for the passed language, and modify the features_path accordingly
|
59
|
+
def set_language(language)
|
60
|
+
@features_path = File.join(@features_path, language)
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_options!(opt)
|
64
|
+
opt.separator ''
|
65
|
+
opt.separator 'Options:'
|
66
|
+
opt.on('--rspec', 'Setup cucumber for use with RSpec (default)') do |value|
|
67
|
+
options[:framework] = :rspec
|
68
|
+
end
|
69
|
+
|
70
|
+
opt.on('--testunit', 'Setup cucumber for use with test/unit') do |value|
|
71
|
+
options[:framework] = :testunit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
7
|
+
<% if language %>
|
8
|
+
t.language = "<%= language%>"
|
9
|
+
t.cucumber_opts = "--format pretty --language <%= language%>"
|
10
|
+
<% else %>
|
11
|
+
t.cucumber_opts = "--format pretty"
|
12
|
+
<% end %>
|
13
|
+
end
|
14
|
+
task :features => 'db:test:prepare'
|
15
|
+
rescue LoadError
|
16
|
+
desc 'Cucumber rake task not available'
|
17
|
+
task :features do
|
18
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
|
6
|
+
Cucumber::Rails.use_transactional_fixtures
|
7
|
+
|
8
|
+
require 'webrat'
|
9
|
+
|
10
|
+
Webrat.configure do |config|
|
11
|
+
config.mode = :rails
|
12
|
+
end
|
13
|
+
<% if framework == :rspec -%>
|
14
|
+
|
15
|
+
require 'cucumber/rails/rspec'
|
16
|
+
require 'webrat/core/matchers'
|
17
|
+
<% end -%>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
def path_to(page_name)
|
3
|
+
case page_name
|
4
|
+
|
5
|
+
when /the homepage/i
|
6
|
+
root_path
|
7
|
+
|
8
|
+
# Add more page name => path mappings here
|
9
|
+
|
10
|
+
else
|
11
|
+
raise "Can't find mapping from \"#{page_name}\" to a path."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
World do |world|
|
17
|
+
world.extend NavigationHelpers
|
18
|
+
world
|
19
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2
|
+
|
3
|
+
# Commonly used webrat steps
|
4
|
+
# http://github.com/brynary/webrat
|
5
|
+
|
6
|
+
Given /^I am on (.+)$/ do |page_name|
|
7
|
+
visit path_to(page_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I go to (.+)$/ do |page_name|
|
11
|
+
visit path_to(page_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^I press "(.*)"$/ do |button|
|
15
|
+
click_button(button)
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^I follow "(.*)"$/ do |link|
|
19
|
+
click_link(link)
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
|
23
|
+
fill_in(field, :with => value)
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^I select "(.*)" from "(.*)"$/ do |value, field|
|
27
|
+
select(value, :from => field)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
31
|
+
# When I select "December 25, 2008 10:00" as the date and time
|
32
|
+
When /^I select "(.*)" as the date and time$/ do |time|
|
33
|
+
select_datetime(time)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
37
|
+
# you want to specify which datetime to select. Given the following view:
|
38
|
+
# <%%= f.label :preferred %><br />
|
39
|
+
# <%%= f.datetime_select :preferred %>
|
40
|
+
# <%%= f.label :alternative %><br />
|
41
|
+
# <%%= f.datetime_select :alternative %>
|
42
|
+
# The following steps would fill out the form:
|
43
|
+
# When I select "November 23, 2004 11:20" as the "Preferred" data and time
|
44
|
+
# And I select "November 25, 2004 10:30" as the "Alternative" data and time
|
45
|
+
When /^I select "(.*)" as the "(.*)" date and time$/ do |datetime, datetime_label|
|
46
|
+
select_datetime(datetime, :from => datetime_label)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
50
|
+
# When I select "2:20PM" as the time
|
51
|
+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
52
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
53
|
+
When /^I select "(.*)" as the time$/ do |time|
|
54
|
+
select_time(time)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Use this step when using multiple time_select helpers on a page or you want to
|
58
|
+
# specify the name of the time on the form. For example:
|
59
|
+
# When I select "7:30AM" as the "Gym" time
|
60
|
+
When /^I select "(.*)" as the "(.*)" time$/ do |time, time_label|
|
61
|
+
select_time(time, :from => time_label)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
65
|
+
# When I select "February 20, 1981" as the date
|
66
|
+
When /^I select "(.*)" as the date$/ do |date|
|
67
|
+
select_date(date)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Use this step when using multiple date_select helpers on one page or
|
71
|
+
# you want to specify the name of the date on the form. For example:
|
72
|
+
# When I select "April 26, 1982" as the "Date of Birth" date
|
73
|
+
When /^I select "(.*)" as the "(.*)" date$/ do |date, date_label|
|
74
|
+
select_date(date, :from => date_label)
|
75
|
+
end
|
76
|
+
|
77
|
+
When /^I check "(.*)"$/ do |field|
|
78
|
+
check(field)
|
79
|
+
end
|
80
|
+
|
81
|
+
When /^I uncheck "(.*)"$/ do |field|
|
82
|
+
uncheck(field)
|
83
|
+
end
|
84
|
+
|
85
|
+
When /^I choose "(.*)"$/ do |field|
|
86
|
+
choose(field)
|
87
|
+
end
|
88
|
+
|
89
|
+
When /^I attach the file at "(.*)" to "(.*)"$/ do |path, field|
|
90
|
+
attach_file(field, path)
|
91
|
+
end
|
92
|
+
|
93
|
+
Then /^I should see "(.*)"$/ do |text|
|
94
|
+
<% if framework == :rspec -%>
|
95
|
+
response.should contain(text)
|
96
|
+
<% else -%>
|
97
|
+
assert_contain text
|
98
|
+
<% end -%>
|
99
|
+
end
|
100
|
+
|
101
|
+
Then /^I should not see "(.*)"$/ do |text|
|
102
|
+
<% if framework == :rspec -%>
|
103
|
+
response.should_not contain(text)
|
104
|
+
<% else -%>
|
105
|
+
assert_not_contain text
|
106
|
+
<% end -%>
|
107
|
+
end
|
108
|
+
|
109
|
+
Then /^the "(.*)" checkbox should be checked$/ do |label|
|
110
|
+
<% if framework == :rspec -%>
|
111
|
+
field_labeled(label).should be_checked
|
112
|
+
<% else -%>
|
113
|
+
assert field_labeled(label).checked?
|
114
|
+
<% end -%>
|
115
|
+
end
|