rspec 0.4.0 → 0.5.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 (94) hide show
  1. data/CHANGES +7 -12
  2. data/Rakefile +17 -12
  3. data/TUTORIAL +1 -1
  4. data/WHY_RSPEC +115 -0
  5. data/bin/spec +17 -4
  6. data/bin/test2rspec +35 -0
  7. data/examples/airport_spec.rb +35 -0
  8. data/examples/mocking_spec.rb +16 -0
  9. data/examples/spec_framework_spec.rb +28 -0
  10. data/examples/stack.rb +36 -0
  11. data/examples/stack_spec.rb +112 -0
  12. data/lib/spec.rb +5 -18
  13. data/lib/spec/api.rb +4 -0
  14. data/lib/spec/{exceptions.rb → api/exceptions.rb} +1 -1
  15. data/lib/spec/{expectations.rb → api/expectations.rb} +5 -4
  16. data/lib/spec/api/helper.rb +10 -0
  17. data/lib/spec/{have_helper.rb → api/helper/have_helper.rb} +1 -1
  18. data/lib/spec/{instance_helper.rb → api/helper/instance_helper.rb} +0 -0
  19. data/lib/spec/{instance_negator.rb → api/helper/instance_negator.rb} +0 -0
  20. data/lib/spec/{kind_helper.rb → api/helper/kind_helper.rb} +0 -0
  21. data/lib/spec/{kind_negator.rb → api/helper/kind_negator.rb} +0 -0
  22. data/lib/spec/{respond_helper.rb → api/helper/respond_helper.rb} +0 -0
  23. data/lib/spec/{respond_negator.rb → api/helper/respond_negator.rb} +0 -0
  24. data/lib/spec/{should_base.rb → api/helper/should_base.rb} +6 -4
  25. data/lib/spec/{should_helper.rb → api/helper/should_helper.rb} +12 -0
  26. data/lib/spec/{should_negator.rb → api/helper/should_negator.rb} +11 -0
  27. data/lib/spec/api/mock.rb +184 -0
  28. data/lib/spec/rake/spectask.rb +153 -0
  29. data/lib/spec/runner.rb +9 -0
  30. data/lib/spec/runner/backtrace_tweaker.rb +17 -0
  31. data/lib/spec/runner/context.rb +47 -0
  32. data/lib/spec/runner/context_runner.rb +52 -0
  33. data/lib/spec/runner/execution_context.rb +15 -0
  34. data/lib/spec/runner/instance_exec.rb +15 -0
  35. data/lib/spec/runner/kernel_ext.rb +6 -0
  36. data/lib/spec/runner/option_parser.rb +41 -0
  37. data/lib/spec/runner/rdoc_formatter.rb +17 -0
  38. data/lib/spec/runner/simple_text_reporter.rb +92 -0
  39. data/lib/spec/runner/specification.rb +42 -0
  40. data/lib/spec/tool/command_line.rb +39 -0
  41. data/lib/spec/tool/test_unit_translator.rb +112 -0
  42. data/lib/spec/version.rb +13 -0
  43. data/test/spec/api/helper/arbitrary_predicate_test.rb +121 -0
  44. data/test/spec/api/helper/containment_test.rb +117 -0
  45. data/test/spec/api/helper/equality_test.rb +46 -0
  46. data/test/spec/api/helper/identity_test.rb +68 -0
  47. data/test/spec/api/helper/raising_test.rb +50 -0
  48. data/test/spec/api/helper/regex_matching_test.rb +38 -0
  49. data/test/spec/api/helper/should_satisfy_test.rb +37 -0
  50. data/test/spec/api/helper/throwing_test.rb +56 -0
  51. data/test/spec/api/helper/true_false_special_case_test.rb +87 -0
  52. data/test/spec/api/helper/typing_test.rb +107 -0
  53. data/test/spec/api/mock_test.rb +161 -0
  54. data/test/spec/runner/backtrace_tweaker_test.rb +20 -0
  55. data/test/spec/runner/context_runner_test.rb +19 -0
  56. data/test/spec/runner/context_test.rb +29 -0
  57. data/test/spec/runner/execution_context_test.rb +13 -0
  58. data/test/spec/runner/option_parser_test.rb +50 -0
  59. data/test/spec/runner/rdoc_formatter_test.rb +23 -0
  60. data/test/spec/runner/simple_text_reporter_test.rb +128 -0
  61. data/test/spec/runner/specification_test.rb +70 -0
  62. data/test/spec/tool/command_line_test.rb +22 -0
  63. data/test/spec/tool/test_unit_api_spec.rb +61 -0
  64. data/test/spec/tool/test_unit_api_test.rb +61 -0
  65. data/test/spec/tool/test_unit_translator_test.rb +29 -0
  66. data/test/test_helper.rb +8 -0
  67. metadata +89 -67
  68. data/examples/add_specification_spec.rb +0 -15
  69. data/examples/craps.rb +0 -15
  70. data/examples/craps_spec.rb +0 -105
  71. data/examples/dsl_spec.rb +0 -8
  72. data/examples/movie.rb +0 -7
  73. data/examples/movie_list.rb +0 -19
  74. data/examples/movie_spec.rb +0 -37
  75. data/lib/spec/collector.rb +0 -17
  76. data/lib/spec/context.rb +0 -89
  77. data/lib/spec/dsl.rb +0 -23
  78. data/lib/spec/gui_runner.rb +0 -59
  79. data/lib/spec/mock.rb +0 -183
  80. data/lib/spec/text_runner.rb +0 -75
  81. data/test/collection_owner.rb +0 -48
  82. data/test/context_fixtures_test.rb +0 -71
  83. data/test/context_run_test.rb +0 -174
  84. data/test/dsl_test.rb +0 -48
  85. data/test/error_reporting_test.rb +0 -225
  86. data/test/expectations_for_should_have_test.rb +0 -144
  87. data/test/expectations_test.rb +0 -592
  88. data/test/get_classes.rb +0 -6
  89. data/test/gui_runner_test.rb +0 -162
  90. data/test/mock_test.rb +0 -157
  91. data/test/spec_collection_test.rb +0 -39
  92. data/test/specification_addition_test.rb +0 -29
  93. data/test/specification_identification_test.rb +0 -71
  94. data/test/text_runner_test.rb +0 -146
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Api
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 { 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 { true }
17
+ end
18
+ end
19
+
20
+ # should.not.satisfy
21
+
22
+ def test_should_raise_exception_when_block_yields_false
23
+ assert_raise(ExpectationNotMetError) do
24
+ 5.should.not.satisfy { true }
25
+ end
26
+ end
27
+
28
+ def test_should_not_raise_exception_when_block_yields_true
29
+ assert_nothing_raised do
30
+ 5.should.not.satisfy { false }
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+ module Helper
6
+ class ThrowingTest < Test::Unit::TestCase
7
+
8
+ # should.raise
9
+
10
+ def test_should_throw_should_pass_when_proper_symbol_is_thrown
11
+ assert_nothing_raised do
12
+ proc { throw :foo }.should.throw :foo
13
+ end
14
+ end
15
+
16
+ def test_should_throw_should_fail_when_wrong_exception_is_thrown
17
+ assert_raise(ExpectationNotMetError) do
18
+ proc { throw :bar }.should.throw :foo
19
+ end
20
+ end
21
+
22
+ def test_should_throw_should_fail_when_no_symbol_is_thrown
23
+ assert_raise(ExpectationNotMetError) do
24
+ proc {''.to_s}.should.throw :foo
25
+ end
26
+ end
27
+
28
+ # should.not.throw
29
+
30
+ def test_should_not_throw_should_fail_when_specific_symbol_is_thrown
31
+ assert_raise(ExpectationNotMetError) do
32
+ proc { throw :foo }.should.not.throw :foo
33
+ end
34
+ end
35
+
36
+ def test_should_not_throw_should_pass_when_other_symbol_is_thrown
37
+ assert_nothing_raised do
38
+ proc { throw :bar }.should.not.throw :foo
39
+ end
40
+ end
41
+
42
+ def test_should_not_throw_should_pass_when_no_symbol_is_thrown
43
+ assert_nothing_raised do
44
+ proc { ''.to_s }.should.not.throw :foo
45
+ end
46
+ end
47
+
48
+ def test_should_not_throw_should_pass_when_no_symbol_is_thrown_and_none_is_specified
49
+ assert_nothing_raised do
50
+ proc { ''.to_s }.should.not.throw
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,87 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+ module Helper
6
+ class TrueFalseSpecialCaseTest < Test::Unit::TestCase
7
+
8
+ # should.be true
9
+
10
+ def test_should_be_true_should_raise_when_object_is_nil
11
+ assert_raise(ExpectationNotMetError) do
12
+ nil.should.be true
13
+ end
14
+ end
15
+
16
+ def test_should_be_true_should_raise_when_object_is_false
17
+ assert_raise(ExpectationNotMetError) do
18
+ false.should.be true
19
+ end
20
+ end
21
+
22
+ def test_should_be_true_shouldnt_raise_when_object_is_true
23
+ assert_nothing_raised do
24
+ true.should.be true
25
+ end
26
+ end
27
+
28
+ def test_should_be_true_shouldnt_raise_when_object_is_a_number
29
+ assert_nothing_raised do
30
+ 5.should.be true
31
+ end
32
+ end
33
+
34
+ def test_should_be_true_shouldnt_raise_when_object_is_a_string
35
+ assert_nothing_raised do
36
+ "hello".should.be true
37
+ end
38
+ end
39
+
40
+ def test_should_be_true_shouldnt_raise_when_object_is_a_some_random_object
41
+ assert_nothing_raised do
42
+ self.should.be true
43
+ end
44
+ end
45
+
46
+ # should.be false
47
+
48
+ def test_should_be_false_shouldnt_raise_when_object_is_nil
49
+ assert_nothing_raised do
50
+ nil.should.be false
51
+ end
52
+ end
53
+
54
+ def test_should_be_false_shouldnt_raise_when_object_is_false
55
+ assert_nothing_raised do
56
+ false.should.be false
57
+ end
58
+ end
59
+
60
+ def test_should_be_false_should_raise_when_object_is_true
61
+ assert_raise(ExpectationNotMetError) do
62
+ true.should.be false
63
+ end
64
+ end
65
+
66
+ def test_should_be_false_shouldnt_raise_when_object_is_a_number
67
+ assert_raise(ExpectationNotMetError) do
68
+ 5.should.be false
69
+ end
70
+ end
71
+
72
+ def test_should_be_false_shouldnt_raise_when_object_is_a_string
73
+ assert_raise(ExpectationNotMetError) do
74
+ "hello".should.be false
75
+ end
76
+ end
77
+
78
+ def test_should_be_false_shouldnt_raise_when_object_is_a_some_random_object
79
+ assert_raise(ExpectationNotMetError) do
80
+ self.should.be false
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,107 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+ module Helper
6
+ class TypeTest < Test::Unit::TestCase
7
+
8
+ # should.be.an.instance.of <class>
9
+
10
+ def test_should_be_an_instance_of_should_pass_when_target_is_specified_class
11
+ assert_nothing_raised do
12
+ 5.should.be.an.instance.of Fixnum
13
+ end
14
+ end
15
+
16
+ def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
17
+ assert_raise(ExpectationNotMetError) do
18
+ 5.should.be.an.instance.of Integer
19
+ end
20
+ end
21
+
22
+ # should.be.a.kind.of <class>
23
+
24
+ def test_should_be_a_kind_of_should_pass_when_target_is_of_specified_class
25
+ assert_nothing_raised do
26
+ 5.should.be.a.kind.of Fixnum
27
+ end
28
+ end
29
+
30
+ def test_should_be_a_kind_of_should_pass_when_target_is_of_subclass_of_specified_class
31
+ assert_nothing_raised do
32
+ 5.should.be.a.kind.of Integer
33
+ end
34
+ end
35
+
36
+ def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
37
+ assert_raise(ExpectationNotMetError) do
38
+ 5.should.be.a.kind.of String
39
+ end
40
+ end
41
+
42
+ # should.not.be.an.instance_of <class>
43
+
44
+ def test_should_not_be_an_instance_of_should_fail_when_target_is_of_specified_class
45
+ assert_raise(ExpectationNotMetError) do
46
+ 'hello'.should.not.be.an.instance.of String
47
+ end
48
+ end
49
+
50
+ def test_should_be_an_instance_of_should_pass_when_target_is_not_of_specified_class
51
+ assert_nothing_raised do
52
+ [].should.not.be.an.instance.of String
53
+ end
54
+ end
55
+
56
+ # should.be.a.kind.of <class>
57
+
58
+ def test_should_not_be_a_kind_of_should_fail_when_target_is_of_specified_class
59
+ assert_raise(ExpectationNotMetError) do
60
+ 5.should.not.be.a.kind.of Fixnum
61
+ end
62
+ end
63
+
64
+ def test_should_not_be_a_kind_of_should_fail_when_target_is_of_subclass_of_specified_class
65
+ assert_raise(ExpectationNotMetError) do
66
+ 5.should.not.be.a.kind.of Integer
67
+ end
68
+ end
69
+
70
+ def test_should_not_be_an_instance_of_should_pass_when_target_is_not_specified_class
71
+ assert_nothing_raised do
72
+ 5.should.not.be.a.kind.of String
73
+ end
74
+ end
75
+
76
+ # should.respond.to <message>
77
+
78
+ def test_should_respond_to_should_pass_when_target_does
79
+ assert_nothing_raised do
80
+ "".should.respond.to :length
81
+ end
82
+ end
83
+
84
+ def test_should_respond_to_should_fail_when_target_doesnt
85
+ assert_raise(ExpectationNotMetError) do
86
+ "".should.respond.to :connect
87
+ end
88
+ end
89
+
90
+ # should.not.respond.to <message>
91
+
92
+ def test_not_should_respond_to_should_fail_when_target_does
93
+ assert_raise(ExpectationNotMetError) do
94
+ "".should.not.respond.to :length
95
+ end
96
+ end
97
+
98
+ def test_not_should_respond_to_should_pass_when_target_doesnt
99
+ assert_nothing_raised do
100
+ "".should.not.respond.to :connect
101
+ end
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+
6
+ class MockTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @mock = Mock.new("test mock")
10
+ end
11
+
12
+ def test_should_report_line_number_of_expectation_of_unreceived_message
13
+ @mock.should_receive(:wont_happen).with("x", 3)
14
+
15
+ begin
16
+ @mock.__verify
17
+ rescue MockExpectationError => e
18
+ e.backtrace[0].should.match /mock_test\.rb:13:in .test_should_report_line/
19
+ end
20
+
21
+ end
22
+
23
+ def test_should_allow_block_to_calculate_return_values
24
+ @mock.should_receive(:random_call).with("a","b","c").and_return { |a,b,c| c+b+a }
25
+ assert_equal "cba", @mock.random_call("a","b","c")
26
+ # TODO: remove __verify when migrating to self-hosting. Verify happens transparently in teardown. (AH)
27
+ @mock.__verify
28
+ end
29
+
30
+ def test_should_allow_parameter_as_return_value
31
+ @mock.should_receive(:random_call).with("a","b","c").and_return("booh")
32
+ assert_equal "booh", @mock.random_call("a","b","c")
33
+ @mock.__verify
34
+ end
35
+
36
+ def test_return_nil_if_no_return_value_set
37
+ @mock.should_receive(:random_call).with("a","b","c")
38
+ assert_nil @mock.random_call("a","b","c")
39
+ @mock.__verify
40
+ end
41
+
42
+ def test_should_test_multiple_calls_to_method_with_same_parameters
43
+ @mock.should_receive(:random_call).twice.with("a","b","c")
44
+ @mock.random_call("a","b","c")
45
+ @mock.random_call("a","b","c")
46
+ @mock.__verify
47
+ end
48
+
49
+ def test_should_raise_exception_if_parameters_dont_match_when_method_called
50
+ @mock.should_receive(:random_call).with("a","b","c").and_return("booh")
51
+ assert_raise(MockExpectationError) {
52
+ @mock.random_call("a","d","c")
53
+ }
54
+ end
55
+
56
+ def test_should_fail_if_unexpected_method_called
57
+ assert_raise(MockExpectationError) {
58
+ @mock.random_call("a","d","c")
59
+ }
60
+ end
61
+
62
+ def test_should_allow_unexpected_methods_if_ignore_missing_set
63
+ m = Mock.new("null_object", :null_object=>true)
64
+ m.random_call("a","d","c")
65
+ m.__verify
66
+ end
67
+
68
+ # TODO: rename to should_raise_exception_telling_what_message_was_not_received
69
+ def test_should_raise_exception_on_verify_if_call_counts_not_as_expected
70
+ @mock.should_receive(:random_call).twice.with("a","b","c").and_return("booh")
71
+ @mock.random_call("a","b","c")
72
+ assert_raise(MockExpectationError) do
73
+ @mock.__verify
74
+ end
75
+ end
76
+
77
+ def test_should_use_block_for_expectation_if_provided
78
+ @mock.should_receive(:random_call) do | a, b |
79
+ a.should.equal("a")
80
+ b.should.equal("b")
81
+ "booh"
82
+ end
83
+ assert_equal("booh", @mock.random_call("a", "b"))
84
+ @mock.__verify
85
+ end
86
+
87
+ def test_failing_expectation_block_throws
88
+ @mock.should_receive(:random_call) {| a | a.should.be true}
89
+ assert_raise(MockExpectationError) do
90
+ @mock.random_call false
91
+ end
92
+ end
93
+
94
+ def test_two_return_values
95
+ @mock.should_receive(:multi_call).twice.with_no_args.and_return_consecutively([1, 2])
96
+ assert_equal(1, @mock.multi_call)
97
+ assert_equal(2, @mock.multi_call)
98
+ @mock.__verify
99
+ end
100
+
101
+ def test_repeating_final_return_value
102
+ @mock.should_receive(:multi_call).at_least_once.with_no_args.and_return_consecutively([1, 2])
103
+ assert_equal(1, @mock.multi_call)
104
+ assert_equal(2, @mock.multi_call)
105
+ assert_equal(2, @mock.multi_call)
106
+ @mock.__verify
107
+ end
108
+
109
+ def test_should_throw_on_call_of_never_method
110
+ @mock.should_receive(:random_call).never
111
+ assert_raise(MockExpectationError) do
112
+ @mock.random_call
113
+ @mock.__verify
114
+ end
115
+ end
116
+
117
+ def test_should_throw_if_at_least_once_method_not_called
118
+ @mock.should_receive(:random_call).at_least_once
119
+ assert_raise(MockExpectationError) do
120
+ @mock.__verify
121
+ end
122
+ end
123
+
124
+ def test_should_not_throw_if_any_number_of_times_method_not_called
125
+ @mock.should_receive(:random_call).any_number_of_times
126
+ @mock.__verify
127
+ end
128
+
129
+ def test_should_not_throw_if_any_number_of_times_method_is_called
130
+ @mock.should_receive(:random_call).any_number_of_times
131
+ @mock.random_call
132
+ @mock.__verify
133
+ end
134
+
135
+ def test_should_not_throw_if_at_least_once_method_is_called_twice
136
+ @mock.should_receive(:random_call).at_least_once
137
+ @mock.random_call
138
+ @mock.random_call
139
+ @mock.__verify
140
+ end
141
+
142
+ def test_should_support_mutiple_calls_with_different_args
143
+ @mock.should_receive(:random_call).once.with(1)
144
+ @mock.should_receive(:random_call).once.with(2)
145
+ @mock.random_call(1)
146
+ @mock.random_call(2)
147
+ @mock.__verify
148
+ end
149
+
150
+ def test_should_support_multiple_calls_with_different_args_and_counts
151
+ @mock.should_receive(:random_call).twice.with(1)
152
+ @mock.should_receive(:random_call).once.with(2)
153
+ @mock.random_call(1)
154
+ @mock.random_call(2)
155
+ @mock.random_call(1)
156
+ @mock.__verify
157
+ end
158
+
159
+ end
160
+ end
161
+ end