rspec 0.9.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGES +24 -0
  2. data/EXAMPLES.rd +6 -2
  3. data/README +9 -9
  4. data/Rakefile +32 -29
  5. data/examples/not_yet_implemented_spec.rb +12 -0
  6. data/examples/shared_behaviours_example.rb +8 -0
  7. data/examples/stack_spec.rb +1 -0
  8. data/lib/spec/dsl/behaviour.rb +21 -6
  9. data/lib/spec/dsl/behaviour_callbacks.rb +44 -26
  10. data/lib/spec/dsl/behaviour_eval.rb +21 -12
  11. data/lib/spec/dsl/behaviour_factory.rb +23 -13
  12. data/lib/spec/dsl/configuration.rb +85 -5
  13. data/lib/spec/dsl/description.rb +14 -6
  14. data/lib/spec/dsl/example.rb +2 -2
  15. data/lib/spec/matchers.rb +5 -5
  16. data/lib/spec/matchers/be.rb +16 -0
  17. data/lib/spec/matchers/operator_matcher.rb +21 -1
  18. data/lib/spec/matchers/raise_error.rb +1 -1
  19. data/lib/spec/rake/verify_rcov.rb +5 -1
  20. data/lib/spec/runner.rb +7 -27
  21. data/lib/spec/runner/behaviour_runner.rb +1 -1
  22. data/lib/spec/runner/extensions/kernel.rb +20 -0
  23. data/lib/spec/runner/formatter/base_formatter.rb +6 -1
  24. data/lib/spec/runner/formatter/base_text_formatter.rb +10 -2
  25. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +1 -1
  26. data/lib/spec/runner/formatter/failing_examples_formatter.rb +1 -1
  27. data/lib/spec/runner/formatter/html_formatter.rb +63 -31
  28. data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -0
  29. data/lib/spec/runner/formatter/rdoc_formatter.rb +4 -0
  30. data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -1
  31. data/lib/spec/runner/option_parser.rb +1 -1
  32. data/lib/spec/runner/reporter.rb +13 -4
  33. data/lib/spec/runner/spec_parser.rb +1 -1
  34. data/lib/spec/version.rb +5 -5
  35. data/spec/spec/dsl/behaviour_spec.rb +88 -24
  36. data/spec/spec/dsl/configuration_spec.rb +8 -1
  37. data/spec/spec/dsl/example_class_spec.rb +1 -1
  38. data/spec/spec/dsl/example_instance_spec.rb +5 -5
  39. data/spec/spec/dsl/shared_behaviour_spec.rb +24 -2
  40. data/spec/spec/matchers/be_spec.rb +20 -2
  41. data/spec/spec/matchers/operator_matcher_spec.rb +158 -0
  42. data/spec/spec/runner/command_line_spec.rb +5 -4
  43. data/spec/spec/runner/drb_command_line_spec.rb +15 -8
  44. data/spec/spec/runner/formatter/html_formatter_spec.rb +22 -5
  45. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +1 -1
  46. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +7 -2
  47. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +1 -1
  48. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +6 -1
  49. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +1 -1
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +15 -5
  51. data/spec/spec/runner/option_parser_spec.rb +5 -0
  52. data/spec/spec/runner/reporter_spec.rb +23 -5
  53. data/spec/spec/runner/spec_matcher_spec.rb +1 -1
  54. data/spec/spec/runner/spec_parser_spec.rb +1 -1
  55. data/spec/spec_helper.rb +38 -2
  56. metadata +41 -42
  57. data/spec/spec/matchers/should_===_spec.rb +0 -38
  58. data/spec/spec/matchers/should_==_spec.rb +0 -37
  59. data/spec/spec/matchers/should_=~_spec.rb +0 -36
@@ -17,7 +17,7 @@ module Spec
17
17
  def dump_failure(counter, failure)
18
18
  end
19
19
 
20
- def dump_summary(duration, example_count, failure_count)
20
+ def dump_summary(duration, example_count, failure_count, not_implemented_count)
21
21
  end
22
22
  end
23
23
  end
@@ -14,7 +14,7 @@ module Spec
14
14
  def dump_failure(counter, failure)
15
15
  end
16
16
 
17
- def dump_summary(duration, example_count, failure_count)
17
+ def dump_summary(duration, example_count, failure_count, not_implemented_count)
18
18
  end
19
19
  end
20
20
  end
@@ -70,6 +70,14 @@ module Spec
70
70
  @output.flush
71
71
  end
72
72
 
73
+ def example_not_implemented(name)
74
+ @current_example_number += 1
75
+ @output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>"
76
+ @output.puts " <script type=\"text/javascript\">makeYellow('behaviour_#{current_behaviour_number}');</script>"
77
+ move_progress
78
+ @output.puts " <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{escape(name)}</span></dd>"
79
+ @output.flush
80
+ end
73
81
  # Override this method if you wish to output extra HTML for a failed spec. For example, you
74
82
  # could output links to images or other files produced during the specs.
75
83
  #
@@ -90,11 +98,12 @@ module Spec
90
98
  def dump_failure(counter, failure)
91
99
  end
92
100
 
93
- def dump_summary(duration, example_count, failure_count)
101
+ def dump_summary(duration, example_count, failure_count, not_implemented_count)
94
102
  if @dry_run
95
103
  totals = "This was a dry-run"
96
104
  else
97
105
  totals = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
106
+ totals << ", #{not_implemented_count} not implemented" if not_implemented_count > 0
98
107
  end
99
108
  @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
100
109
  @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
@@ -120,8 +129,10 @@ module Spec
120
129
  <meta http-equiv="Pragma" content="no-cache" />
121
130
  <style type="text/css">
122
131
  body {
123
- margin: 0; padding: 0;
132
+ margin: 0;
133
+ padding: 0;
124
134
  background: #fff;
135
+ font-size: 80%;
125
136
  }
126
137
  </style>
127
138
  </head>
@@ -161,7 +172,21 @@ function moveProgressBar(percentDone) {
161
172
  }
162
173
  function makeRed(element_id) {
163
174
  document.getElementById(element_id).style.background = '#C40D0D';
164
- }
175
+ document.getElementById(element_id).style.color = '#FFFFFF';
176
+ }
177
+
178
+ function makeYellow(element_id) {
179
+ if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D')
180
+ {
181
+ document.getElementById(element_id).style.background = '#FAF834';
182
+ document.getElementById(element_id).style.color = '#000000';
183
+ }
184
+ else
185
+ {
186
+ document.getElementById(element_id).style.background = '#FAF834';
187
+ document.getElementById(element_id).style.color = '#000000';
188
+ }
189
+ }
165
190
  EOF
166
191
  end
167
192
 
@@ -171,15 +196,16 @@ EOF
171
196
  background: #65C400; color: #fff;
172
197
  }
173
198
 
174
- div.rspec-report h1 {
199
+ .rspec-report h1 {
175
200
  margin: 0px 10px 0px 10px;
176
201
  padding: 10px;
177
- font: bold 18px "Lucida Grande", Helvetica, sans-serif;
202
+ font-family: "Lucida Grande", Helvetica, sans-serif;
203
+ font-size: 1.8em;
178
204
  }
179
205
 
180
206
  #summary {
181
207
  margin: 0; padding: 5px 10px;
182
- font: bold 10px "Lucida Grande", Helvetica, sans-serif;
208
+ font-family: "Lucida Grande", Helvetica, sans-serif;
183
209
  text-align: right;
184
210
  position: absolute;
185
211
  top: 0px;
@@ -187,11 +213,11 @@ div.rspec-report h1 {
187
213
  }
188
214
 
189
215
  #summary p {
190
- margin: 0 0 2px;
216
+ margin: 0 0 0 2px;
191
217
  }
192
218
 
193
219
  #summary #totals {
194
- font-size: 14px;
220
+ font-size: 1.2em;
195
221
  }
196
222
 
197
223
  .behaviour {
@@ -228,7 +254,13 @@ dd.spec.failed {
228
254
  color: #C20000; background: #FFFBD3;
229
255
  }
230
256
 
231
- div.backtrace {
257
+ dd.spec.not_implemented {
258
+ border-left: 5px solid #FAF834;
259
+ border-bottom: 1px solid #FAF834;
260
+ background: #FCFB98; color: #131313;
261
+ }
262
+
263
+ .backtrace {
232
264
  color: #000;
233
265
  font-size: 12px;
234
266
  }
@@ -238,7 +270,7 @@ a {
238
270
  }
239
271
 
240
272
  /* Ruby code, style similar to vibrant ink */
241
- pre.ruby {
273
+ .ruby {
242
274
  font-size: 12px;
243
275
  font-family: monospace;
244
276
  color: white;
@@ -246,27 +278,27 @@ pre.ruby {
246
278
  padding: 0.1em 0 0.2em 0;
247
279
  }
248
280
 
249
- pre.ruby .keyword { color: #FF6600; }
250
- pre.ruby .constant { color: #339999; }
251
- pre.ruby .attribute { color: white; }
252
- pre.ruby .global { color: white; }
253
- pre.ruby .module { color: white; }
254
- pre.ruby .class { color: white; }
255
- pre.ruby .string { color: #66FF00; }
256
- pre.ruby .ident { color: white; }
257
- pre.ruby .method { color: #FFCC00; }
258
- pre.ruby .number { color: white; }
259
- pre.ruby .char { color: white; }
260
- pre.ruby .comment { color: #9933CC; }
261
- pre.ruby .symbol { color: white; }
262
- pre.ruby .regex { color: #44B4CC; }
263
- pre.ruby .punct { color: white; }
264
- pre.ruby .escape { color: white; }
265
- pre.ruby .interp { color: white; }
266
- pre.ruby .expr { color: white; }
267
-
268
- pre.ruby .offending { background-color: gray; }
269
- pre.ruby .linenum {
281
+ .ruby .keyword { color: #FF6600; }
282
+ .ruby .constant { color: #339999; }
283
+ .ruby .attribute { color: white; }
284
+ .ruby .global { color: white; }
285
+ .ruby .module { color: white; }
286
+ .ruby .class { color: white; }
287
+ .ruby .string { color: #66FF00; }
288
+ .ruby .ident { color: white; }
289
+ .ruby .method { color: #FFCC00; }
290
+ .ruby .number { color: white; }
291
+ .ruby .char { color: white; }
292
+ .ruby .comment { color: #9933CC; }
293
+ .ruby .symbol { color: white; }
294
+ .ruby .regex { color: #44B4CC; }
295
+ .ruby .punct { color: white; }
296
+ .ruby .escape { color: white; }
297
+ .ruby .interp { color: white; }
298
+ .ruby .expr { color: white; }
299
+
300
+ .ruby .offending { background-color: gray; }
301
+ .ruby .linenum {
270
302
  width: 75px;
271
303
  padding: 0.1em 1em 0.2em 0;
272
304
  color: #000000;
@@ -15,6 +15,11 @@ module Spec
15
15
  @output.flush
16
16
  end
17
17
 
18
+ def example_not_implemented(name)
19
+ @output.print yellow('*')
20
+ @output.flush
21
+ end
22
+
18
23
  def start_dump
19
24
  @output.puts
20
25
  @output.flush
@@ -14,6 +14,10 @@ module Spec
14
14
  def example_failed(name, counter, failure)
15
15
  @output.puts "# * #{name} [#{counter} - FAILED]"
16
16
  end
17
+
18
+ def example_not_implemented(name)
19
+ @output.puts "# * #{name} [NOT IMPLEMENTED]"
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -17,7 +17,12 @@ module Spec
17
17
  @output.puts green("- #{name}")
18
18
  @output.flush
19
19
  end
20
+
21
+ def example_not_implemented(name)
22
+ @output.puts yellow("- #{name} (NOT IMPLEMENTED)")
23
+ @output.flush
24
+ end
20
25
  end
21
26
  end
22
27
  end
23
- end
28
+ end
@@ -144,7 +144,7 @@ module Spec
144
144
  end
145
145
 
146
146
  opts.rspec_on(:drb) do
147
- parse_drb args_copy, out, err, warn_if_no_files
147
+ return parse_drb(args_copy, out, err, warn_if_no_files)
148
148
  end
149
149
 
150
150
  opts.rspec_on(:version) {parse_version(out)}
@@ -17,9 +17,12 @@ module Spec
17
17
  @formatters.each{|f| f.example_started(name)}
18
18
  end
19
19
 
20
- def example_finished(name, error=nil, failure_location=nil)
20
+ def example_finished(name, error=nil, failure_location=nil, not_implemented = false)
21
21
  @example_names << name
22
- if error.nil?
22
+
23
+ if not_implemented
24
+ example_not_implemented(name)
25
+ elsif error.nil?
23
26
  example_passed(name)
24
27
  else
25
28
  example_failed(name, error, failure_location)
@@ -40,7 +43,7 @@ module Spec
40
43
  def dump
41
44
  @formatters.each{|f| f.start_dump}
42
45
  dump_failures
43
- @formatters.each{|f| f.dump_summary(duration, @example_names.length, @failures.length)}
46
+ @formatters.each{|f| f.dump_summary(duration, @example_names.length, @failures.length, @not_implemented_count)}
44
47
  @failures.length
45
48
  end
46
49
 
@@ -49,6 +52,7 @@ module Spec
49
52
  def clear!
50
53
  @behaviour_names = []
51
54
  @failures = []
55
+ @not_implemented_count = 0
52
56
  @example_names = []
53
57
  @start_time = nil
54
58
  @end_time = nil
@@ -66,7 +70,7 @@ module Spec
66
70
  return @end_time - @start_time unless (@end_time.nil? or @start_time.nil?)
67
71
  return "0.0"
68
72
  end
69
-
73
+
70
74
  def example_passed(name)
71
75
  @formatters.each{|f| f.example_passed(name)}
72
76
  end
@@ -79,6 +83,11 @@ module Spec
79
83
  @formatters.each{|f| f.example_failed(name, @failures.length, failure)}
80
84
  end
81
85
 
86
+ def example_not_implemented(name)
87
+ @not_implemented_count += 1
88
+ @formatters.each{|f| f.example_not_implemented(name)}
89
+ end
90
+
82
91
  class Failure
83
92
  attr_reader :exception
84
93
 
@@ -41,7 +41,7 @@ module Spec
41
41
  def parse_description(str)
42
42
  return str[1..-2] if str =~ /^['"].*['"]$/
43
43
  if matches = /^(.*)\s*,\s*['"](.*)['"]$/.match(str)
44
- return "#{matches[1]}#{matches[2]}"
44
+ return ::Spec::DSL::Description.generate_description(matches[1], matches[2])
45
45
  end
46
46
  return str
47
47
  end
@@ -1,13 +1,13 @@
1
1
  module Spec
2
2
  module VERSION
3
3
  unless defined? MAJOR
4
- MAJOR = 0
5
- MINOR = 9
6
- TINY = 4
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ TINY = 0
7
7
  RELEASE_CANDIDATE = nil
8
8
 
9
- # RANDOM_TOKEN: 0.310952573062985
10
- REV = "$LastChangedRevision: 1935 $".match(/LastChangedRevision: (\d+)/)[1]
9
+ # RANDOM_TOKEN: 0.805184248412641
10
+ REV = "$LastChangedRevision: 1986 $".match(/LastChangedRevision: (\d+)/)[1]
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].join('.')
13
13
  TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
@@ -11,20 +11,12 @@ module Spec
11
11
 
12
12
  describe Behaviour, "class methods" do
13
13
  before :each do
14
- @original_before_all_parts = Behaviour.before_all_parts.dup
15
- @original_after_all_parts = Behaviour.after_all_parts.dup
16
- @original_before_each_parts = Behaviour.before_each_parts.dup
17
- @original_after_each_parts = Behaviour.after_each_parts.dup
18
-
19
14
  @reporter = FakeReporter.new(mock("formatter", :null_object => true), mock("backtrace_tweaker", :null_object => true))
20
15
  @behaviour = Behaviour.new("example") {}
21
16
  end
22
17
 
23
18
  after :each do
24
- Behaviour.instance_variable_set(:@before_all_parts, @original_before_all_parts)
25
- Behaviour.instance_variable_set(:@after_all_parts, @original_after_all_parts)
26
- Behaviour.instance_variable_set(:@before_each_parts, @original_before_each_parts)
27
- Behaviour.instance_variable_set(:@after_each_parts, @original_after_each_parts)
19
+ Behaviour.clear_before_and_after!
28
20
  end
29
21
 
30
22
  it "should not run before(:all) or after(:all) on dry run" do
@@ -96,20 +88,12 @@ module Spec
96
88
 
97
89
  describe Behaviour do
98
90
  before :each do
99
- @original_before_all_parts = Behaviour.before_all_parts.dup
100
- @original_after_all_parts = Behaviour.after_all_parts.dup
101
- @original_before_each_parts = Behaviour.before_each_parts.dup
102
- @original_after_each_parts = Behaviour.after_each_parts.dup
103
-
104
91
  @reporter = FakeReporter.new(mock("formatter", :null_object => true), mock("backtrace_tweaker", :null_object => true))
105
92
  @behaviour = Behaviour.new("example") {}
106
93
  end
107
94
 
108
95
  after :each do
109
- Behaviour.instance_variable_set(:@before_all_parts, @original_before_all_parts)
110
- Behaviour.instance_variable_set(:@after_all_parts, @original_after_all_parts)
111
- Behaviour.instance_variable_set(:@before_each_parts, @original_before_each_parts)
112
- Behaviour.instance_variable_set(:@after_each_parts, @original_after_each_parts)
96
+ Behaviour.clear_before_and_after!
113
97
  end
114
98
 
115
99
  it "should send reporter add_behaviour" do
@@ -255,6 +239,50 @@ module Spec
255
239
  @behaviour.run(@reporter)
256
240
  context_instance_value_in.should == context_instance_value_out
257
241
  end
242
+
243
+ it "should not add global before callbacks for untargetted behaviours" do
244
+ fiddle = []
245
+
246
+ Behaviour.before(:all) { fiddle << "Behaviour.before(:all)" }
247
+ Behaviour.prepend_before(:all) { fiddle << "Behaviour.prepend_before(:all)" }
248
+ Behaviour.before(:each, :behaviour_type => :special) { fiddle << "Behaviour.before(:each, :behaviour_type => :special)" }
249
+ Behaviour.prepend_before(:each, :behaviour_type => :special) { fiddle << "Behaviour.prepend_before(:each, :behaviour_type => :special)" }
250
+ Behaviour.before(:all, :behaviour_type => :special) { fiddle << "Behaviour.before(:all, :behaviour_type => :special)" }
251
+ Behaviour.prepend_before(:all, :behaviour_type => :special) { fiddle << "Behaviour.prepend_before(:all, :behaviour_type => :special)" }
252
+
253
+ behaviour = Behaviour.new("I'm not special", :behaviour_type => :not_special) {}
254
+ behaviour.run(@reporter)
255
+ fiddle.should == [
256
+ 'Behaviour.prepend_before(:all)',
257
+ 'Behaviour.before(:all)',
258
+ ]
259
+ end
260
+
261
+ it "should add global before callbacks for targetted behaviours" do
262
+ fiddle = []
263
+
264
+ Behaviour.before(:all) { fiddle << "Behaviour.before(:all)" }
265
+ Behaviour.prepend_before(:all) { fiddle << "Behaviour.prepend_before(:all)" }
266
+ Behaviour.before(:each, :behaviour_type => :special) { fiddle << "Behaviour.before(:each, :behaviour_type => :special)" }
267
+ Behaviour.prepend_before(:each, :behaviour_type => :special) { fiddle << "Behaviour.prepend_before(:each, :behaviour_type => :special)" }
268
+ Behaviour.before(:all, :behaviour_type => :special) { fiddle << "Behaviour.before(:all, :behaviour_type => :special)" }
269
+ Behaviour.prepend_before(:all, :behaviour_type => :special) { fiddle << "Behaviour.prepend_before(:all, :behaviour_type => :special)" }
270
+
271
+ Behaviour.append_before(:behaviour_type => :special) { fiddle << "Behaviour.append_before(:each, :behaviour_type => :special)" }
272
+
273
+ behaviour = Behaviour.new("I'm not special", :behaviour_type => :special) {}
274
+ behaviour.it("test") {true}
275
+ behaviour.run(@reporter)
276
+ fiddle.should == [
277
+ 'Behaviour.prepend_before(:all)',
278
+ 'Behaviour.before(:all)',
279
+ 'Behaviour.prepend_before(:all, :behaviour_type => :special)',
280
+ 'Behaviour.before(:all, :behaviour_type => :special)',
281
+ 'Behaviour.prepend_before(:each, :behaviour_type => :special)',
282
+ 'Behaviour.before(:each, :behaviour_type => :special)',
283
+ 'Behaviour.append_before(:each, :behaviour_type => :special)',
284
+ ]
285
+ end
258
286
 
259
287
  it "before callbacks are ordered from global to local" do
260
288
  fiddle = []
@@ -399,14 +427,50 @@ module Spec
399
427
  mod1_method_called.should be_true
400
428
  mod2_method_called.should be_true
401
429
  end
430
+
431
+ it "should not include untargeted modules" do
432
+ special_method_called = false
433
+ special_mod = Module.new do
434
+ define_method :special_method do
435
+ special_method_called = true
436
+ end
437
+ end
438
+
439
+ behaviour = Behaviour.new("I'm not special", :behaviour_type => :not_special) {}
440
+ behaviour.include special_mod, :behaviour_type => :special
441
+ behaviour.it "test" do
442
+ special_method
443
+ end
444
+ behaviour.run(@reporter)
445
+
446
+ special_method_called.should be_false
447
+ end
448
+
449
+ it "should include targeted modules" do
450
+ special_method_called = false
451
+ special_mod = Module.new do
452
+ define_method :special_method do
453
+ special_method_called = true
454
+ end
455
+ end
456
+
457
+ behaviour = Behaviour.new("I'm not special", :behaviour_type => :special) {}
458
+ behaviour.include special_mod, :behaviour_type => :special
459
+ behaviour.it "test" do
460
+ special_method
461
+ end
462
+ behaviour.run(@reporter)
463
+
464
+ special_method_called.should be_true
465
+ end
402
466
 
403
467
  it "should have accessible class methods from included module" do
404
468
  mod1_method_called = false
405
469
  mod1 = Module.new do
406
470
  class_methods = Module.new do
407
- define_method :mod1_method do
408
- mod1_method_called = true
409
- end
471
+ define_method :mod1_method do
472
+ mod1_method_called = true
473
+ end
410
474
  end
411
475
 
412
476
  metaclass.class_eval do
@@ -419,9 +483,9 @@ module Spec
419
483
  mod2_method_called = false
420
484
  mod2 = Module.new do
421
485
  class_methods = Module.new do
422
- define_method :mod2_method do
423
- mod2_method_called = true
424
- end
486
+ define_method :mod2_method do
487
+ mod2_method_called = true
488
+ end
425
489
  end
426
490
 
427
491
  metaclass.class_eval do