aslakhellesoy-cucumber 0.3.92 → 0.3.93

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,11 @@ module Cucumber
21
21
  def has_tags?(tag_names)
22
22
  tags.has_tags?(tag_names)
23
23
  end
24
-
24
+
25
+ def has_all_tags?(tag_names)
26
+ tags.has_all_tags?(tag_names)
27
+ end
28
+
25
29
  def build(filter)
26
30
  if(filter.nil? || feature_elements.accept?(filter) || (!bg.empty? && filter.accept?(bg)))
27
31
  background = bg.respond_to?(:build) ? bg.build : nil
@@ -47,6 +51,10 @@ module Cucumber
47
51
  (tag_names & tags).any?
48
52
  end
49
53
 
54
+ def has_all_tags?(tags)
55
+ (tags & tag_names) == tags
56
+ end
57
+
50
58
  def build
51
59
  Ast::Tags.new(ts.line, tag_names)
52
60
  end
@@ -89,6 +97,11 @@ module Cucumber
89
97
  feature_tags.has_tags?(tag_names)
90
98
  end
91
99
 
100
+ def has_all_tags?(tag_names)
101
+ feature_tags = self.parent.tags
102
+ feature_tags.has_all_tags?(tag_names)
103
+ end
104
+
92
105
  def build
93
106
  Ast::Background.new(
94
107
  comment.build,
@@ -130,6 +143,11 @@ module Cucumber
130
143
  tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
131
144
  end
132
145
 
146
+ def has_all_tags?(tag_names)
147
+ feature_tags = self.parent.parent.tags
148
+ tags.has_all_tags?(tag_names) || feature_tags.has_all_tags?(tag_names)
149
+ end
150
+
133
151
  def matches_name?(regexp_to_match)
134
152
  name.build =~ regexp_to_match
135
153
  end
@@ -166,6 +184,11 @@ module Cucumber
166
184
  tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
167
185
  end
168
186
 
187
+ def has_all_tags?(tag_names)
188
+ feature_tags = self.parent.parent.tags
189
+ tags.has_all_tags?(tag_names) || feature_tags.has_all_tags?(tag_names)
190
+ end
191
+
169
192
  def matches_name?(regexp_to_match)
170
193
  outline_matches_name?(regexp_to_match) || examples_sections.matches_name?(regexp_to_match)
171
194
  end
@@ -249,6 +272,10 @@ module Cucumber
249
272
  true
250
273
  end
251
274
 
275
+ def has_all_tags?(tag_names)
276
+ true
277
+ end
278
+
252
279
  def outline_at_line?(line)
253
280
  true
254
281
  end
@@ -47,6 +47,10 @@ module Cucumber
47
47
  Treetop.load_from_string(grammar)
48
48
  self.class.alias_step_definitions(@keywords)
49
49
  @parser = Parser::I18n.const_get("#{@keywords['grammar_name']}Parser").new
50
+ def @parser.inspect
51
+ "#<#{self.class.name}>"
52
+ end
53
+ @parser
50
54
  end
51
55
 
52
56
  def parse(source, path, filter)
@@ -49,7 +49,7 @@ module Cucumber
49
49
  end
50
50
  end
51
51
  if s0.empty?
52
- self.index = i0
52
+ @index = i0
53
53
  r0 = nil
54
54
  else
55
55
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
@@ -58,7 +58,7 @@ module Cucumber
58
58
 
59
59
  node_cache[:table][start_index] = r0
60
60
 
61
- return r0
61
+ r0
62
62
  end
63
63
 
64
64
  module TableRow0
@@ -116,7 +116,7 @@ module Cucumber
116
116
  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
117
117
  s0 << r1
118
118
  if r1
119
- if input.index('|', index) == index
119
+ if has_terminal?('|', false, index)
120
120
  r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
121
121
  @index += 1
122
122
  else
@@ -131,7 +131,7 @@ module Cucumber
131
131
  r6 = _nt_cell
132
132
  s5 << r6
133
133
  if r6
134
- if input.index('|', index) == index
134
+ if has_terminal?('|', false, index)
135
135
  r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
136
136
  @index += 1
137
137
  else
@@ -144,7 +144,7 @@ module Cucumber
144
144
  r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
145
145
  r5.extend(TableRow0)
146
146
  else
147
- self.index = i5
147
+ @index = i5
148
148
  r5 = nil
149
149
  end
150
150
  if r5
@@ -154,7 +154,7 @@ module Cucumber
154
154
  end
155
155
  end
156
156
  if s4.empty?
157
- self.index = i4
157
+ @index = i4
158
158
  r4 = nil
159
159
  else
160
160
  r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
@@ -184,7 +184,7 @@ module Cucumber
184
184
  end
185
185
  end
186
186
  if s11.empty?
187
- self.index = i11
187
+ @index = i11
188
188
  r11 = nil
189
189
  else
190
190
  r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
@@ -196,7 +196,7 @@ module Cucumber
196
196
  if r13
197
197
  r10 = r13
198
198
  else
199
- self.index = i10
199
+ @index = i10
200
200
  r10 = nil
201
201
  end
202
202
  end
@@ -210,13 +210,13 @@ module Cucumber
210
210
  r0.extend(TableRow1)
211
211
  r0.extend(TableRow2)
212
212
  else
213
- self.index = i0
213
+ @index = i0
214
214
  r0 = nil
215
215
  end
216
216
 
217
217
  node_cache[:table_row][start_index] = r0
218
218
 
219
- return r0
219
+ r0
220
220
  end
221
221
 
222
222
  module Cell0
@@ -235,7 +235,7 @@ module Cucumber
235
235
  i1, s1 = index, []
236
236
  i2 = index
237
237
  i3 = index
238
- if input.index('|', index) == index
238
+ if has_terminal?('|', false, index)
239
239
  r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
240
240
  @index += 1
241
241
  else
@@ -249,14 +249,14 @@ module Cucumber
249
249
  if r5
250
250
  r3 = r5
251
251
  else
252
- self.index = i3
252
+ @index = i3
253
253
  r3 = nil
254
254
  end
255
255
  end
256
256
  if r3
257
257
  r2 = nil
258
258
  else
259
- self.index = i2
259
+ @index = i2
260
260
  r2 = instantiate_node(SyntaxNode,input, index...index)
261
261
  end
262
262
  s1 << r2
@@ -274,7 +274,7 @@ module Cucumber
274
274
  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
275
275
  r1.extend(Cell0)
276
276
  else
277
- self.index = i1
277
+ @index = i1
278
278
  r1 = nil
279
279
  end
280
280
  if r1
@@ -287,7 +287,7 @@ module Cucumber
287
287
 
288
288
  node_cache[:cell][start_index] = r0
289
289
 
290
- return r0
290
+ r0
291
291
  end
292
292
 
293
293
  def _nt_space
@@ -298,7 +298,7 @@ module Cucumber
298
298
  return cached
299
299
  end
300
300
 
301
- if input.index(Regexp.new('[ \\t]'), index) == index
301
+ if has_terminal?('\G[ \\t]', true, index)
302
302
  r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
303
303
  @index += 1
304
304
  else
@@ -307,7 +307,7 @@ module Cucumber
307
307
 
308
308
  node_cache[:space][start_index] = r0
309
309
 
310
- return r0
310
+ r0
311
311
  end
312
312
 
313
313
  module Eol0
@@ -322,7 +322,7 @@ module Cucumber
322
322
  end
323
323
 
324
324
  i0 = index
325
- if input.index("\n", index) == index
325
+ if has_terminal?("\n", false, index)
326
326
  r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
327
327
  @index += 1
328
328
  else
@@ -333,7 +333,7 @@ module Cucumber
333
333
  r0 = r1
334
334
  else
335
335
  i2, s2 = index, []
336
- if input.index("\r", index) == index
336
+ if has_terminal?("\r", false, index)
337
337
  r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
338
338
  @index += 1
339
339
  else
@@ -342,7 +342,7 @@ module Cucumber
342
342
  end
343
343
  s2 << r3
344
344
  if r3
345
- if input.index("\n", index) == index
345
+ if has_terminal?("\n", false, index)
346
346
  r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
347
347
  @index += 1
348
348
  else
@@ -360,20 +360,20 @@ module Cucumber
360
360
  r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
361
361
  r2.extend(Eol0)
362
362
  else
363
- self.index = i2
363
+ @index = i2
364
364
  r2 = nil
365
365
  end
366
366
  if r2
367
367
  r0 = r2
368
368
  else
369
- self.index = i0
369
+ @index = i0
370
370
  r0 = nil
371
371
  end
372
372
  end
373
373
 
374
374
  node_cache[:eol][start_index] = r0
375
375
 
376
- return r0
376
+ r0
377
377
  end
378
378
 
379
379
  def _nt_eof
@@ -395,13 +395,13 @@ module Cucumber
395
395
  if r1
396
396
  r0 = nil
397
397
  else
398
- self.index = i0
398
+ @index = i0
399
399
  r0 = instantiate_node(SyntaxNode,input, index...index)
400
400
  end
401
401
 
402
402
  node_cache[:eof][start_index] = r0
403
403
 
404
- return r0
404
+ r0
405
405
  end
406
406
 
407
407
  end
@@ -2,7 +2,7 @@ module Cucumber #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 92
5
+ TINY = 93
6
6
  PATCH = nil # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
@@ -4,7 +4,7 @@ module Webrat
4
4
  ".//table"
5
5
  end
6
6
 
7
- # Converts this Table element into a 2-dimensional array of String where each cell
7
+ # Converts this Table element into an Array of Array of String where each cell
8
8
  # represents the inner_html of the <td> and <th> elements. The number of columns is
9
9
  # determined by the number of cells in the first row.
10
10
  def to_a
@@ -20,7 +20,7 @@ class CucumberGenerator < Rails::Generator::Base
20
20
 
21
21
  m.directory 'features/support'
22
22
 
23
- if options[:spork]
23
+ if spork?
24
24
  m.template 'spork_env.rb', 'features/support/env.rb'
25
25
  else
26
26
  m.template 'env.rb', 'features/support/env.rb'
@@ -40,6 +40,10 @@ class CucumberGenerator < Rails::Generator::Base
40
40
  def framework
41
41
  options[:framework] || :rspec
42
42
  end
43
+
44
+ def spork?
45
+ options[:spork]
46
+ end
43
47
 
44
48
  protected
45
49
 
@@ -3,6 +3,7 @@ begin
3
3
  load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4
4
  rescue LoadError => e
5
5
  raise unless e.to_s =~ /cucumber/
6
- require "rubygems"
7
- load File.join(Gem.bindir, "cucumber")
6
+ require 'rubygems'
7
+ require 'cucumber'
8
+ load Cucumber::BINARY
8
9
  end
@@ -15,9 +15,12 @@ config.action_controller.allow_forgery_protection = false
15
15
  # ActionMailer::Base.deliveries array.
16
16
  config.action_mailer.delivery_method = :test
17
17
 
18
- config.gem "cucumber", :lib => false, :version => ">=<%= cucumber_version %>" unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
- config.gem "webrat", :lib => false, :version => ">=0.4.4" unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
18
+ config.gem 'cucumber', :lib => false, :version => '>=<%= cucumber_version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
+ config.gem 'webrat', :lib => false, :version => '>=0.4.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
20
20
  <% if framework == :rspec -%>
21
- config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
22
- config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
21
+ config.gem 'rspec', :lib => false, :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
22
+ config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
23
+ <% end %>
24
+ <% if spork? -%>
25
+ config.gem 'spork', :lib => false, :version => '>=0.5.7' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
23
26
  <% end %>
@@ -19,6 +19,10 @@ When /^I follow "([^\"]*)"$/ do |link|
19
19
  click_link(link)
20
20
  end
21
21
 
22
+ When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
23
+ click_link_within(parent, link)
24
+ end
25
+
22
26
  When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23
27
  fill_in(field, :with => value)
24
28
  end
@@ -17,13 +17,25 @@ module Cli
17
17
  end
18
18
 
19
19
  before(:each) do
20
+ #given_cucumber_yml_defined_as({'default' => '-q'})
21
+ File.stub!(:exist?).and_return(false) # Meaning, no cucumber.yml exists
20
22
  Kernel.stub!(:exit).and_return(nil)
21
23
  end
22
24
 
25
+ def config
26
+ @config ||= Configuration.new(@out = StringIO.new, @error = StringIO.new)
27
+ end
28
+
29
+ def reset_config
30
+ @config = nil
31
+ end
32
+
33
+ attr_reader :out, :error
34
+
35
+
23
36
  it "should require files in support paths first" do
24
37
  given_the_following_files("/features/step_definitions/foo.rb","/features/support/bar.rb")
25
38
 
26
- config = Configuration.new(StringIO.new)
27
39
  config.parse!(%w{--require /features})
28
40
 
29
41
  config.files_to_require.should == [
@@ -35,7 +47,6 @@ module Cli
35
47
  it "should require env.rb files first" do
36
48
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
37
49
 
38
- config = Configuration.new(StringIO.new)
39
50
  config.parse!(%w{--require /features})
40
51
 
41
52
  config.files_to_require.should == [
@@ -47,7 +58,6 @@ module Cli
47
58
  it "should not require env.rb files when --dry-run" do
48
59
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
49
60
 
50
- config = Configuration.new(StringIO.new)
51
61
  config.parse!(%w{--require /features --dry-run})
52
62
 
53
63
  config.files_to_require.should == [
@@ -59,7 +69,6 @@ module Cli
59
69
  given_the_following_files("/vendor/plugins/plugin_a/cucumber/foo.rb",
60
70
  "/vendor/gems/gem_a/cucumber/bar.rb")
61
71
 
62
- config = Configuration.new(StringIO.new)
63
72
  config.parse!(%w{--require /features})
64
73
 
65
74
  config.files_to_require.should == [
@@ -73,7 +82,6 @@ module Cli
73
82
  it "excludes a ruby file from requiring when the name matches exactly" do
74
83
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
75
84
 
76
- config = Configuration.new(StringIO.new)
77
85
  config.parse!(%w{--require /features --exclude a_file.rb})
78
86
 
79
87
  config.files_to_require.should == [
@@ -86,7 +94,6 @@ module Cli
86
94
  "/features/support/food.rb","/features/blah.rb",
87
95
  "/features/support/fooz.rb")
88
96
 
89
- config = Configuration.new(StringIO.new)
90
97
  config.parse!(%w{--require /features --exclude foo[df] --exclude blah})
91
98
 
92
99
  config.files_to_require.should == [
@@ -98,29 +105,23 @@ module Cli
98
105
 
99
106
  describe '#drb?' do
100
107
  it "indicates whether the --drb flag was passed in or not" do
101
- config = Configuration.new(StringIO.new)
102
-
103
108
  config.parse!(%w{features})
104
- config.drb?.should == false
109
+ config.should_not be_drb
105
110
 
106
111
 
107
112
  config.parse!(%w{features --drb})
108
- config.drb?.should == true
113
+ config.should be_drb
109
114
  end
110
115
  end
111
116
 
112
117
  context '--drb' do
113
118
  it "removes the --drb flag from the args" do
114
- config = Configuration.new(StringIO.new)
115
-
116
119
  args = %w{features --drb}
117
120
  config.parse!(args)
118
121
  args.should == %w{features}
119
122
  end
120
123
 
121
124
  it "keeps all other flags intact" do
122
- config = Configuration.new(StringIO.new)
123
-
124
125
  args = %w{features --drb --format profile}
125
126
  config.parse!(args)
126
127
  args.should == %w{features --format profile}
@@ -131,7 +132,6 @@ module Cli
131
132
  context '--drb in a profile' do
132
133
  it "removes the --drb flag from the args" do
133
134
  given_cucumber_yml_defined_as({'server' => '--drb features'})
134
- config = Configuration.new(StringIO.new)
135
135
 
136
136
  args = %w{--profile server}
137
137
  config.parse!(args)
@@ -142,11 +142,9 @@ module Cli
142
142
  given_cucumber_yml_defined_as({'server' => '--drb features --profile nested',
143
143
  'nested' => '--verbose'})
144
144
 
145
- config = Configuration.new(StringIO.new)
146
-
147
145
  args = %w{--profile server --format profile}
148
146
  config.parse!(args)
149
- args.should == %w{features --verbose --format profile}
147
+ args.should == %w{--format profile features --verbose}
150
148
  end
151
149
 
152
150
  end
@@ -154,35 +152,40 @@ module Cli
154
152
  context '--drb in the default profile and no arguments specified' do
155
153
  it "expands the profile's arguments into the args excpet for --drb" do
156
154
  given_cucumber_yml_defined_as({'default' => '--drb features --format pretty'})
157
- config = Configuration.new(StringIO.new)
158
155
  args = []
159
156
  config.parse!(args)
160
157
  args.should == %w{features --format pretty}
161
158
  end
162
159
  end
163
160
 
164
- it "should expand args from YAML file" do
165
- given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
161
+ it "uses the default profile when no profile is defined" do
162
+ given_cucumber_yml_defined_as({'default' => '--require some_file'})
166
163
 
167
- config = Configuration.new
168
- config.parse!(%w{--format progress --profile bongo})
169
- config.options[:formats].should == [['progress', STDOUT]]
170
- config.options[:require].should == ['from/yml']
164
+ config.parse!(%w{--format progress})
165
+ config.options[:require].should include('some_file')
171
166
  end
172
167
 
173
- it "should expand args from YAML file's default if there are no args" do
174
- given_cucumber_yml_defined_as({'default' => '--require from/yml'})
168
+ context '--profile' do
175
169
 
176
- config = Configuration.new
177
- config.parse!([])
178
- config.options[:require].should == ['from/yml']
179
- end
170
+ it "expands args from profiles in the cucumber.yml file" do
171
+ given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
172
+
173
+ config.parse!(%w{--format progress --profile bongo})
174
+ config.options[:formats].should == [['progress', out]]
175
+ config.options[:require].should == ['from/yml']
176
+ end
177
+
178
+ it "expands args from the default profile when no flags are provided" do
179
+ given_cucumber_yml_defined_as({'default' => '--require from/yml'})
180
+
181
+ config.parse!([])
182
+ config.options[:require].should == ['from/yml']
183
+ end
180
184
 
181
- it "should provide a helpful error message when a specified profile does not exists in YAML file" do
182
- given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
185
+ it "provides a helpful error message when a specified profile does not exists in cucumber.yml" do
186
+ given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
183
187
 
184
- config = Configuration.new(StringIO.new, error = StringIO.new)
185
- expected_message = <<-END_OF_MESSAGE
188
+ expected_message = <<-END_OF_MESSAGE
186
189
  Could not find profile: 'i_do_not_exist'
187
190
 
188
191
  Defined profiles in cucumber.yml:
@@ -190,141 +193,175 @@ Defined profiles in cucumber.yml:
190
193
  * html_report
191
194
  END_OF_MESSAGE
192
195
 
193
- lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_message)
194
- end
196
+ lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(ProfileNotFound, expected_message)
197
+ end
195
198
 
196
- it "should allow array as profile" do
197
- given_cucumber_yml_defined_as({'foo' => [1,2,3]})
199
+ it "allows profiles to be defined in arrays" do
200
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
198
201
 
199
- config = Configuration.new(StringIO.new, error = StringIO.new)
200
- config.parse!(%w{--profile foo})
201
- config.paths.should == [1,2,3]
202
- end
202
+ config.parse!(%w{--profile foo})
203
+ config.paths.should == [1,2,3]
204
+ end
203
205
 
204
- it "should provide a helpful error message when a specified profile exists but is nil or blank" do
205
- [nil, ' '].each do |bad_input|
206
- given_cucumber_yml_defined_as({'foo' => bad_input})
206
+ it "notifies the user that an individual profile is being used" do
207
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
207
208
 
208
- config = Configuration.new(StringIO.new, error = StringIO.new)
209
- expected_error = /The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml./
210
- lambda{config.parse!(%w{--profile foo})}.should raise_error(expected_error)
209
+ config.parse!(%w{--profile foo})
210
+ out.string.should =~ /Using the foo profile...\n/
211
211
  end
212
- end
213
212
 
214
- it "should provide a helpful error message when no YAML file exists and a profile is specified" do
215
- File.should_receive(:exist?).with('cucumber.yml').and_return(false)
213
+ it "notifies the user when multiple profiles are being used" do
214
+ given_cucumber_yml_defined_as({'foo' => [1,2,3], 'bar' => ['v'], 'dog' => ['v']})
216
215
 
217
- config = Configuration.new(StringIO.new, error = StringIO.new)
218
- expected_error = /cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml./
219
- lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_error)
220
- end
216
+ config.parse!(%w{--profile foo --profile bar})
217
+ out.string.should =~ /Using the foo and bar profiles...\n/
221
218
 
222
- it "should provide a helpful error message when cucumber.yml is blank or malformed" do
223
- expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
219
+ reset_config
224
220
 
225
- ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
226
- given_cucumber_yml_defined_as(bad_input)
221
+ config.parse!(%w{--profile foo --profile bar --profile dog})
222
+ out.string.should =~ /Using the foo, bar and dog profiles...\n/
223
+ end
227
224
 
228
- config = Configuration.new(StringIO.new, error = StringIO.new)
229
- lambda{config.parse!([])}.should raise_error(expected_error_message)
225
+ it "disregards paths in profiles when other paths are passed in (via cmd line)" do
226
+ given_cucumber_yml_defined_as({'foo' => %w[-v features]})
227
+
228
+ config.parse!(%w{--profile foo features/specific.feature --format pretty})
229
+ config.paths.should == ['features/specific.feature']
230
230
  end
231
- end
232
231
 
233
- it "should procide a helpful error message when the YAML can not be parsed" do
234
- expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./
232
+ it "disregards default STDOUT formatter defined in profile when another is passed in (via cmd line)" do
233
+ given_cucumber_yml_defined_as({'foo' => %w[--format pretty]})
234
+ config.parse!(%w{--format progress --profile foo})
235
+ config.options[:formats].should == [['progress', out]]#, ['pretty', 'pretty.txt']]
236
+ end
237
+
238
+
239
+
240
+ ["--no-profile", "-P"].each do |flag|
241
+
242
+ context 'when none is specified with #{flag}' do
235
243
 
236
- given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
237
- YAML.should_receive(:load).and_raise ArgumentError
244
+ it "disables profiles" do
245
+ given_cucumber_yml_defined_as({'default' => '-v --require file_specified_in_default_profile.rb'})
238
246
 
239
- config = Configuration.new(StringIO.new, error = StringIO.new)
240
- lambda{config.parse!([])}.should raise_error(expected_error_message)
247
+ config.parse!("#{flag} --require some_file.rb".split(" "))
248
+ config.options[:require].should == ['some_file.rb']
249
+ end
250
+
251
+ it "notifies the user that the profiles are being disabled" do
252
+ given_cucumber_yml_defined_as({'default' => '-v'})
253
+
254
+ config.parse!("#{flag} --require some_file.rb".split(" "))
255
+ out.string.should =~ /Disabling profiles.../
256
+ end
257
+
258
+ end
259
+
260
+ end
261
+
262
+
263
+
264
+ it "issues a helpful error message when a specified profile exists but is nil or blank" do
265
+ [nil, ' '].each do |bad_input|
266
+ given_cucumber_yml_defined_as({'foo' => bad_input})
267
+
268
+ expected_error = /The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml./
269
+ lambda{config.parse!(%w{--profile foo})}.should raise_error(expected_error)
270
+ end
271
+ end
272
+
273
+ it "issues a helpful error message when no YAML file exists and a profile is specified" do
274
+ File.should_receive(:exist?).with('cucumber.yml').and_return(false)
275
+
276
+ expected_error = /cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml./
277
+ lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_error)
278
+ end
279
+
280
+ it "issues a helpful error message when cucumber.yml is blank or malformed" do
281
+ expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
282
+
283
+ ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
284
+ given_cucumber_yml_defined_as(bad_input)
285
+ lambda{config.parse!([])}.should raise_error(expected_error_message)
286
+ reset_config
287
+ end
288
+ end
289
+
290
+ it "issues a helpful error message when cucumber.yml can not be parsed" do
291
+ expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./
292
+
293
+ given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
294
+ YAML.should_receive(:load).and_raise ArgumentError
295
+
296
+ lambda{config.parse!([])}.should raise_error(expected_error_message)
297
+ end
241
298
  end
242
299
 
300
+
243
301
  it "should accept --dry-run option" do
244
- config = Configuration.new(StringIO.new)
245
302
  config.parse!(%w{--dry-run})
246
303
  config.options[:dry_run].should be_true
247
304
  end
248
305
 
249
306
  it "should accept --no-source option" do
250
- config = Configuration.new
251
307
  config.parse!(%w{--no-source})
252
308
 
253
309
  config.options[:source].should be_false
254
310
  end
255
311
 
256
312
  it "should accept --no-snippets option" do
257
- config = Configuration.new
258
313
  config.parse!(%w{--no-snippets})
259
314
 
260
315
  config.options[:snippets].should be_false
261
316
  end
262
317
 
263
318
  it "should set snippets and source to false with --quiet option" do
264
- config = Configuration.new
265
319
  config.parse!(%w{--quiet})
266
320
 
267
- config.options[:snippets].should be_nil
268
- config.options[:source].should be_nil
321
+ config.options[:snippets].should be_false
322
+ config.options[:source].should be_false
269
323
  end
270
324
 
271
325
  it "should accept --verbose option" do
272
- config = Configuration.new
273
326
  config.parse!(%w{--verbose})
274
327
 
275
328
  config.options[:verbose].should be_true
276
329
  end
277
330
 
278
331
  it "should accept --out option" do
279
- config = Configuration.new(StringIO.new)
280
332
  config.parse!(%w{--out jalla.txt})
281
333
  config.options[:formats].should == [['pretty', 'jalla.txt']]
282
334
  end
283
335
 
284
336
  it "should accept multiple --out options" do
285
- config = Configuration.new(StringIO.new)
286
337
  config.parse!(%w{--format progress --out file1 --out file2})
287
338
  config.options[:formats].should == [['progress', 'file2']]
288
339
  end
289
340
 
290
341
  it "should accept multiple --format options and put the STDOUT one first so progress is seen" do
291
- io = StringIO.new
292
- config = Configuration.new(io)
293
342
  config.parse!(%w{--format pretty --out pretty.txt --format progress})
294
- config.options[:formats].should == [['progress', io], ['pretty', 'pretty.txt']]
343
+ config.options[:formats].should == [['progress', out], ['pretty', 'pretty.txt']]
295
344
  end
296
345
 
297
346
  it "should not accept multiple --format options when both use implicit STDOUT" do
298
- io = StringIO.new
299
- config = Configuration.new(io)
300
347
  lambda do
301
348
  config.parse!(%w{--format pretty --format progress})
302
349
  end.should raise_error("All but one formatter must use --out, only one can print to STDOUT")
303
350
  end
304
351
 
305
352
  it "should associate --out to previous --format" do
306
- config = Configuration.new(StringIO.new)
307
353
  config.parse!(%w{--format progress --out file1 --format profile --out file2})
308
354
  config.options[:formats].should == [["progress", "file1"], ["profile" ,"file2"]]
309
355
  end
310
356
 
311
357
  it "should accept --color option" do
312
358
  Term::ANSIColor.should_receive(:coloring=).with(true)
313
- config = Configuration.new(StringIO.new)
314
359
  config.parse!(['--color'])
315
360
  end
316
361
 
317
362
  it "should accept --no-color option" do
318
363
  Term::ANSIColor.should_receive(:coloring=).with(false)
319
- config = Configuration.new(StringIO.new)
320
- config.parse!(['--no-color'])
321
- end
322
-
323
- it "should parse tags" do
324
- config = Configuration.new(nil)
325
- includes, excludes = config.parse_tags("one,~two,@three,~@four")
326
- includes.should == ['one', 'three']
327
- excludes.should == ['two', 'four']
364
+ config.parse!(%w[--no-color])
328
365
  end
329
366
 
330
367
  describe "--backtrace" do
@@ -349,12 +386,10 @@ END_OF_MESSAGE
349
386
  describe "diff output" do
350
387
 
351
388
  it "is enabled by default" do
352
- config = Configuration.new
353
389
  config.diff_enabled?.should be_true
354
390
  end
355
391
 
356
392
  it "is disabled when the --no-diff option is supplied" do
357
- config = Configuration.new
358
393
  config.parse!(%w{--no-diff})
359
394
 
360
395
  config.diff_enabled?.should be_false
@@ -363,7 +398,6 @@ END_OF_MESSAGE
363
398
  end
364
399
 
365
400
  it "should accept multiple --name options" do
366
- config = Configuration.new
367
401
  config.parse!(['--name', "User logs in", '--name', "User signs up"])
368
402
 
369
403
  config.options[:name_regexps].should include(/User logs in/)
@@ -371,7 +405,6 @@ END_OF_MESSAGE
371
405
  end
372
406
 
373
407
  it "should accept multiple -n options" do
374
- config = Configuration.new
375
408
  config.parse!(['-n', "User logs in", '-n', "User signs up"])
376
409
 
377
410
  config.options[:name_regexps].should include(/User logs in/)
@@ -383,22 +416,19 @@ END_OF_MESSAGE
383
416
  Dir.should_receive(:[]).with("feature_directory/**/*.feature").
384
417
  any_number_of_times.and_return(["cucumber.feature"])
385
418
 
386
- config = Configuration.new(StringIO)
387
419
  config.parse!(%w{feature_directory/})
388
420
 
389
421
  config.feature_files.should == ["cucumber.feature"]
390
422
  end
391
423
 
392
424
  it "should allow specifying environment variables on the command line" do
393
- config = Configuration.new
394
425
  config.parse!(["foo=bar"])
395
426
  ENV["foo"].should == "bar"
396
427
  config.feature_files.should == []
397
428
  end
398
-
429
+
399
430
  it "should allow specifying environment variables in profiles" do
400
431
  given_cucumber_yml_defined_as({'selenium' => 'RAILS_ENV=selenium'})
401
- config = Configuration.new
402
432
  config.parse!(["--profile", "selenium"])
403
433
  ENV["RAILS_ENV"].should == "selenium"
404
434
  config.feature_files.should == []