aslakhellesoy-cucumber 0.1.5 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +228 -0
- data/License.txt +20 -0
- data/Manifest.txt +226 -0
- data/README.txt +41 -0
- data/Rakefile +9 -0
- data/TODO.txt +26 -0
- data/bin/cucumber +5 -0
- data/config/hoe.rb +69 -0
- data/config/requirements.rb +15 -0
- data/cucumber.yml +1 -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/step_definitons/calculator_steps.rb +43 -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/step_definitons/hello_steps.rb +25 -0
- data/examples/cs/features/step_definitons/tree_steps.rb +14 -0
- data/examples/cs/features/tree.feature +9 -0
- data/examples/cs/src/Hello.cs +18 -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 +16 -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 +31 -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 +22 -0
- data/examples/i18n/da/features/summering.feature +17 -0
- data/examples/i18n/da/lib/kalkulator.rb +11 -0
- data/examples/i18n/en/Rakefile +5 -0
- data/examples/i18n/en/features/addition.feature +17 -0
- data/examples/i18n/en/features/division.feature +10 -0
- data/examples/i18n/en/features/step_definitons/calculator_steps.rb +31 -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 +22 -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 +26 -0
- data/examples/i18n/et/lib/kalkulaator.rb +10 -0
- data/examples/i18n/fr/Rakefile +6 -0
- data/examples/i18n/fr/features/addition.feature +13 -0
- data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +22 -0
- data/examples/i18n/fr/lib/calculatrice.rb +10 -0
- data/examples/i18n/id/Rakefile +6 -0
- data/examples/i18n/id/features/addition.feature +17 -0
- data/examples/i18n/id/features/division.feature +10 -0
- data/examples/i18n/id/features/step_definitons/calculator_steps.rb +31 -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 +22 -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 +17 -0
- data/examples/i18n/ja/features/division.feature +10 -0
- data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +30 -0
- data/examples/i18n/ja/lib/calculator.rb +14 -0
- data/examples/i18n/no/Rakefile +6 -0
- data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +22 -0
- data/examples/i18n/no/features/summering.feature +17 -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 +22 -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 +22 -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 +22 -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 +24 -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/selenium/Rakefile +6 -0
- data/examples/selenium/features/search.feature +9 -0
- data/examples/selenium/features/step_definitons/stories_steps.rb +41 -0
- data/examples/tickets/Rakefile +11 -0
- data/examples/tickets/cucumber.yml +2 -0
- data/examples/tickets/features/step_definitons/tickets_steps.rb +32 -0
- data/examples/tickets/features/tickets.feature +22 -0
- data/examples/watir/Rakefile +6 -0
- data/examples/watir/features/search.feature +9 -0
- data/examples/watir/features/step_definitons/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 +41 -0
- data/lib/autotest/cucumber.rb +6 -0
- data/lib/autotest/cucumber_mixin.rb +109 -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 +39 -0
- data/lib/cucumber/broadcaster.rb +20 -0
- data/lib/cucumber/cli.rb +269 -0
- data/lib/cucumber/core_ext/proc.rb +54 -0
- data/lib/cucumber/core_ext/string.rb +22 -0
- data/lib/cucumber/executor.rb +170 -0
- data/lib/cucumber/formatters.rb +1 -0
- data/lib/cucumber/formatters/ansicolor.rb +111 -0
- data/lib/cucumber/formatters/autotest_formatter.rb +23 -0
- data/lib/cucumber/formatters/cucumber.css +132 -0
- data/lib/cucumber/formatters/cucumber.js +11 -0
- data/lib/cucumber/formatters/html_formatter.rb +128 -0
- data/lib/cucumber/formatters/jquery.js +32 -0
- data/lib/cucumber/formatters/pretty_formatter.rb +234 -0
- data/lib/cucumber/formatters/profile_formatter.rb +92 -0
- data/lib/cucumber/formatters/progress_formatter.rb +58 -0
- data/lib/cucumber/languages.yml +235 -0
- data/lib/cucumber/model.rb +1 -0
- data/lib/cucumber/model/table.rb +28 -0
- data/lib/cucumber/rails/rspec.rb +12 -0
- data/lib/cucumber/rails/world.rb +73 -0
- data/lib/cucumber/rake/task.rb +101 -0
- data/lib/cucumber/step_methods.rb +49 -0
- data/lib/cucumber/step_mother.rb +89 -0
- data/lib/cucumber/tree.rb +18 -0
- data/lib/cucumber/tree/feature.rb +61 -0
- data/lib/cucumber/tree/features.rb +21 -0
- data/lib/cucumber/tree/given_scenario.rb +13 -0
- data/lib/cucumber/tree/scenario.rb +158 -0
- data/lib/cucumber/tree/step.rb +134 -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 +206 -0
- data/lib/cucumber/treetop_parser/feature_ar.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_cy.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_da.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_de.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_en-tx.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_en.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_es.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_et.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_fr.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_id.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_it.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_ja.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_nl.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_no.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_parser.rb +34 -0
- data/lib/cucumber/treetop_parser/feature_pl.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_pt.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_ro.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_ro2.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_ru.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_se.rb +1591 -0
- data/lib/cucumber/treetop_parser/feature_zh-CN.rb +1591 -0
- data/lib/cucumber/version.rb +9 -0
- data/rails_generators/cucumber/USAGE +11 -0
- data/rails_generators/cucumber/cucumber_generator.rb +30 -0
- data/rails_generators/cucumber/templates/cucumber +7 -0
- data/rails_generators/cucumber/templates/cucumber.rake +7 -0
- data/rails_generators/cucumber/templates/env.rb +8 -0
- data/rails_generators/cucumber/templates/webrat_steps.rb +46 -0
- data/rails_generators/feature/USAGE +12 -0
- data/rails_generators/feature/feature_generator.rb +16 -0
- data/rails_generators/feature/templates/feature.erb +28 -0
- data/rails_generators/feature/templates/steps.erb +22 -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/broadcaster_spec.rb +27 -0
- data/spec/cucumber/cli_spec.rb +242 -0
- data/spec/cucumber/core_ext/proc_spec.rb +45 -0
- data/spec/cucumber/core_ext/string_spec.rb +34 -0
- data/spec/cucumber/executor_spec.rb +222 -0
- data/spec/cucumber/formatters/ansicolor_spec.rb +35 -0
- data/spec/cucumber/formatters/autotest_formatter_spec.rb +26 -0
- data/spec/cucumber/formatters/features.html +269 -0
- data/spec/cucumber/formatters/html_formatter_spec.rb +74 -0
- data/spec/cucumber/formatters/pretty_formatter_spec.rb +204 -0
- data/spec/cucumber/formatters/profile_formatter_spec.rb +192 -0
- data/spec/cucumber/formatters/progress_formatter_spec.rb +65 -0
- data/spec/cucumber/model/table_spec.rb +20 -0
- data/spec/cucumber/rails/stubs/mini_rails.rb +17 -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_mother_spec.rb +74 -0
- data/spec/cucumber/tree/feature_spec.rb +12 -0
- data/spec/cucumber/tree/row_scenario_spec.rb +25 -0
- data/spec/cucumber/tree/scenario_spec.rb +76 -0
- data/spec/cucumber/tree/step_spec.rb +50 -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 +98 -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/multiline_steps.feature +17 -0
- data/spec/cucumber/treetop_parser/multiple_tables.feature +29 -0
- data/spec/cucumber/treetop_parser/spaces.feature +10 -0
- data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
- data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +19 -0
- metadata +151 -35
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module Cucumber
|
4
|
+
describe Broadcaster do
|
5
|
+
|
6
|
+
it "should broadcast methods to registered objects" do
|
7
|
+
broadcaster = Broadcaster.new
|
8
|
+
mock_receiver = mock('receiver')
|
9
|
+
|
10
|
+
mock_receiver.should_receive(:konbanwa).with('good evening')
|
11
|
+
broadcaster.register(mock_receiver)
|
12
|
+
|
13
|
+
broadcaster.konbanwa('good evening')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not call methods on registered objects if they dont support the method" do
|
17
|
+
broadcaster = Broadcaster.new
|
18
|
+
mock_receiver = mock('receiver', :respond_to? => false)
|
19
|
+
|
20
|
+
mock_receiver.should_not_receive(:konbanwa)
|
21
|
+
broadcaster.register(mock_receiver)
|
22
|
+
|
23
|
+
broadcaster.konbanwa()
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
describe CLI do
|
6
|
+
|
7
|
+
def mock_executor(stubs = {})
|
8
|
+
stub('executor', {:visit_features => nil, :failed => false, :formatters= => nil}.merge(stubs))
|
9
|
+
end
|
10
|
+
|
11
|
+
def mock_broadcaster(stubs = {})
|
12
|
+
stub(Broadcaster, {:register => nil}.merge(stubs))
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
Kernel.stub!(:exit)
|
17
|
+
end
|
18
|
+
|
19
|
+
def given_cucumber_yml_defined_as(hash)
|
20
|
+
File.stub!(:exist?).and_return(true)
|
21
|
+
cucumber_yml = hash.to_yaml
|
22
|
+
IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should expand args from YAML file" do
|
26
|
+
cli = CLI.new
|
27
|
+
|
28
|
+
given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
|
29
|
+
|
30
|
+
cli.parse_options!(%w{--format progress --profile bongo})
|
31
|
+
cli.options[:formats].should == {'progress' => [STDOUT]}
|
32
|
+
cli.options[:require].should == ['from/yml']
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should expand args from YAML file's default if there are no args" do
|
36
|
+
cli = CLI.new
|
37
|
+
|
38
|
+
given_cucumber_yml_defined_as({'default' => '--require from/yml'})
|
39
|
+
|
40
|
+
cli.parse_options!([])
|
41
|
+
cli.options[:require].should == ['from/yml']
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should provide a helpful error message when a specified profile does not exists in YAML file" do
|
45
|
+
cli = CLI.new(StringIO.new, error = StringIO.new)
|
46
|
+
|
47
|
+
given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
|
48
|
+
|
49
|
+
cli.parse_options!(%w{--profile i_do_not_exist})
|
50
|
+
|
51
|
+
expected_message = <<-END_OF_MESSAGE
|
52
|
+
Could not find profile: 'i_do_not_exist'
|
53
|
+
|
54
|
+
Defined profiles in cucumber.yml:
|
55
|
+
* default
|
56
|
+
* html_report
|
57
|
+
END_OF_MESSAGE
|
58
|
+
|
59
|
+
error.string.should == expected_message
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should provide a helpful error message when a specified profile is not a String" do
|
63
|
+
cli = CLI.new(StringIO.new, error = StringIO.new)
|
64
|
+
|
65
|
+
given_cucumber_yml_defined_as({'foo' => [1,2,3]})
|
66
|
+
|
67
|
+
cli.parse_options!(%w{--profile foo})
|
68
|
+
|
69
|
+
error.string.should == "Profiles must be defined as a String. The 'foo' profile was [1, 2, 3] (Array).\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should provide a helpful error message when no YAML file exists and a profile is specified" do
|
73
|
+
cli = CLI.new(StringIO.new, error = StringIO.new)
|
74
|
+
|
75
|
+
File.should_receive(:exist?).with('cucumber.yml').and_return(false)
|
76
|
+
|
77
|
+
cli.parse_options!(%w{--profile i_do_not_exist})
|
78
|
+
|
79
|
+
error.string.should match(/cucumber.yml was not found. Please define your 'i_do_not_exist' and other profiles in cucumber.yml./)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should accept --no-source option" do
|
83
|
+
cli = CLI.new
|
84
|
+
cli.parse_options!(%w{--no-source})
|
85
|
+
|
86
|
+
cli.options[:source].should be_false
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should accept --no-snippets option" do
|
90
|
+
cli = CLI.new
|
91
|
+
cli.parse_options!(%w{--no-snippets})
|
92
|
+
|
93
|
+
cli.options[:snippets].should be_false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should accept --quiet option" do
|
97
|
+
cli = CLI.new
|
98
|
+
cli.parse_options!(%w{--quiet})
|
99
|
+
|
100
|
+
cli.options[:snippets].should be_false
|
101
|
+
cli.options[:source].should be_false
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should accept --out option" do
|
105
|
+
cli = CLI.new
|
106
|
+
File.should_receive(:open).with('jalla.txt', 'w')
|
107
|
+
cli.parse_options!(%w{--out jalla.txt})
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should accept multiple --out options" do
|
111
|
+
cli = CLI.new
|
112
|
+
mock_file1 = stub(File, :open => nil)
|
113
|
+
mock_file2 = stub(File, :open => nil)
|
114
|
+
File.stub!(:open).and_return(mock_file1, mock_file2)
|
115
|
+
|
116
|
+
cli.parse_options!(%w{--format progress --out file1 --out file2})
|
117
|
+
cli.options[:formats].should == {'progress' => [mock_file1, mock_file2]}
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should accept multiple --format options" do
|
121
|
+
cli = CLI.new
|
122
|
+
cli.parse_options!(%w{--format pretty --format progress})
|
123
|
+
cli.options[:formats].should have_key('pretty')
|
124
|
+
cli.options[:formats].should have_key('progress')
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should associate --out to previous --format" do
|
128
|
+
cli = CLI.new
|
129
|
+
mock_file1 = stub(File, :open => nil)
|
130
|
+
mock_file2 = stub(File, :open => nil)
|
131
|
+
File.stub!(:open).and_return(mock_file1, mock_file2)
|
132
|
+
|
133
|
+
cli.parse_options!(%w{--format progress --out file1 --format profile --out file2})
|
134
|
+
cli.options[:formats].should == {'progress' => [mock_file1], 'profile' => [mock_file2]}
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should allow a single formatter to have STDOUT and a file" do
|
138
|
+
cli = CLI.new
|
139
|
+
mock_file = stub(File, :open => nil)
|
140
|
+
File.stub!(:open).and_return(mock_file)
|
141
|
+
|
142
|
+
cli.parse_options!(%w{--format progress --format progress --out file})
|
143
|
+
cli.options[:formats].should == {'progress' => [STDOUT, mock_file]}
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should register --out files with an output broadcaster" do
|
147
|
+
cli = CLI.new
|
148
|
+
mock_file = stub(File)
|
149
|
+
File.stub!(:open).and_return(mock_file)
|
150
|
+
mock_output_broadcaster = mock_broadcaster
|
151
|
+
Broadcaster.stub!(:new).and_return(mock_broadcaster, mock_output_broadcaster)
|
152
|
+
|
153
|
+
mock_output_broadcaster.should_receive(:register).with(mock_file)
|
154
|
+
cli.parse_options!(%w{--out test.file})
|
155
|
+
|
156
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should register --formatters with the formatter broadcaster" do
|
160
|
+
cli = CLI.new
|
161
|
+
mock_progress_formatter = stub(Formatters::ProgressFormatter)
|
162
|
+
Formatters::ProgressFormatter.stub!(:new).and_return(mock_progress_formatter)
|
163
|
+
mock_formatter_broadcaster = mock_broadcaster
|
164
|
+
Broadcaster.stub!(:new).and_return(mock_formatter_broadcaster, mock_broadcaster)
|
165
|
+
|
166
|
+
mock_formatter_broadcaster.should_receive(:register).with(mock_progress_formatter)
|
167
|
+
cli.parse_options!(%w{--format progress})
|
168
|
+
|
169
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should setup the executor with the formatter broadcaster" do
|
173
|
+
cli = CLI.new
|
174
|
+
broadcaster = Broadcaster.new
|
175
|
+
Broadcaster.stub!(:new).and_return(broadcaster)
|
176
|
+
mock_executor = mock_executor()
|
177
|
+
mock_executor.should_receive(:formatters=).with(broadcaster)
|
178
|
+
cli.parse_options!(%w{--format progress})
|
179
|
+
|
180
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should accept multiple --scenario options" do
|
184
|
+
cli = CLI.new
|
185
|
+
cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
|
186
|
+
cli.options[:scenario_names].should include("User logs in")
|
187
|
+
cli.options[:scenario_names].should include("User signs up")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should register --scenario options with the executor" do
|
191
|
+
cli = CLI.new
|
192
|
+
cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
|
193
|
+
executor = mock_executor
|
194
|
+
executor.should_receive(:scenario_names=).with(["User logs in", "User signs up"])
|
195
|
+
cli.execute!(stub('step mother'), executor, stub('features'))
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should accept --color option" do
|
199
|
+
cli = CLI.new
|
200
|
+
cli.parse_options!(['--color'])
|
201
|
+
cli.options[:color].should == true
|
202
|
+
Term::ANSIColor.should_receive(:coloring=).with(true)
|
203
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should accept --no-color option" do
|
207
|
+
cli = CLI.new
|
208
|
+
cli.parse_options!(['--no-color'])
|
209
|
+
cli.options[:color].should == false
|
210
|
+
Term::ANSIColor.should_receive(:coloring=).with(false)
|
211
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should accept --color and --no-color and use the last one" do
|
215
|
+
cli = CLI.new
|
216
|
+
cli.parse_options!(['--color', '--no-color'])
|
217
|
+
cli.options[:color].should == false
|
218
|
+
Term::ANSIColor.should_receive(:coloring=).with(false)
|
219
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should use a default color setting if no option is given" do
|
223
|
+
cli = CLI.new
|
224
|
+
cli.parse_options!(['--'])
|
225
|
+
cli.options[:color].should == nil
|
226
|
+
Term::ANSIColor.should_not_receive(:coloring=)
|
227
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features'))
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should search for all features in the specified directory" do
|
231
|
+
cli = CLI.new
|
232
|
+
|
233
|
+
cli.parse_options!(%w{feature_directory/})
|
234
|
+
File.stub!(:directory?).and_return(true)
|
235
|
+
|
236
|
+
Dir.should_receive(:[]).with("feature_directory/**/*.feature").any_number_of_times.and_return([])
|
237
|
+
|
238
|
+
cli.execute!(stub('step mother'), mock_executor, stub('features', :<< => nil))
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
module Cucumber
|
4
|
+
module CoreExt
|
5
|
+
describe "proc extended with CallIn" do
|
6
|
+
it "should raise ArityMismatchError for too many args (expecting 0)" do
|
7
|
+
proc = lambda {}
|
8
|
+
proc.extend CallIn
|
9
|
+
lambda {
|
10
|
+
proc.call_in(Object.new, 1)
|
11
|
+
}.should raise_error(Cucumber::ArityMismatchError, "expected 0 block argument(s), got 1")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should raise ArityMismatchError for too many args (expecting 1)" do
|
15
|
+
proc = lambda {|a|}
|
16
|
+
proc.extend CallIn
|
17
|
+
lambda {
|
18
|
+
proc.call_in(Object.new, 1, 2)
|
19
|
+
}.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 2")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise ArityMismatchError for too few args (expecting 1)" do
|
23
|
+
proc = lambda {|a|}
|
24
|
+
proc.extend CallIn
|
25
|
+
lambda {
|
26
|
+
proc.call_in(Object.new)
|
27
|
+
}.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 0")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise ArityMismatchError for too few args (expecting 2)" do
|
31
|
+
proc = lambda {|a,b|}
|
32
|
+
proc.extend CallIn
|
33
|
+
lambda {
|
34
|
+
proc.call_in(Object.new, 1)
|
35
|
+
}.should raise_error(Cucumber::ArityMismatchError, "expected 2 block argument(s), got 1")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should remove extraneous path info for file" do
|
39
|
+
proc = lambda {|a,b|}
|
40
|
+
proc.extend CallIn
|
41
|
+
proc.file_colon_line.should == "spec/cucumber/core_ext/proc_spec.rb:39"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../lib/cucumber/core_ext/string'
|
2
|
+
|
3
|
+
describe String, "#gzub" do
|
4
|
+
it "should format groups with format string" do
|
5
|
+
"I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "<span>%s</span>").should ==
|
6
|
+
"I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should format groups with format string when there are dupes" do
|
10
|
+
"I bob 1 bo this bobs".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "<span>%s</span>").should ==
|
11
|
+
"I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should format groups with block" do
|
15
|
+
f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
|
16
|
+
"<span>#{m}</span>"
|
17
|
+
end
|
18
|
+
f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should format groups with block with not all placeholders having a value" do
|
22
|
+
f = "another member named Bob joins the group".gzub(/(a|another) (user|member) named ([^ ]+)( who is not logged in)?/) do |m|
|
23
|
+
"<span>#{m}</span>"
|
24
|
+
end
|
25
|
+
f.should == "<span>another</span> <span>member</span> named <span>Bob</span> joins the group"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should format match groups in a textile table row" do
|
29
|
+
f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
|
30
|
+
"<span>#{m}</span>"
|
31
|
+
end
|
32
|
+
f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
describe Executor do
|
6
|
+
before do # TODO: Way more setup and duplication of lib code. Use lib code!
|
7
|
+
@io = StringIO.new
|
8
|
+
@step_mother = StepMother.new
|
9
|
+
@executor = Executor.new(@step_mother)
|
10
|
+
@formatters = Broadcaster.new [Formatters::ProgressFormatter.new(@io)]
|
11
|
+
@executor.formatters = @formatters
|
12
|
+
@feature_file = File.dirname(__FILE__) + '/sell_cucumbers.feature'
|
13
|
+
@parser = TreetopParser::FeatureParser.new
|
14
|
+
@features = Tree::Features.new
|
15
|
+
@feature = @parser.parse_feature(@feature_file)
|
16
|
+
@features << @feature
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should pass when blocks are ok" do
|
20
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) { |n| @n = n.to_i }
|
21
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| @n -= n.to_i }
|
22
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| @n.should == -n.to_i }
|
23
|
+
@executor.visit_features(@features)
|
24
|
+
@formatters.dump
|
25
|
+
|
26
|
+
@io.string.should =~ (/\.+\n+/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should print filtered backtrace with feature line" do
|
30
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) { |n| @n = n }
|
31
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| @n = n }
|
32
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| raise "dang" }
|
33
|
+
@executor.visit_features(@features)
|
34
|
+
@io.string.should include(%{Failed:
|
35
|
+
|
36
|
+
1)
|
37
|
+
dang
|
38
|
+
#{__FILE__}:32:in `Then /I should owe (\\d*) cucumbers/'
|
39
|
+
#{@feature_file}:9:in `Then I should owe 7 cucumbers'
|
40
|
+
})
|
41
|
+
end
|
42
|
+
|
43
|
+
# it "should allow calling of other steps from steps" do
|
44
|
+
# @executor.register_step_proc("call me please") { @x = 1 }
|
45
|
+
# @executor.register_step_proc("I will call you") { @executor.register_step_proc("call me please") }
|
46
|
+
# @executor.register_step_proc(/I should owe (\d*) cucumbers/) { |n| @n.should == -n.to_i }
|
47
|
+
# @feature.accept(@executor)
|
48
|
+
# @formatters.each { |formatter| formatter.dump }
|
49
|
+
# @io.string.should == "...\n"
|
50
|
+
# end
|
51
|
+
|
52
|
+
describe "visiting steps" do
|
53
|
+
def make_regex(a,b,c)
|
54
|
+
exp = "#{a}.*#{b}.*#{c}"
|
55
|
+
Regexp.compile(exp)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should report multiple definitions as an error" do
|
59
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {|n|}
|
60
|
+
@step_mother.register_step_proc(/there (.*) (\d*) cucumbers/) {|n|}
|
61
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n|}
|
62
|
+
@executor.visit_features(@features)
|
63
|
+
@io.string.should =~ make_regex('F','_','P')
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should report subsequent multiple definitions as an skipped" do
|
67
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {|n|}
|
68
|
+
@step_mother.register_step_proc(/there (.*) (\d*) cucumbers/) {|n|}
|
69
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n|}
|
70
|
+
@step_mother.register_step_proc(/I sell (\d*) (.*)/) {|n|}
|
71
|
+
@executor.visit_features(@features)
|
72
|
+
@io.string.should =~ make_regex('F','_','P')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should report pending steps after failures" do
|
76
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {|n|}
|
77
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n| raise "oops"}
|
78
|
+
@executor.visit_features(@features)
|
79
|
+
@io.string.should =~ make_regex('\.','F','P')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should skip passing steps after failures" do
|
83
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {|n|}
|
84
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n| raise "oops"}
|
85
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) {|n|}
|
86
|
+
@executor.visit_features(@features)
|
87
|
+
@io.string.should =~ make_regex('\.','F','_')
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should skip failing steps after failures" do
|
91
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {|n|}
|
92
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n| raise "oops"}
|
93
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) {|n| raise "oops again"}
|
94
|
+
@executor.visit_features(@features)
|
95
|
+
@io.string.should =~ make_regex('\.','F','_')
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
it "should report pending steps after pending" do
|
100
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n|}
|
101
|
+
@executor.visit_features(@features)
|
102
|
+
@io.string.should =~ make_regex('P','_','P')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should skip passing steps after pending" do
|
106
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n|}
|
107
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) {|n|}
|
108
|
+
@executor.visit_features(@features)
|
109
|
+
@io.string.should =~ make_regex('P','_','_')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should skip failing steps after pending" do
|
113
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) {|n| raise "oops"}
|
114
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) {|n| raise "oops again"}
|
115
|
+
@executor.visit_features(@features)
|
116
|
+
@io.string.should =~ make_regex('P','_','_')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should report an ArityMismatchError" do
|
120
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) {}
|
121
|
+
@executor.visit_features(@features)
|
122
|
+
@io.string.should =~ /expected 0 block argument\(s\), got 1/m
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "visiting row scenarios" do
|
128
|
+
|
129
|
+
def mock_row_scenario(stubs = {})
|
130
|
+
@row_scenario ||= stub("row scenario", {
|
131
|
+
:row? => true,
|
132
|
+
:name => 'test',
|
133
|
+
:update_table_column_widths => nil,
|
134
|
+
:steps => [],
|
135
|
+
:pending? => true
|
136
|
+
}.merge(stubs))
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "without having first run the matching regular scenario" do
|
140
|
+
|
141
|
+
before(:each) do
|
142
|
+
@scenario = Tree::Scenario.new(nil, 'test', 1)
|
143
|
+
@executor.line=5
|
144
|
+
@executor.visit_regular_scenario(@scenario)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should run the regular scenario before the row scenario" do
|
148
|
+
@scenario.should_receive(:accept)
|
149
|
+
|
150
|
+
@executor.visit_row_scenario(mock_row_scenario(:name => 'test', :at_line? => true, :accept => nil))
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should run the row scenario after running the regular scenario" do
|
154
|
+
mock_row_scenario(:at_line? => true).should_receive(:accept)
|
155
|
+
|
156
|
+
@executor.visit_row_scenario(mock_row_scenario)
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "having run matching regular scenario" do
|
162
|
+
|
163
|
+
it "should not run the regular scenario if it has already run" do
|
164
|
+
scenario = Tree::Scenario.new(nil, 'test', 1)
|
165
|
+
@executor.visit_regular_scenario(scenario)
|
166
|
+
|
167
|
+
scenario.should_not_receive(:accept)
|
168
|
+
|
169
|
+
@executor.visit_row_scenario(mock_row_scenario(:name => 'test', :at_line? => true, :accept => nil))
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "caching visited scenarios" do
|
176
|
+
|
177
|
+
def mock_scenario(stubs = {})
|
178
|
+
@scenario ||= stub("scenario", {
|
179
|
+
:row? => false,
|
180
|
+
:name => 'test',
|
181
|
+
:accept => nil,
|
182
|
+
:steps => [],
|
183
|
+
:pending? => true
|
184
|
+
}.merge(stubs))
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should reset cache after each feature visit" do
|
188
|
+
Tree::Scenario.stub!(:new).and_return(mock_scenario)
|
189
|
+
|
190
|
+
feature = Tree::Feature.new(nil)
|
191
|
+
feature.add_scenario(nil, nil)
|
192
|
+
|
193
|
+
@executor.visit_feature(feature)
|
194
|
+
|
195
|
+
@executor.instance_variable_get("@regular_scenario_cache").should == {}
|
196
|
+
@executor.instance_variable_get("@executed_scenarios").should == {}
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "with specified scenarios" do
|
202
|
+
it "should only visit the specified scenarios" do
|
203
|
+
$amounts_sold = []
|
204
|
+
|
205
|
+
@step_mother.register_step_proc(/there are (\d*) cucumbers/) { |n| }
|
206
|
+
@step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| }
|
207
|
+
@step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| $amounts_sold << n.to_i }
|
208
|
+
|
209
|
+
@executor.scenario_names = ["Sell a dozen", "Sell fifty"]
|
210
|
+
@executor.visit_features(@features)
|
211
|
+
|
212
|
+
$amounts_sold.should == [12, 50]
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should only visit features with specified scenarios" do
|
216
|
+
@executor.scenario_names = ["Jump up and down"]
|
217
|
+
@feature.should_not_receive(:accept).with(@executor)
|
218
|
+
@executor.visit_features(@features)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|