rspec 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/CHANGES +9 -1
  2. data/README +2 -2
  3. data/Rakefile +13 -5
  4. data/examples/custom_formatter.rb +2 -2
  5. data/examples/file_accessor.rb +18 -0
  6. data/examples/file_accessor_spec.rb +38 -0
  7. data/examples/io_processor.rb +8 -0
  8. data/examples/io_processor_spec.rb +21 -0
  9. data/lib/spec/api/exceptions.rb +3 -0
  10. data/lib/spec/api/mocks/message_expectation.rb +45 -29
  11. data/lib/spec/api/mocks/mock.rb +1 -1
  12. data/lib/spec/api/mocks/order_group.rb +1 -1
  13. data/lib/spec/runner.rb +1 -5
  14. data/lib/spec/runner/formatter.rb +5 -0
  15. data/lib/spec/runner/formatter/base_text_formatter.rb +79 -0
  16. data/lib/spec/runner/formatter/html_formatter.rb +156 -0
  17. data/lib/spec/runner/formatter/progress_bar_formatter.rb +27 -0
  18. data/lib/spec/runner/formatter/rdoc_formatter.rb +22 -0
  19. data/lib/spec/runner/formatter/specdoc_formatter.rb +22 -0
  20. data/lib/spec/runner/option_parser.rb +17 -17
  21. data/lib/spec/runner/reporter.rb +1 -1
  22. data/lib/spec/version.rb +1 -1
  23. data/test/spec/api/helper/arbitrary_predicate_test.rb +38 -38
  24. data/test/spec/api/helper/diff_test.rb +1 -1
  25. data/test/spec/api/helper/identity_test.rb +17 -10
  26. data/test/spec/api/helper/{equality_test.rb → object_equality_test.rb} +15 -29
  27. data/test/spec/api/helper/regex_matching_test.rb +7 -9
  28. data/test/spec/api/helper/throwing_test.rb +11 -12
  29. data/test/spec/api/helper/true_false_special_case_test.rb +15 -17
  30. data/test/spec/api/helper/typing_test.rb +27 -26
  31. data/test/spec/api/mocks/mock_arg_constraints_test.rb +1 -1
  32. data/test/spec/api/mocks/mock_test.rb +45 -11
  33. data/test/spec/api/mocks/null_object_test.rb +3 -3
  34. data/test/spec/runner/context_matching_test.rb +2 -2
  35. data/test/spec/runner/formatter/failure_dump_test.rb +94 -0
  36. data/test/spec/runner/formatter/html_formatter_test.rb +48 -0
  37. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +56 -0
  38. data/test/spec/runner/formatter/rdoc_formatter_test.rb +51 -0
  39. data/test/spec/runner/formatter/specdoc_formatter_test.rb +57 -0
  40. data/test/spec/runner/kernel_ext_test.rb +1 -1
  41. data/test/spec/runner/option_parser_test.rb +22 -12
  42. data/test/spec/runner/reporter_test.rb +1 -1
  43. data/test/test_classes.rb +7 -7
  44. metadata +19 -14
  45. data/lib/spec/runner/base_text_formatter.rb +0 -77
  46. data/lib/spec/runner/html_formatter.rb +0 -153
  47. data/lib/spec/runner/progress_bar_formatter.rb +0 -25
  48. data/lib/spec/runner/rdoc_formatter.rb +0 -20
  49. data/lib/spec/runner/specdoc_formatter.rb +0 -20
  50. data/test/spec/runner/failure_dump_test.rb +0 -92
  51. data/test/spec/runner/html_formatter_test.rb +0 -47
  52. data/test/spec/runner/progress_bar_formatter_test.rb +0 -54
  53. data/test/spec/runner/rdoc_formatter_test.rb +0 -50
  54. data/test/spec/runner/specdoc_formatter_test.rb +0 -55
@@ -0,0 +1,27 @@
1
+ module Spec
2
+ module Runner
3
+ module Formatter
4
+ class ProgressBarFormatter < BaseTextFormatter
5
+ def add_context(name, first)
6
+ @output << "\n" if first
7
+ @output.flush
8
+ end
9
+
10
+ def spec_failed(name, counter, failure)
11
+ @output << 'F'
12
+ @output.flush
13
+ end
14
+
15
+ def spec_passed(name)
16
+ @output << '.'
17
+ @output.flush
18
+ end
19
+
20
+ def start_dump
21
+ @output << "\n"
22
+ @output.flush
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module Spec
2
+ module Runner
3
+ module Formatter
4
+ class RdocFormatter < BaseTextFormatter
5
+ def add_context(name, first)
6
+ @output << "# #{name}\n"
7
+ @output.flush
8
+ end
9
+
10
+ def spec_passed(name)
11
+ @output << "# * #{name}\n"
12
+ @output.flush
13
+ end
14
+
15
+ def spec_failed(name, counter, failure)
16
+ @output << "# * #{name} [#{counter} - FAILED]\n"
17
+ @output.flush
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Spec
2
+ module Runner
3
+ module Formatter
4
+ class SpecdocFormatter < BaseTextFormatter
5
+ def add_context(name, first)
6
+ @output << "\n#{name}\n"
7
+ @output.flush
8
+ end
9
+
10
+ def spec_failed(name, counter, failure)
11
+ @output << "- #{name} (FAILED - #{counter})\n"
12
+ @output.flush
13
+ end
14
+
15
+ def spec_passed(name)
16
+ @output << "- #{name}\n"
17
+ @output.flush
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -16,7 +16,7 @@ module Spec
16
16
  def self.parse(args, standalone, err, out)
17
17
  options = OpenStruct.new
18
18
  options.out = out
19
- options.formatter_type = ProgressBarFormatter
19
+ options.formatter_type = Formatter::ProgressBarFormatter
20
20
  options.backtrace_tweaker = QuietBacktraceTweaker.new
21
21
  options.spec_name = nil
22
22
 
@@ -24,25 +24,24 @@ module Spec
24
24
  opts.banner = "Usage: spec [options] (FILE|DIRECTORY|GLOB)+"
25
25
  opts.separator ""
26
26
 
27
- opts.on("-b", "--backtrace", "Output full backtrace") do
28
- options.backtrace_tweaker = NoisyBacktraceTweaker.new
27
+ opts.on("--diff", "Show unified diff of Strings that are expected to be equal when they are not") do
28
+ require 'spec/api/helper/diff'
29
29
  end
30
30
 
31
- opts.on("-r", "--require FILE", "Require FILE before running specs",
32
- "Useful for loading custom formatters or other extensions") do |req|
33
- require req
31
+ opts.on("-s", "--spec SPECIFICATION_NAME", "Execute a single specification") do |spec_name|
32
+ options.spec_name = spec_name
34
33
  end
35
-
34
+
36
35
  opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r|html|h",
37
36
  "You can also specify a custom formatter class",
38
37
  "(in which case you should also specify --require)") do |format|
39
38
  case format
40
39
  when 'specdoc', 's'
41
- options.formatter_type = SpecdocFormatter
40
+ options.formatter_type = Formatter::SpecdocFormatter
42
41
  when 'html', 'h'
43
- options.formatter_type = HtmlFormatter
42
+ options.formatter_type = Formatter::HtmlFormatter
44
43
  when 'rdoc', 'r'
45
- options.formatter_type = RdocFormatter
44
+ options.formatter_type = Formatter::RdocFormatter
46
45
  options.dry_run = true
47
46
  else
48
47
  begin
@@ -55,18 +54,19 @@ module Spec
55
54
  end
56
55
  end
57
56
 
58
- opts.on("-d", "--dry-run", "Don't execute specs") do
59
- options.dry_run = true
57
+ opts.on("-r", "--require FILE", "Require FILE before running specs",
58
+ "Useful for loading custom formatters or other extensions") do |req|
59
+ require req
60
60
  end
61
61
 
62
- opts.on("--diff", "Show unified diff of Strings that are expected to be equal when they are not") do
63
- require 'spec/api/helper/diff'
62
+ opts.on("-b", "--backtrace", "Output full backtrace") do
63
+ options.backtrace_tweaker = NoisyBacktraceTweaker.new
64
64
  end
65
65
 
66
- opts.on("-s", "--spec SPECIFICATION_NAME", "Execute a single specification") do |spec_name|
67
- options.spec_name = spec_name
66
+ opts.on("-d", "--dry-run", "Don't execute specs") do
67
+ options.dry_run = true
68
68
  end
69
-
69
+
70
70
  opts.on("-v", "--version", "Show version") do
71
71
  out.puts ::Spec::VERSION::DESCRIPTION
72
72
  exit if out == $stdout
@@ -93,7 +93,7 @@ module Spec
93
93
  private
94
94
 
95
95
  def class_name
96
- @exception.class.name.split('::').last
96
+ @exception.class.name #.split('::').last
97
97
  end
98
98
 
99
99
  end
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 12
6
+ TINY = 13
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -6,102 +6,102 @@ module Spec
6
6
 
7
7
  class ArbitraryPredicateTest < Test::Unit::TestCase
8
8
 
9
- # should.be.xxx
9
+ # should.be.funny
10
10
 
11
- def test_should_be_xxx_should_raise_when_target_doesnt_understand_xxx
11
+ def test_should_be_funny_should_raise_when_target_doesnt_understand_funny
12
12
  assert_raise(NoMethodError) do
13
- 5.should.be.xxx
13
+ 5.should.be.funny
14
14
  end
15
15
  end
16
16
 
17
- def test_should_be_xxx_should_raise_when_sending_xxx_to_target_returns_false
18
- mock = XxxMock.new(false)
17
+ def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_false
18
+ mock = HandCodedMock.new(false)
19
19
  assert_raise(ExpectationNotMetError) do
20
- mock.should.be.xxx
20
+ mock.should.be.funny
21
21
  end
22
22
  mock.__verify
23
23
  end
24
24
 
25
- def test_should_be_xxx_should_raise_when_sending_xxx_to_target_returns_nil
26
- mock = XxxMock.new(nil)
25
+ def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_nil
26
+ mock = HandCodedMock.new(nil)
27
27
  assert_raise(ExpectationNotMetError) do
28
- mock.should.be.xxx
28
+ mock.should.be.funny
29
29
  end
30
30
  mock.__verify
31
31
  end
32
32
 
33
- def test_should_be_xxx_should_not_raise_when_sending_xxx_to_target_returns_true
34
- mock = XxxMock.new(true)
33
+ def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_true
34
+ mock = HandCodedMock.new(true)
35
35
  assert_nothing_raised do
36
- mock.should.be.xxx
36
+ mock.should.be.funny
37
37
  end
38
38
  mock.__verify
39
39
  end
40
40
 
41
- def test_should_be_xxx_should_not_raise_when_sending_xxx_to_target_returns_something_other_than_true_false_or_nil
42
- mock = XxxMock.new(5)
41
+ def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
42
+ mock = HandCodedMock.new(5)
43
43
  assert_nothing_raised do
44
- mock.should.be.xxx
44
+ mock.should.be.funny
45
45
  end
46
46
  mock.__verify
47
47
  end
48
48
 
49
- # should.be.xxx(args)
49
+ # should.be.funny(args)
50
50
 
51
- def test_should_be_xxx_with_args_passes_args_properly
52
- mock = XxxMock.new(true)
51
+ def test_should_be_funny_with_args_passes_args_properly
52
+ mock = HandCodedMock.new(true)
53
53
  assert_nothing_raised do
54
- mock.should.be.yyy(1, 2, 3)
54
+ mock.should.be.hungry(1, 2, 3)
55
55
  end
56
56
  mock.__verify
57
57
  end
58
58
 
59
- # should.not.be.xxx
59
+ # should.not.be.funny
60
60
 
61
- def test_should_not_be_xxx_should_raise_when_target_doesnt_understand_xxx
61
+ def test_should_not_be_funny_should_raise_when_target_doesnt_understand_funny
62
62
  assert_raise(NoMethodError) do
63
- 5.should.not.be.xxx
63
+ 5.should.not.be.funny
64
64
  end
65
65
  end
66
66
 
67
- def test_should_not_be_xxx_should_raise_when_sending_xxx_to_target_returns_true
68
- mock = XxxMock.new(true)
67
+ def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_true
68
+ mock = HandCodedMock.new(true)
69
69
  assert_raise(ExpectationNotMetError) do
70
- mock.should.not.be.xxx
70
+ mock.should.not.be.funny
71
71
  end
72
72
  mock.__verify
73
73
  end
74
74
 
75
- def test_should_not_be_xxx_shouldnt_raise_when_sending_xxx_to_target_returns_nil
76
- mock = XxxMock.new(nil)
75
+ def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_nil
76
+ mock = HandCodedMock.new(nil)
77
77
  assert_nothing_raised do
78
- mock.should.not.be.xxx
78
+ mock.should.not.be.funny
79
79
  end
80
80
  mock.__verify
81
81
  end
82
82
 
83
- def test_should_not_be_xxx_shouldnt_raise_when_sending_xxx_to_target_returns_false
84
- mock = XxxMock.new(false)
83
+ def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_false
84
+ mock = HandCodedMock.new(false)
85
85
  assert_nothing_raised do
86
- mock.should.not.be.xxx
86
+ mock.should.not.be.funny
87
87
  end
88
88
  mock.__verify
89
89
  end
90
90
 
91
- def test_should_not_be_xxx_should_raise_when_sending_xxx_to_target_returns_something_other_than_true_false_or_nil
92
- mock = XxxMock.new(5)
91
+ def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
92
+ mock = HandCodedMock.new(5)
93
93
  assert_raise(ExpectationNotMetError) do
94
- mock.should.not.be.xxx
94
+ mock.should.not.be.funny
95
95
  end
96
96
  mock.__verify
97
97
  end
98
98
 
99
- # should.be.xxx(args)
99
+ # should.be.funny(args)
100
100
 
101
- def test_should_not_be_xxx_with_args_passes_args_properly
102
- mock = XxxMock.new(false)
101
+ def test_should_not_be_funny_with_args_passes_args_properly
102
+ mock = HandCodedMock.new(false)
103
103
  assert_nothing_raised do
104
- mock.should.not.be.yyy(1, 2, 3)
104
+ mock.should.not.be.hungry(1, 2, 3)
105
105
  end
106
106
  mock.__verify
107
107
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
3
  module Spec
4
4
  class DiffTest < Test::Unit::TestCase
5
- def test_should_output_unified_diff
5
+ def test_should_output_unified_diff_of_two_strings
6
6
  expected = <<-EOF
7
7
  foo
8
8
  bar
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class IdentityTest < Test::Unit::TestCase
6
+ class ShouldBeTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @dummy = 'dummy'
@@ -12,51 +12,58 @@ module Spec
12
12
  @nil_var = nil
13
13
  end
14
14
 
15
- def test_should_be_same_as_should_not_raise_when_objects_are_same
15
+ def test_should_not_raise_when_objects_are_same
16
16
  assert_nothing_raised do
17
17
  @dummy.should.be @dummy
18
18
  end
19
19
  end
20
20
 
21
- def test_should_be_same_as_should_raise_when_objects_are_not_same
21
+ def test_should_raise_when_objects_are_not_same
22
22
  assert_raise(ExpectationNotMetError) do
23
23
  @dummy.should.be @equal_dummy
24
24
  end
25
25
  end
26
26
 
27
- def test_should_be_nil_should_not_raise_when_object_is_nil
27
+ def test_should_not_raise_when_both_objects_are_nil
28
28
  assert_nothing_raised do
29
29
  @nil_var.should.be nil
30
30
  end
31
31
  end
32
32
 
33
- def test_should_be_nil_should_raise_when_object_is_not_nil
33
+ def test_should_raise_when_object_is_not_nil
34
34
  assert_raise(ExpectationNotMetError) do
35
35
  @dummy.should.be nil
36
36
  end
37
37
  end
38
+ end
38
39
 
39
- # should.not.be
40
+ class ShouldNotBeTest < Test::Unit::TestCase
41
+ def setup
42
+ @dummy = 'dummy'
43
+ @equal_dummy = 'dummy'
44
+ @another_dummy = 'another_dummy'
45
+ @nil_var = nil
46
+ end
40
47
 
41
- def test_should_not_be_same_as_should_not_raise_when_objects_are_not_same
48
+ def test_should_not_raise_when_objects_are_not_same
42
49
  assert_nothing_raised do
43
50
  @dummy.should.not.be @equal_dummy
44
51
  end
45
52
  end
46
53
 
47
- def test_should_not_be_same_as_should_raise_when_objects_are_not_same
54
+ def test_should_raise_when_objects_are_same
48
55
  assert_raise(ExpectationNotMetError) do
49
56
  @dummy.should.not.be @dummy
50
57
  end
51
58
  end
52
59
 
53
- def test_should_not_be_nil_should_not_raise_when_object_is_not_nil
60
+ def test_should_not_raise_when_left_is_not_nil_and_right_is_nil
54
61
  assert_nothing_raised do
55
62
  @dummy.should.not.be nil
56
63
  end
57
64
  end
58
65
 
59
- def test_should_not_be_nil_should_raise_when_object_is_nil
66
+ def test_should_raise_when_both_objects_are_nil
60
67
  assert_raise(ExpectationNotMetError) do
61
68
  @nil_var.should.not.be nil
62
69
  end
@@ -3,52 +3,38 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class EqualityTest < Test::Unit::TestCase
6
+ class ShouldEqualTest < Test::Unit::TestCase
7
7
 
8
- def setup
9
- @dummy = 'dummy'
10
- @equal_dummy = 'dummy'
11
- @another_dummy = 'another_dummy'
12
- @nil_var = nil
13
- end
14
-
15
- # should.equal
16
-
17
- def test_should_equal_should_not_raise_when_objects_are_equal
8
+ def test_should_not_raise_when_objects_are_equal
18
9
  assert_nothing_raised do
19
- @dummy.should.equal @equal_dummy
10
+ 'apple'.should.equal 'apple'
20
11
  end
21
12
  end
22
13
 
23
- def test_should_equal_should_raise_when_objects_are_not_equal
14
+ def test_should_raise_when_objects_are_not_equal
24
15
  assert_raise(ExpectationNotMetError) do
25
- @dummy.should.equal @another_dummy
16
+ 'apple'.should.equal 'orange'
26
17
  end
27
- end
28
-
29
- def test_should_raise_nice_message
30
- begin
31
- "foo\nbar\nzap".should_equal "foo\nzap\nbar"
32
- rescue ExpectationNotMetError => e
33
- assert_equal "\"foo\\nbar\\nzap\" should equal \"foo\\nzap\\nbar\"", e.message
34
- end
35
- end
18
+ end
19
+ end
36
20
 
37
- # should.not.equal
21
+ class ShouldNotEqualTest < Test::Unit::TestCase
38
22
 
39
- def test_should_not_equal_should_not_raise_when_objects_are_not_equal
23
+ def test_should_not_raise_when_objects_are_not_equal
40
24
  assert_nothing_raised do
41
- @dummy.should.not.equal @another_dummy
25
+ 'apple'.should.not.equal 'orange'
42
26
  end
43
27
  end
44
28
 
45
29
  def test_should_not_equal_should_raise_when_objects_are_equal
46
30
  assert_raise(ExpectationNotMetError) do
47
- @dummy.should.not.equal @equal_dummy
31
+ 'apple'.should.not.equal 'apple'
48
32
  end
49
33
  end
34
+ end
50
35
 
51
- def test_should_be_close_good_cases
36
+ class ShouldBeCloseTest < Test::Unit::TestCase
37
+ def test_should_not_raise_when_values_are_within_bounds
52
38
  assert_nothing_raised do
53
39
  3.5.should.be.close 3.5, 0.5
54
40
  3.5.should.be.close 3.1, 0.5
@@ -58,7 +44,7 @@ module Spec
58
44
  end
59
45
  end
60
46
 
61
- def test_should_be_close_failing_cases
47
+ def test_should_raise_when_values_are_outside_bounds
62
48
  assert_raise(ExpectationNotMetError) do
63
49
  3.5.should.be.close 3.0, 0.5
64
50
  end