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
@@ -1,48 +0,0 @@
1
- class CollectionWithSizeMethod
2
-
3
- def initialize
4
- @list = []
5
- end
6
-
7
- def size
8
- @list.size
9
- end
10
-
11
- def push(item)
12
- @list.push(item)
13
- end
14
-
15
- end
16
-
17
- class CollectionWithLengthMethod
18
-
19
- def initialize
20
- @list = []
21
- end
22
-
23
- def length
24
- @list.length
25
- end
26
-
27
- def push(item)
28
- @list.push(item)
29
- end
30
-
31
- end
32
-
33
- class CollectionOwner
34
- attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method
35
-
36
- def initialize
37
- @items_in_collection_with_size_method = CollectionWithSizeMethod.new
38
- @items_in_collection_with_length_method = CollectionWithLengthMethod.new
39
- end
40
-
41
- def add_to_collection_with_size_method(item)
42
- @items_in_collection_with_size_method.push(item)
43
- end
44
-
45
- def add_to_collection_with_length_method(item)
46
- @items_in_collection_with_length_method.push(item)
47
- end
48
- end
@@ -1,71 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'spec'
4
-
5
-
6
- class FixtureTestingContext < Spec::Context
7
-
8
- @setup_called = false
9
- @spec_called = false
10
- @teardown_called = false
11
-
12
- def setup
13
- @setup_called = true
14
- end
15
-
16
- def verify_setup
17
- @setup_called
18
- end
19
-
20
- def teardown
21
- @teardown_called = true
22
- end
23
-
24
- def verify_teardown
25
- @teardown_called
26
- end
27
-
28
- def specification
29
- @spec_called = true
30
- end
31
-
32
- def verify_spec
33
- @spec_called
34
- end
35
-
36
- end
37
-
38
-
39
- class NullResultListener
40
-
41
- def pass(spec)
42
- end
43
-
44
- def failure(spec)
45
- end
46
-
47
- def error(spec)
48
- end
49
-
50
- def spec(spec)
51
- end
52
-
53
- end
54
-
55
-
56
- class ContextFixturesTest < Test::Unit::TestCase
57
-
58
- def setup
59
- @fixture_testing_context = FixtureTestingContext.new(:specification)
60
- @fixture_testing_context.run(NullResultListener.new)
61
- end
62
-
63
- def test_should_run_setup_before
64
- @fixture_testing_context.verify_setup
65
- end
66
-
67
- def test_should_run_teardown_after
68
- @fixture_testing_context.verify_teardown
69
- end
70
-
71
- end
@@ -1,174 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'spec'
4
-
5
-
6
- class TestCon < Spec::Context
7
-
8
- def empty_specification
9
- end
10
-
11
- def passing_once_specification
12
- true.should.equal(true)
13
- end
14
-
15
- def failing_once_specification
16
- false.should.equal(true)
17
- end
18
-
19
- def erroring_once_specification
20
- undefined_method.should.equal(true)
21
- end
22
-
23
- def passing_multi_specification
24
- true.should.equal(true)
25
- false.should.equal(false)
26
- Object.should.equal(Object)
27
- end
28
-
29
- def failing_multi_specification
30
- false.should.equal(true)
31
- true.should.equal(false)
32
- false.should.equal(nil)
33
- end
34
-
35
- def erroring_multi_specification
36
- undefined_method.should.equal(false)
37
- undefined_method.should.not.equal(true)
38
- end
39
-
40
- end
41
-
42
-
43
- class MockResultListener
44
-
45
- def initialize
46
- @pass_count = 0
47
- @failure_count = 0
48
- @spec_count = 0
49
- end
50
-
51
- def pass(spec)
52
- @pass_count += 1
53
- end
54
-
55
- def failure(spec, exception)
56
- @failure_count += 1
57
- end
58
-
59
- def spec(spec)
60
- @spec_count += 1
61
- end
62
-
63
- def verify_failures(count)
64
- check(count, @failure_count)
65
- end
66
-
67
- def verify_passes(count)
68
- check(count, @pass_count)
69
- end
70
-
71
- def verify_specs(count)
72
- check(count, @spec_count)
73
- end
74
-
75
- def check(expected, actual)
76
- if (expected != actual)
77
- raise Test::Unit::AssertionFailedError.new("expected: " + expected.to_s + " actual: " + actual.to_s)
78
- end
79
- end
80
-
81
- end
82
-
83
-
84
- class ContextRunPassingOnceTest < Test::Unit::TestCase
85
-
86
- def setup
87
- @context = TestCon.new(:passing_once_specification)
88
- @result_listener = MockResultListener.new
89
- @context.run(@result_listener)
90
- end
91
-
92
- def test_should_have_one_pass
93
- @result_listener.verify_passes(1)
94
- end
95
-
96
- def test_should_have_no_failures
97
- @result_listener.verify_failures(0)
98
- end
99
-
100
- def test_should_have_one_expectation
101
- @result_listener.verify_specs(1)
102
- end
103
-
104
- end
105
-
106
-
107
- class ContextRunFailingOnceTest < Test::Unit::TestCase
108
-
109
- def setup
110
- @context = TestCon.new(:failing_once_specification)
111
- @result_listener = MockResultListener.new
112
- @context.run(@result_listener)
113
- end
114
-
115
- def test_should_have_one_failure
116
- @result_listener.verify_failures(1)
117
- end
118
-
119
- def test_should_have_no_passes
120
- @result_listener.verify_passes(0)
121
- end
122
-
123
- def test_should_have_one_expectation
124
- @result_listener.verify_specs(1)
125
- end
126
-
127
- end
128
-
129
-
130
- class ContextRunErroringTest < Test::Unit::TestCase
131
-
132
- def setup
133
- @context = TestCon.new(:erroring_once_specification)
134
- @result_listener = MockResultListener.new
135
- @context.run(@result_listener)
136
- end
137
-
138
- def test_should_have_one_failures
139
- @result_listener.verify_failures(1)
140
- end
141
-
142
- def test_should_have_no_passes
143
- @result_listener.verify_passes(0)
144
- end
145
-
146
- def test_should_have_one_spec
147
- @result_listener.verify_specs(1);
148
- end
149
-
150
- end
151
-
152
-
153
- class ContextRunFailingMultipleTest <Test::Unit::TestCase
154
-
155
- def test_should_have_one_expectation
156
- @context = TestCon.new(:failing_multi_specification)
157
- @result_listener = MockResultListener.new
158
- @context.run(@result_listener)
159
- @result_listener.verify_specs(1)
160
- end
161
-
162
- end
163
-
164
-
165
- class ContextRunErroringMultipleTest < Test::Unit::TestCase
166
-
167
- def test_should_have_no_expectations
168
- @context = TestCon.new(:erroring_multi_specification)
169
- @result_listener = MockResultListener.new
170
- @context.run(@result_listener)
171
- @result_listener.verify_specs(1)
172
- end
173
-
174
- end
@@ -1,48 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'spec'
4
-
5
- class DSLTest < Test::Unit::TestCase
6
-
7
- def setup
8
- $default_context = nil
9
- $current_context = nil
10
- end
11
-
12
- def test_should_have_specification_method_defined
13
- assert_equal true, Object.public_method_defined?(:specification)
14
- end
15
-
16
- def test_should_add_specification_to_default_context
17
- specification('foobar') { true.should_equal true }
18
-
19
- assert_equal true, $default_context.specifications.include?('foobar')
20
- end
21
-
22
- def test_should_create_new_context
23
- context 'my_context'
24
-
25
- assert_equal Spec::Context, $my_context.superclass
26
- end
27
-
28
- def test_should_set_current_context_to_new_context
29
- context 'bar'
30
-
31
- assert_equal $current_context, $bar
32
- end
33
-
34
- def test_should_add_bar_specification_to_foo_context
35
- context 'foo'
36
- specification('bar') { true.should_equal true }
37
-
38
- assert_equal true, $foo.specifications.include?('bar')
39
- end
40
-
41
- def test_should_add_bar_specification_to_current_context
42
- context 'foo'
43
- specification('bar') { true.should_equal true }
44
-
45
- assert_equal true, $current_context.specifications.include?('bar')
46
- end
47
-
48
- end
@@ -1,225 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'collection_owner'
4
- require 'spec'
5
-
6
- class ErrorReportingContext < Spec::Context
7
-
8
- def should_satisfy
9
- 5.should.satisfy { |x| x == 3 }
10
- end
11
-
12
- def should_not_satisfy
13
- 3.should.not.satisfy { |x| x == 3 }
14
- end
15
-
16
- def should_equal
17
- Object.should.equal Class
18
- end
19
-
20
- def should_not_equal
21
- Object.should.not.equal Object
22
- end
23
-
24
- def should_be_nil
25
- Object.should.be nil
26
- end
27
-
28
- def should_not_be_nil
29
- nil.should.not.be nil
30
- end
31
-
32
- def should_be_empty
33
- ['foo', 'bar'].should.be.empty
34
- end
35
-
36
- def should_not_be_empty
37
- [].should.not.be.empty
38
- end
39
-
40
- def should_include
41
- ['foo'].should.include('bar')
42
- end
43
-
44
- def should_not_include
45
- ['foo'].should.not.include('foo')
46
- end
47
-
48
- def should_be_true
49
- false.should.be true
50
- end
51
-
52
- def should_be_false
53
- true.should.be false
54
- end
55
-
56
- def should_raise_with_no_error
57
- proc { ''.to_s }.should.raise NoMethodError
58
- end
59
-
60
- def should_raise_with_wrong_error
61
- proc { ''.no_method }.should.raise SyntaxError
62
- end
63
-
64
- def should_not_raise
65
- proc { ''.no_method }.should.not.raise NoMethodError
66
- end
67
-
68
- def should_have_with_length
69
- owner = CollectionOwner.new
70
- owner.should.have(3).items_in_collection_with_length_method
71
- end
72
-
73
- def should_have_at_least_with_length
74
- owner = CollectionOwner.new
75
- owner.should.have.at.least(3).items_in_collection_with_length_method
76
- end
77
-
78
- def should_have_at_most_with_length
79
- owner = CollectionOwner.new
80
- (1..4).each { |n| owner.add_to_collection_with_length_method n }
81
- owner.should.have.at.most(3).items_in_collection_with_length_method
82
- end
83
-
84
- def should_have_with_size
85
- owner = CollectionOwner.new
86
- owner.should.have(3).items_in_collection_with_size_method
87
- end
88
-
89
- def should_have_at_least_with_size
90
- owner = CollectionOwner.new
91
- owner.should.have.at.least(3).items_in_collection_with_size_method
92
- end
93
-
94
- def should_have_at_most_with_size
95
- owner = CollectionOwner.new
96
- (1..4).each { |n| owner.add_to_collection_with_size_method n }
97
- owner.should.have.at.most(3).items_in_collection_with_size_method
98
- end
99
- end
100
-
101
- class ErrorReportingRunner
102
-
103
- def initialize
104
- @failures = []
105
- end
106
-
107
- def pass(spec)
108
- end
109
-
110
- def failure(spec, exception)
111
- @failures << exception.message
112
- end
113
-
114
- def error(spec)
115
- end
116
-
117
- def spec(spec)
118
- end
119
-
120
- def run(context)
121
- context.specifications.each do |example|
122
- the_context = context.new(example)
123
- the_context.run(self)
124
- end
125
- end
126
-
127
- def dump_failures
128
- @failures
129
- end
130
-
131
- end
132
-
133
-
134
- class ErrorReportingTest < Test::Unit::TestCase
135
-
136
- def setup
137
- @runner = ErrorReportingRunner.new
138
- @runner.run(ErrorReportingContext)
139
- end
140
-
141
- def test_should_report_message_for_should_satisfy
142
- assert @runner.dump_failures.include?("Supplied expectation was not satisfied")
143
- end
144
-
145
- def test_should_report_message_for_should_equal
146
- assert @runner.dump_failures.include?("<Object:Class> should equal <Class:Class>"), @runner.dump_failures
147
- end
148
-
149
- def test_should_report_message_for_should_not_equal
150
- assert @runner.dump_failures.include?("<Object:Class> should not equal <Object:Class>"), @runner.dump_failures
151
- end
152
-
153
- def test_should_report_message_for_should_be_nil
154
- assert @runner.dump_failures.include?("<Object:Class> should be nil")
155
- end
156
-
157
- def test_should_report_message_for_should_not_be_nil
158
- assert @runner.dump_failures.include?("nil should not be nil")
159
- end
160
-
161
- def test_should_report_message_for_should_be_empty
162
- assert @runner.dump_failures.include?('<["foo", "bar"]> should be empty')
163
- end
164
-
165
- def test_should_report_message_for_should_not_be_empty
166
- assert @runner.dump_failures.include?("<[]> should not be empty")
167
- end
168
-
169
- def test_should_report_message_for_should_include
170
- assert @runner.dump_failures.include?('<["foo"]> should include <"bar">')
171
- end
172
-
173
- def test_should_report_message_for_should_not_include
174
- assert @runner.dump_failures.include?('<["foo"]> should not include <"foo">')
175
- end
176
-
177
- def test_should_report_message_for_should_be_true
178
- assert @runner.dump_failures.include?("<false> should be <true>")
179
- end
180
-
181
- def test_should_report_message_for_should_be_false
182
- assert @runner.dump_failures.include?("<true> should be <false>")
183
- end
184
-
185
- def test_should_report_message_for_should_raise_with_no_error
186
- assert @runner.dump_failures.include?("<Proc> should raise <\"NoMethodError\">")
187
- end
188
-
189
- def test_should_report_message_for_should_raise_with_wrong_error
190
- assert @runner.dump_failures.include?("<Proc> should raise <\"SyntaxError\">")
191
- end
192
-
193
- def test_should_report_message_for_should_not_raise
194
- assert @runner.dump_failures.include?("<Proc> should not raise <\"NoMethodError\">")
195
- end
196
-
197
- def test_should_report_message_for_should_not_raise
198
- assert @runner.dump_failures.include?("<Proc> should not raise <\"NoMethodError\">")
199
- end
200
-
201
- def test_should_report_message_for_should_have_with_length
202
- assert @runner.dump_failures.include?('<CollectionOwner> should have 3 items_in_collection_with_length_method (has 0)')
203
- end
204
-
205
- def test_should_report_message_for_should_have_at_least_with_length
206
- assert @runner.dump_failures.include?('<CollectionOwner> should have at least 3 items_in_collection_with_length_method (has 0)')
207
- end
208
-
209
- def test_should_report_message_for_should_have_at_most_with_length
210
- assert @runner.dump_failures.include?('<CollectionOwner> should have at most 3 items_in_collection_with_length_method (has 4)')
211
- end
212
-
213
- def test_should_report_message_for_should_have_with_size
214
- assert @runner.dump_failures.include?('<CollectionOwner> should have 3 items_in_collection_with_size_method (has 0)')
215
- end
216
-
217
- def test_should_report_message_for_should_have_at_least_with_size
218
- assert @runner.dump_failures.include?('<CollectionOwner> should have at least 3 items_in_collection_with_size_method (has 0)')
219
- end
220
-
221
- def test_should_report_message_for_should_have_at_most_with_size
222
- assert @runner.dump_failures.include?('<CollectionOwner> should have at most 3 items_in_collection_with_size_method (has 4)')
223
- end
224
-
225
- end