rspec 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/CHANGES +90 -1
  2. data/EXAMPLES.rd +28 -6
  3. data/MIT-LICENSE +20 -0
  4. data/README +18 -12
  5. data/Rakefile +60 -54
  6. data/examples/custom_formatter.rb +4 -4
  7. data/examples/helper_method_example.rb +11 -0
  8. data/examples/mocking_example.rb +19 -2
  9. data/examples/partial_mock_example.rb +28 -0
  10. data/examples/stack_spec.rb +8 -8
  11. data/examples/stubbing_example.rb +50 -9
  12. data/examples/test_case_spec.rb +6 -6
  13. data/lib/spec.rb +1 -2
  14. data/lib/spec/callback.rb +0 -0
  15. data/lib/spec/expectations.rb +3 -6
  16. data/lib/spec/expectations/diff.rb +23 -47
  17. data/lib/spec/expectations/differs/default.rb +62 -0
  18. data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
  19. data/lib/spec/expectations/extensions.rb +4 -0
  20. data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
  21. data/lib/spec/expectations/extensions/numeric.rb +5 -0
  22. data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
  23. data/lib/spec/expectations/extensions/symbol.rb +5 -0
  24. data/lib/spec/expectations/should.rb +4 -0
  25. data/lib/spec/expectations/should/base.rb +42 -0
  26. data/lib/spec/expectations/should/have.rb +79 -0
  27. data/lib/spec/expectations/should/not.rb +72 -0
  28. data/lib/spec/expectations/should/should.rb +83 -0
  29. data/lib/spec/expectations/sugar.rb +6 -25
  30. data/lib/spec/mocks.rb +5 -1
  31. data/lib/spec/mocks/argument_expectation.rb +15 -1
  32. data/lib/spec/mocks/error_generator.rb +72 -0
  33. data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
  34. data/lib/spec/mocks/extensions/object.rb +3 -0
  35. data/lib/spec/mocks/message_expectation.rb +80 -73
  36. data/lib/spec/mocks/mock.rb +4 -69
  37. data/lib/spec/mocks/mock_handler.rb +158 -0
  38. data/lib/spec/mocks/mock_methods.rb +44 -0
  39. data/lib/spec/mocks/order_group.rb +10 -2
  40. data/lib/spec/rake/spectask.rb +20 -18
  41. data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
  42. data/lib/spec/runner.rb +3 -1
  43. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  44. data/lib/spec/runner/context.rb +10 -16
  45. data/lib/spec/runner/context_eval.rb +40 -40
  46. data/lib/spec/runner/execution_context.rb +1 -12
  47. data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
  48. data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
  49. data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
  50. data/lib/spec/runner/formatter/html_formatter.rb +81 -101
  51. data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
  52. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  53. data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
  54. data/lib/spec/runner/option_parser.rb +41 -5
  55. data/lib/spec/runner/reporter.rb +3 -15
  56. data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
  57. data/lib/spec/runner/specification.rb +33 -14
  58. data/lib/spec/version.rb +6 -3
  59. data/vendor/watir/README.txt +1 -1
  60. metadata +34 -68
  61. data/bin/test2spec +0 -112
  62. data/examples/helper_method_spec.rb +0 -12
  63. data/lib/spec/expectations/have_helper.rb +0 -41
  64. data/lib/spec/expectations/helper.rb +0 -4
  65. data/lib/spec/expectations/should_base.rb +0 -52
  66. data/lib/spec/expectations/should_helper.rb +0 -93
  67. data/lib/spec/expectations/should_negator.rb +0 -71
  68. data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
  69. data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
  70. data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
  71. data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
  72. data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
  73. data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
  74. data/test/spec/expectations/containment_test.rb +0 -129
  75. data/test/spec/expectations/diff_test.rb +0 -62
  76. data/test/spec/expectations/identity_test.rb +0 -75
  77. data/test/spec/expectations/object_equality_test.rb +0 -65
  78. data/test/spec/expectations/raising_test.rb +0 -106
  79. data/test/spec/expectations/regex_matching_test.rb +0 -36
  80. data/test/spec/expectations/should_have_test.rb +0 -169
  81. data/test/spec/expectations/should_satisfy_test.rb +0 -37
  82. data/test/spec/expectations/sugar_test.rb +0 -93
  83. data/test/spec/expectations/supported_symbols_test.rb +0 -33
  84. data/test/spec/expectations/throwing_test.rb +0 -55
  85. data/test/spec/expectations/true_false_special_case_test.rb +0 -85
  86. data/test/spec/expectations/typing_test.rb +0 -108
  87. data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
  88. data/test/spec/mocks/mock_counts_test.rb +0 -431
  89. data/test/spec/mocks/mock_ordering_test.rb +0 -109
  90. data/test/spec/mocks/mock_test.rb +0 -220
  91. data/test/spec/mocks/null_object_test.rb +0 -37
  92. data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
  93. data/test/spec/runner/context_matching_test.rb +0 -35
  94. data/test/spec/runner/context_runner_test.rb +0 -62
  95. data/test/spec/runner/context_test.rb +0 -191
  96. data/test/spec/runner/execution_context_test.rb +0 -45
  97. data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
  98. data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
  99. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
  100. data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
  101. data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
  102. data/test/spec/runner/kernel_ext_test.rb +0 -13
  103. data/test/spec/runner/option_parser_test.rb +0 -141
  104. data/test/spec/runner/reporter_test.rb +0 -128
  105. data/test/spec/runner/spec_matcher_test.rb +0 -47
  106. data/test/spec/runner/specification_test.rb +0 -121
  107. data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
  108. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
  109. data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
  110. data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
  111. data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
  112. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
  113. data/test/test_classes.rb +0 -102
  114. data/test/test_helper.rb +0 -32
@@ -1,169 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class ShouldHaveTest < Test::Unit::TestCase
7
-
8
- def setup
9
- @owner = CollectionOwner.new
10
- (1..3).each do |n|
11
- @owner.add_to_collection_with_length_method n
12
- @owner.add_to_collection_with_size_method n
13
- end
14
- end
15
-
16
- def test_should_raise_when_expecting_less_than_actual_length
17
- assert_raise(ExpectationNotMetError) do
18
- @owner.should_have(2).items_in_collection_with_length_method
19
- end
20
- end
21
-
22
- def test_should_raise_when_expecting_less_than_actual_length_with_exactly
23
- assert_raise(ExpectationNotMetError) do
24
- @owner.should_have_exactly(2).items_in_collection_with_length_method
25
- end
26
- end
27
-
28
- def test_should_raise_when_expecting_more_than_actual_length
29
- assert_raise(ExpectationNotMetError) do
30
- @owner.should_have(4).items_in_collection_with_length_method
31
- end
32
- end
33
-
34
- def test_should_not_raise_when_expecting_actual_length
35
- assert_nothing_raised do
36
- @owner.should_have(3).items_in_collection_with_length_method
37
- @owner.should_have_exactly(3).items_in_collection_with_length_method
38
- end
39
- end
40
-
41
- def test_should_raise_when_expecting_less_than_actual_size
42
- assert_raise(ExpectationNotMetError) do
43
- @owner.should_have(2).items_in_collection_with_size_method
44
- end
45
- end
46
-
47
- def test_should_raise_when_expecting_more_than_actual_size
48
- assert_raise(ExpectationNotMetError) do
49
- @owner.should_have(4).items_in_collection_with_size_method
50
- end
51
- end
52
-
53
- def test_should_not_raise_when_expecting_actual_size
54
- assert_nothing_raised do
55
- @owner.should_have(3).items_in_collection_with_size_method
56
- @owner.should_have_exactly(3).items_in_collection_with_size_method
57
- end
58
- end
59
-
60
- def test_should_not_raise_when_expecting_actual_size_with_args
61
- assert_nothing_raised do
62
- @owner.should_have(3).items_for('a')
63
- @owner.should_have_exactly(3).items_for('a')
64
- @owner.should_have(1).items_for('b')
65
- @owner.should_have_exactly(1).items_for('b')
66
- end
67
- end
68
- end
69
-
70
- class ShouldHaveAtLeastTest < Test::Unit::TestCase
71
-
72
- def setup
73
- @owner = CollectionOwner.new
74
- (1..3).each do |n|
75
- @owner.add_to_collection_with_length_method n
76
- @owner.add_to_collection_with_size_method n
77
- end
78
- end
79
-
80
- def test_should_not_raise_when_expecting_less_than_actual_length
81
- assert_nothing_raised do
82
- @owner.should_have_at_least(2).items_in_collection_with_length_method
83
- end
84
- end
85
-
86
- def test_should_raise_when_expecting_more_than_actual_length
87
- assert_raise(ExpectationNotMetError) do
88
- @owner.should_have_at_least(4).items_in_collection_with_length_method
89
- end
90
- end
91
-
92
- def test_should_not_raise_when_expecting_actual_length
93
- assert_nothing_raised do
94
- @owner.should_have_at_least(3).items_in_collection_with_length_method
95
- end
96
- end
97
-
98
-
99
- def test_should_not_raise_when_expecting_less_than_actual_size
100
- assert_nothing_raised do
101
- @owner.should_have_at_least(2).items_in_collection_with_size_method
102
- end
103
- end
104
-
105
- def test_should_raise_when_expecting_more_than_actual_size
106
- assert_raise(ExpectationNotMetError) do
107
- @owner.should_have_at_least(4).items_in_collection_with_size_method
108
- end
109
- end
110
-
111
- def test_should_not_raise_when_expecting_actual_size
112
- assert_nothing_raised do
113
- @owner.should_have_at_least(3).items_in_collection_with_size_method
114
- end
115
- end
116
-
117
- end
118
-
119
- class ShouldHaveAtMostTest < Test::Unit::TestCase
120
-
121
- def setup
122
- @owner = CollectionOwner.new
123
- (1..3).each do |n|
124
- @owner.add_to_collection_with_length_method n
125
- @owner.add_to_collection_with_size_method n
126
- end
127
- end
128
-
129
- def test_should_raise_when_expecting_less_than_actual_length
130
- assert_raise(ExpectationNotMetError) do
131
- @owner.should_have_at_most(2).items_in_collection_with_length_method
132
- end
133
- end
134
-
135
- def test_should_not_raise_when_expecting_more_than_actual_length
136
- assert_nothing_raised do
137
- @owner.should_have_at_most(4).items_in_collection_with_length_method
138
- end
139
- end
140
-
141
- def test_should_not_raise_when_expecting_actual_length
142
- assert_nothing_raised do
143
- @owner.should_have_at_most(3).items_in_collection_with_length_method
144
- end
145
- end
146
-
147
-
148
- def test_should_raise_when_expecting_less_than_actual_size
149
- assert_raise(ExpectationNotMetError) do
150
- @owner.should_have_at_most(2).items_in_collection_with_size_method
151
- end
152
- end
153
-
154
- def test_should_not_raise_when_expecting_more_than_actual_size
155
- assert_nothing_raised do
156
- @owner.should_have_at_most(4).items_in_collection_with_size_method
157
- end
158
- end
159
-
160
- def test_should_not_raise_when_expecting_actual_size
161
- assert_nothing_raised do
162
- @owner.should_have_at_most(3).items_in_collection_with_size_method
163
- end
164
- end
165
-
166
- end
167
- end
168
- end
169
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class ShouldSatisfyTest < Test::Unit::TestCase
7
-
8
- def test_should_raise_exception_when_block_yields_false
9
- assert_raise(ExpectationNotMetError) do
10
- 5.should_satisfy {|target| false }
11
- end
12
- end
13
-
14
- def test_should_not_raise_exception_when_block_yields_true
15
- assert_nothing_raised do
16
- 5.should_satisfy {|target| true }
17
- end
18
- end
19
-
20
- # should_not_satisfy
21
-
22
- def test_should_raise_exception_when_block_yields_false_again
23
- assert_raise(ExpectationNotMetError) do
24
- 5.should_not_satisfy {|target| true }
25
- end
26
- end
27
-
28
- def test_should_not_raise_exception_when_block_yields_true_again
29
- assert_nothing_raised do
30
- 5.should_not_satisfy {|target| false }
31
- end
32
- end
33
-
34
- end
35
- end
36
- end
37
- end
@@ -1,93 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- class SugarTest < Test::Unit::TestCase
6
-
7
- def test_should_allow_underscored_shoulds_on_regular_objects
8
- 1.should_equal 1
9
- lambda { 1.should_not_equal 1 }.should_raise
10
- end
11
-
12
- def test_should_allow_underscored_shoulds_on_mocks
13
- sweetener = Mocks::Mock.new "sweetener"
14
- sweetener.should_receive(:natural?)
15
- sweetener.natural?
16
- sweetener.__verify
17
- end
18
-
19
- def test_should_allow_underscored_ats_on_mocks
20
- sweetener = Mocks::Mock.new "sweetener"
21
- sweetener.should_receive(:natural?).at_least(:once)
22
- sweetener.natural?
23
- sweetener.__verify
24
- end
25
-
26
- def test_should_allow_underscored_ands_on_mocks
27
- sweetener = Mocks::Mock.new "sweetener"
28
- sweetener.should_receive(:natural?).at_least(:once).and_return(true)
29
- natural = sweetener.natural?
30
- natural.should_be true
31
- sweetener.__verify
32
- end
33
-
34
- def test_should_allow_underscored_anys_on_mocks
35
- sweetener = Mocks::Mock.new "sweetener"
36
- sweetener.should_receive(:natural?).any_number_of_times
37
- sweetener.natural?
38
- sweetener.__verify
39
- end
40
-
41
- def test_should_allow_underscored_anys_on_mocks
42
- sweetener = Mocks::Mock.new "sweetener"
43
- sweetener.should_receive(:natural?).once.and_return(false)
44
- natural = sweetener.natural?
45
- natural.should_be false
46
- sweetener.__verify
47
- end
48
-
49
- def test_should_allow_multi_word_predicates_in_passing_specs
50
- subject = ClassWithMultiWordPredicate.new
51
- assert_nothing_raised do
52
- subject.should_be_multi_word_predicate
53
- end
54
- end
55
-
56
- def test_should_allow_multi_word_predicates_in_failing_specs
57
- subject = ClassWithMultiWordPredicate.new
58
- assert_raises(ExpectationNotMetError) do
59
- subject.should_not_be_multi_word_predicate
60
- end
61
- end
62
-
63
- def test_is_an_instance_of_should_work_when_passing
64
- n = 10
65
- assert_nothing_raised do
66
- n.should_be_an_instance_of Fixnum
67
- end
68
- end
69
-
70
- def test_is_an_instance_of_should_work_when_failing
71
- n = 10
72
- assert_raises(Spec::Expectations::ExpectationNotMetError) do
73
- n.should_be_an_instance_of String
74
- end
75
- end
76
-
77
- def test_is_a_kind_of_should_work_when_passing
78
- n = 10
79
- assert_nothing_raised do
80
- n.should_be_a_kind_of Numeric
81
- end
82
- end
83
-
84
- def test_is_a_kind_of_should_work_when_failing
85
- n = 10
86
- assert_raises(Spec::Expectations::ExpectationNotMetError) do
87
- n.should_be_a_kind_of Float
88
- end
89
- end
90
-
91
- end
92
- end
93
- end
@@ -1,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class SupportedSymbolsTest < Test::Unit::TestCase
7
- def test_should_support_less_than
8
- "<".to_sym.should_be_supported_by_rspec
9
- end
10
- def test_should_support_less_than_or_equal_to
11
- "<=".to_sym.should_be_supported_by_rspec
12
- end
13
- def test_should_support_greater_than_or_equal_to
14
- ">=".to_sym.should_be_supported_by_rspec
15
- end
16
- def test_should_support_greater_than
17
- ">".to_sym.should_be_supported_by_rspec
18
- end
19
- def test_should_support_equals_operator
20
- "==".to_sym.should_be_supported_by_rspec
21
- end
22
- def test_should_support_regex_match_operator
23
- "=~".to_sym.should_be_supported_by_rspec
24
- end
25
- end
26
- class SupportedSymbolsTest < Test::Unit::TestCase
27
- def test_should_not_support_not_equals_operator
28
- "!=".to_sym.should_not_be_supported_by_rspec
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class ShouldThrowTest < Test::Unit::TestCase
7
-
8
- def test_should_pass_when_proper_symbol_is_thrown
9
- assert_nothing_raised do
10
- lambda { throw :foo }.should_throw :foo
11
- end
12
- end
13
-
14
- def test_should_fail_when_wrong_symbol_is_thrown
15
- assert_raise(ExpectationNotMetError) do
16
- lambda { throw :bar }.should_throw :foo
17
- end
18
- end
19
-
20
- def test_should_fail_when_no_symbol_is_thrown
21
- assert_raise(ExpectationNotMetError) do
22
- lambda { ''.to_s }.should_throw :foo
23
- end
24
- end
25
- end
26
-
27
- class ShouldNotThrowTest < Test::Unit::TestCase
28
-
29
- def test_should_fail_when_expected_symbol_is_actually_thrown
30
- assert_raise(ExpectationNotMetError) do
31
- lambda { throw :foo }.should_not_throw :foo
32
- end
33
- end
34
-
35
- def test_should_pass_when_expected_symbol_is_thrown
36
- assert_nothing_raised do
37
- lambda { throw :bar }.should_not_throw :foo
38
- end
39
- end
40
-
41
- def test_should_pass_when_no_symbol_is_thrown
42
- assert_nothing_raised do
43
- lambda { ''.to_s }.should_not_throw :foo
44
- end
45
- end
46
-
47
- def test_should_pass_when_no_symbol_is_thrown_and_none_is_specified
48
- assert_nothing_raised do
49
- lambda { ''.to_s }.should_not_throw
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,85 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class ShouldBeTrueTest < Test::Unit::TestCase
7
-
8
- def test_should_raise_when_object_is_nil
9
- assert_raise(ExpectationNotMetError) do
10
- nil.should_be true
11
- end
12
- end
13
-
14
- def test_should_raise_when_object_is_false
15
- assert_raise(ExpectationNotMetError) do
16
- false.should_be true
17
- end
18
- end
19
-
20
- def test_shouldnt_raise_when_object_is_true
21
- assert_nothing_raised do
22
- true.should_be true
23
- end
24
- end
25
-
26
- def test_shouldnt_raise_when_object_is_a_number
27
- assert_nothing_raised do
28
- 5.should_be true
29
- end
30
- end
31
-
32
- def test_shouldnt_raise_when_object_is_a_string
33
- assert_nothing_raised do
34
- "hello".should_be true
35
- end
36
- end
37
-
38
- def test_shouldnt_raise_when_object_is_a_some_random_object
39
- assert_nothing_raised do
40
- self.should_be true
41
- end
42
- end
43
- end
44
-
45
- class ShouldBeFalseTest < Test::Unit::TestCase
46
- def test_shouldnt_raise_when_object_is_nil
47
- assert_nothing_raised do
48
- nil.should_be false
49
- end
50
- end
51
-
52
- def test_shouldnt_raise_when_object_is_false
53
- assert_nothing_raised do
54
- false.should_be false
55
- end
56
- end
57
-
58
- def test_should_raise_when_object_is_true
59
- assert_raise(ExpectationNotMetError) do
60
- true.should_be false
61
- end
62
- end
63
-
64
- def test_shouldnt_raise_when_object_is_a_number
65
- assert_raise(ExpectationNotMetError) do
66
- 5.should_be false
67
- end
68
- end
69
-
70
- def test_shouldnt_raise_when_object_is_a_string
71
- assert_raise(ExpectationNotMetError) do
72
- "hello".should_be false
73
- end
74
- end
75
-
76
- def test_shouldnt_raise_when_object_is_a_some_random_object
77
- assert_raise(ExpectationNotMetError) do
78
- self.should_be false
79
- end
80
- end
81
-
82
- end
83
- end
84
- end
85
- end