rspec 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,303 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- require 'test/unit'
3
- require 'rubygems'
4
- require 'parse_tree'
5
- require 'spec/test_to_spec/sexp_transformer'
6
- require 'spec/test_to_spec/ruby2ruby'
7
-
8
- module Spec
9
- module TestToSpec
10
- class FirstTest < Test::Unit::TestCase
11
- def test_foo
12
- end
13
- end
14
- class FirstContext
15
- def wrapper
16
- context "First" do
17
- specify "foo" do
18
- end
19
- end
20
- end
21
- end
22
-
23
- class SecondTest < Test::Unit::TestCase
24
- def test_foo
25
- assert_same 3, 1+2
26
- assert_match(/sla/, 'aslak')
27
- end
28
- end
29
- class SecondContext
30
- def wrapper
31
- context "Second" do
32
- specify "foo" do
33
- (1+2).should_be 3
34
- 'aslak'.should_match(/sla/)
35
- end
36
- end
37
- end
38
- end
39
-
40
- class ThirdTest < Test::Unit::TestCase
41
- def test_bar
42
- one = 1
43
- two = 2
44
- end
45
- def test_foo
46
- end
47
- end
48
- class ThirdContext
49
- def wrapper
50
- context "Third" do
51
- specify "bar" do
52
- one = 1
53
- two = 2
54
- end
55
- specify "foo" do
56
- end
57
- end
58
- end
59
- end
60
-
61
- class FourthTest < Test::Unit::TestCase
62
- def setup
63
- one = 1
64
- end
65
- def test_foo
66
- two = 2
67
- end
68
- end
69
- class FourthContext
70
- def wrapper
71
- context "Fourth" do
72
- setup do
73
- one = 1
74
- end
75
- specify "foo" do
76
- two = 2
77
- end
78
- end
79
- end
80
- end
81
-
82
- class FifthTest
83
- def setup
84
- one = 1
85
- end
86
- def foo
87
- two = 2
88
- end
89
- end
90
- class FifthContext
91
- def wrapper
92
- context "Fifth" do
93
- setup do
94
- one = 1
95
- end
96
- def foo
97
- two = 2
98
- end
99
- end
100
- end
101
- end
102
-
103
- class SixthTest
104
- def setup
105
- end
106
- def foo
107
- two = 2
108
- end
109
- end
110
- class SixthContext
111
- def wrapper
112
- context "Sixth" do
113
- setup do
114
- end
115
-
116
- def foo
117
- two = 2
118
- end
119
- end
120
- end
121
- end
122
-
123
- class SeventhTest
124
- def foo
125
- two = 2
126
- end
127
- end
128
- class SeventhContext
129
- def wrapper
130
- context "Seventh" do
131
- setup do
132
- end
133
- def foo
134
- two = 2
135
- end
136
- end
137
- end
138
- end
139
-
140
- class EighthTest < Test::Unit::TestCase
141
- def foo
142
- two = 2
143
- end
144
-
145
- def teardown
146
- torn = true
147
- end
148
-
149
- def test_foo
150
- bar = foo
151
- assert_equal 2, bar
152
- end
153
- end
154
- class EighthContext
155
- def wrapper
156
- context "Eighth" do
157
- setup do
158
- end
159
- teardown do
160
- torn = true
161
- end
162
- specify "foo" do
163
- bar = foo
164
- bar.should_equal 2
165
- end
166
- def foo
167
- two = 2
168
- end
169
- end
170
- end
171
- end
172
-
173
- class NinthTest < Test::Unit::TestCase
174
- def test_2_should_be_pair
175
- foo = 1
176
- assert_pair(2)
177
- end
178
-
179
- def assert_pair(n)
180
- assert_equal 0, n%2
181
- end
182
- end
183
- class NinthContext
184
- def wrapper
185
- context "Ninth" do
186
- setup do
187
- end
188
- specify "2 should be pair" do
189
- foo = 1
190
- assert_pair(2)
191
- end
192
- def assert_pair(n)
193
- (n%2).should_equal 0
194
- end
195
- end
196
- end
197
- end
198
-
199
- class SexpTransformerTest < Test::Unit::TestCase
200
- def test_first
201
- should_translate_class_to_context('First')
202
- end
203
-
204
- def test_second
205
- should_translate_class_to_context('Second')
206
- end
207
-
208
- def test_third
209
- should_translate_class_to_context('Third')
210
- end
211
-
212
- def test_fourth
213
- should_translate_class_to_context('Fourth')
214
- end
215
-
216
- def test_fifth
217
- should_translate_class_to_context('Fifth')
218
- end
219
-
220
- def test_sixth
221
- should_translate_class_to_context('Sixth')
222
- end
223
-
224
- def test_seventh
225
- should_translate_class_to_context('Seventh')
226
- end
227
-
228
- def test_eighth
229
- should_translate_class_to_context('Eighth')
230
- end
231
-
232
- def test_ninth
233
- should_translate_class_to_context('Ninth')
234
- end
235
-
236
- class Something
237
- def method_with_asserts
238
- assert_equal 2, 3
239
- end
240
- end
241
- class SomethingTranslated
242
- def method_with_asserts
243
- 3.should_equal 2
244
- end
245
- end
246
- def test_translates_regular_method_bodies
247
- something = ParseTree.new.parse_tree_for_method(Something, :method_with_asserts)
248
- expected_something_translated = ParseTree.new.parse_tree_for_method(SomethingTranslated, :method_with_asserts)
249
- actual_something_translated = @t.process(something)
250
- verify_sexp_equal expected_something_translated, actual_something_translated
251
- end
252
-
253
- def should_translate_class_to_context(name, debug=false)
254
- test_class_name = "#{name}Test"
255
- context_class_name = "#{name}Context"
256
- t = test_class_exp(eval(test_class_name))
257
- if(debug)
258
- puts "ORIGINAL"
259
- pp t
260
- end
261
- c = wrapper_exp(eval(context_class_name))
262
-
263
- trans = @t.process(t)
264
-
265
- verify_sexp_equal c, trans
266
-
267
- =begin
268
- if c != trans
269
- # Try to print out the Ruby2Ruby of the trans
270
- begin
271
- trans2ruby = @r2r.process(trans.dup[0])
272
- # Parse the translation again
273
- retranslated_class_name = "#{context_class_name}Retranslated"
274
- eval "class #{retranslated_class_name}\ndef wrapper\n#{trans2ruby}\nend\nend"
275
- retranslated_class = eval(retranslated_class_name)
276
- retranslated_tree = wrapper_exp(retranslated_class)
277
- retranslated_tree
278
- verify_sexp_equal c, retranslated_tree
279
- rescue SexpProcessorError => e
280
- # That didn't work, just print the tree
281
- verify_sexp_equal c, trans
282
- end
283
- end
284
- =end
285
- # Verify that we can evaluate it after translated by R2R
286
- eval(@r2r.process(trans[0]))
287
- end
288
-
289
- def test_class_exp(klass)
290
- ParseTree.new.parse_tree(klass)[0]
291
- end
292
-
293
- def wrapper_exp(klass)
294
- ParseTree.new.parse_tree_for_method(klass, :wrapper)[2][1][2..-1]
295
- end
296
-
297
- def setup
298
- @t = SexpTransformer.new
299
- @r2r = RubyToRuby.new
300
- end
301
- end
302
- end
303
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- require 'spec/test_to_spec/test_case_ext'
3
- require 'spec/test_to_spec/testfiles/test_unit_api_test'
4
- require 'tempfile'
5
-
6
- class TestCaseExtTest < Test::Unit::TestCase
7
- def test_to_rspec_should_return_rspec_context
8
- translated = TestUnitApiTest.to_rspec
9
- translated_tmp = Tempfile.open("translated")
10
- translated_tmp.write(translated)
11
- translated_tmp.flush
12
- translated_tmp.close
13
-
14
- expected_path = File.dirname(__FILE__) + '/testfiles/test_unit_api_spec.rb'
15
- expected = File.open(expected_path).read
16
-
17
- diff = `diff -w -u #{expected_path} #{translated_tmp.path}`
18
- if diff.strip != ""
19
- # We should fail here....
20
- #fail("Conversion didn't match expectation. Diff:\n#{diff}")
21
- else
22
- assert true # Just so we get an assertion count in the output
23
- end
24
- end
25
- end
@@ -1,75 +0,0 @@
1
- module Spec
2
- module TestToSpec
3
- context "TestUnitApi" do
4
- setup do
5
- @an_int = 789
6
- end
7
-
8
- teardown do
9
- nil
10
- end
11
-
12
- specify "can be translated to rspec" do
13
- a_float = 123.45
14
- a_nil = nil
15
- true.should_be true
16
- @an_int.should_not_be nil
17
- lambda {
18
- true
19
- }.should_be true
20
- lambda {
21
- true
22
- }.should_be true
23
- @an_int.should_equal 789
24
- a_float.should_be_close 123.5, 0.1
25
- @an_int.should_be_instance_of Fixnum
26
- @an_int.should_be_kind_of Numeric
27
- @an_int.to_s.should_match /789/
28
- a_nil.should_be nil
29
- @an_int.to_s.should_not_match /7890/
30
- @an_int.should_not_equal 780
31
- @an_int.should_not_be nil
32
- a_float.should_not_be @an_int
33
- lambda {
34
- foo = 1
35
- }.should_not_raise
36
- lambda {
37
- bar = 2
38
- }.should_not_raise
39
- [2].each {|a|
40
- a.should_equal 2
41
- }
42
- [0,1,2].each_with_index {|b, c|
43
- b.should_equal c
44
- }
45
- lambda {
46
- zip = 3
47
- }.should_not_throw
48
- lambda {
49
- zap = 4
50
- }.should_not_throw
51
- lambda {
52
- raise(NotImplementedError)
53
- }.should_raise(NotImplementedError)
54
- lambda {
55
- raise(NotImplementedError)
56
- }.should_raise(NotImplementedError)
57
- lambda {
58
- raise(NotImplementedError)
59
- }.should_raise(NotImplementedError)
60
- lambda {
61
- raise(NotImplementedError)
62
- }.should_raise(NotImplementedError)
63
- @an_int.should_respond_to :to_f
64
- a_float.should_be a_float
65
- lambda {
66
- throw(:foo)
67
- }.should_throw(:foo)
68
- lambda {
69
- throw(:foo)
70
- }.should_throw(:foo)
71
- end
72
-
73
- end
74
- end
75
- end
@@ -1,70 +0,0 @@
1
- require 'test/unit'
2
-
3
- class TestUnitApiTest < Test::Unit::TestCase
4
-
5
- def setup
6
- @an_int = 789
7
- end
8
-
9
- def teardown
10
- end
11
-
12
- def assert_pair(n)
13
- assert_equal 0, n%2
14
- end
15
-
16
- def test_can_be_translated_to_rspec
17
- a_float = 123.45
18
- a_nil = nil
19
-
20
- assert_pair(2)
21
-
22
- assert true
23
- assert_not_nil @an_int
24
- assert_block { true }
25
- assert_block do
26
- true
27
- end
28
- assert_equal 789 ,@an_int, "a message"
29
- assert_in_delta 123.5, a_float, 0.1, "a message"
30
- assert_instance_of Fixnum, @an_int, "a message"
31
- assert_kind_of Numeric, @an_int, "a message"
32
- assert_match(/789/ , @an_int.to_s)
33
- assert_nil a_nil
34
- assert_no_match(/7890/, @an_int.to_s, "a message")
35
- assert_not_equal 780, @an_int
36
- assert_not_nil @an_int, "a message"
37
- assert_not_same @an_int, a_float, "a message"
38
- assert_nothing_raised { foo = 1 }
39
- assert_nothing_raised do
40
- bar = 2
41
- end
42
- [2].each do |a|
43
- assert_equal 2, a
44
- end
45
- [0,1,2].each_with_index do |b, c|
46
- assert_equal c, b
47
- end
48
- assert_nothing_thrown { zip = 3 }
49
- assert_nothing_thrown do
50
- zap = 4
51
- end
52
- #assert_operator object1, operator, object2, "a message"
53
- assert_raise(NotImplementedError){ raise NotImplementedError }
54
- assert_raise(NotImplementedError) do
55
- raise NotImplementedError
56
- end
57
- assert_raises(NotImplementedError){ raise NotImplementedError }
58
- assert_raises(NotImplementedError) do
59
- raise NotImplementedError
60
- end
61
- assert_respond_to @an_int, :to_f, "a message"
62
- assert_same a_float, a_float, "a message"
63
- #assert_send send_array, "a message"
64
- assert_throws(:foo, "a message"){ throw :foo }
65
- assert_throws(:foo, "a message") do
66
- throw :foo
67
- end
68
- end
69
-
70
- end