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,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- module Spec
3
- module Runner
4
- class SpecMatcherTest < Test::Unit::TestCase
5
-
6
- def test_should_match_context_and_spec
7
- matcher = SpecMatcher.new("a context with a spec", "a context")
8
- assert matcher.matches?("with a spec")
9
- end
10
-
11
- def test_should_match_with_regexp_reserved_characters
12
- matcher = SpecMatcher.new("a context with #[] a spec", "a context")
13
- assert matcher.matches?("with #[] a spec")
14
- end
15
-
16
- def test_should_not_match_wrong_context
17
- matcher = SpecMatcher.new("another context with a spec", "a context")
18
- assert !matcher.matches?("with a spec")
19
- end
20
-
21
- def test_should_not_match_wrong_spec
22
- matcher = SpecMatcher.new("a context with another spec", "a context")
23
- assert !matcher.matches?("with a spec")
24
- end
25
-
26
- def test_should_match_context_only
27
- matcher = SpecMatcher.new("a context", "a context")
28
- assert matcher.matches?("with a spec")
29
- end
30
-
31
- def test_should_not_match_wrong_context_only
32
- matcher = SpecMatcher.new("another context", "a context")
33
- assert !matcher.matches?("with a spec")
34
- end
35
-
36
- def test_should_match_spec_only
37
- matcher = SpecMatcher.new("with a spec", "a context")
38
- assert matcher.matches?("with a spec")
39
- end
40
-
41
- def test_should_match_wrong_spec_only
42
- matcher = SpecMatcher.new("with another spec", "a context")
43
- assert !matcher.matches?("with a spec")
44
- end
45
- end
46
- end
47
- end
@@ -1,121 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- module Spec
3
- module Runner
4
- class SpecificationTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @reporter = Spec::Mocks::Mock.new "reporter"
8
- end
9
-
10
- def test_should_run_spec_in_scope_of_execution_context
11
- spec = Specification.new("should pass") do
12
- self.should_not_be_an_instance_of Specification
13
- self.should_be_an_instance_of ExecutionContext
14
- end
15
- @reporter.should_receive(:spec_started).with "should pass"
16
- @reporter.should_receive(:spec_finished).with "should pass", nil, nil
17
- spec.run @reporter
18
- end
19
-
20
- def test_should_add_itself_to_reporter_when_passes
21
- spec = Specification.new("spec") {}
22
- @reporter.should_receive(:spec_started).with "spec"
23
- @reporter.should_receive(:spec_finished).with "spec", nil, nil
24
- spec.run(@reporter)
25
- end
26
-
27
- def test_should_add_itself_to_reporter_when_fails
28
- error = RuntimeError.new
29
- spec = Specification.new("spec") { raise error }
30
- @reporter.should_receive(:spec_started).with "spec"
31
- @reporter.should_receive(:spec_finished).with "spec", error, "spec"
32
- spec.run(@reporter)
33
- end
34
-
35
- def test_should_add_itself_to_reporter_when_calling_run_dry
36
- spec = Specification.new("spec") {}
37
- @reporter.should_receive(:spec_started).with "spec"
38
- @reporter.should_receive(:spec_finished).with "spec"
39
- spec.run(@reporter, nil, nil, true)
40
- end
41
-
42
- def test_should_verify_mocks_after_teardown
43
- spec = Specification.new("spec") do
44
- mock = mock("a mock")
45
- mock.should_receive(:poke)
46
- end
47
- @reporter.should_receive(:spec_started).with "spec"
48
- @reporter.should_receive(:spec_finished) do |spec_name, error|
49
- spec_name.should_equal "spec"
50
- error.message.should_match(/expected 'poke' once, but received it 0 times/)
51
- end
52
- spec.run @reporter
53
- end
54
-
55
- def test_should_run_teardown_even_when_main_block_fails
56
- spec = Specification.new("spec") do
57
- raise "in body"
58
- end
59
- teardown = lambda do
60
- raise "in teardown"
61
- end
62
- @reporter.should_receive(:spec_started).with "spec"
63
- @reporter.should_receive(:spec_finished) do |spec, error, location|
64
- spec.should_equal "spec"
65
- location.should_equal "spec"
66
- error.message.should_equal "in body"
67
- end
68
- spec.run @reporter, nil, teardown
69
- end
70
-
71
- def test_should_supply_setup_as_spec_name_if_failure_in_setup
72
- spec = Specification.new("spec") do
73
- end
74
- setup = lambda do
75
- raise "in setup"
76
- end
77
- @reporter.should_receive(:spec_started).with "spec"
78
- @reporter.should_receive(:spec_finished) do |name, error, location|
79
- name.should_equal "spec"
80
- error.message.should_equal "in setup"
81
- location.should_equal "setup"
82
- end
83
- spec.run @reporter, setup
84
- end
85
-
86
- def test_should_supply_teardown_as_failure_location_if_failure_in_teardown
87
- spec = Specification.new("spec") do
88
- end
89
- teardown = lambda do
90
- raise "in teardown"
91
- end
92
- @reporter.should_receive(:spec_started).with "spec"
93
- @reporter.should_receive(:spec_finished) do |name, error, location|
94
- name.should_equal "spec"
95
- error.message.should_equal "in teardown"
96
- location.should_equal "teardown"
97
- end
98
- spec.run @reporter, nil, teardown
99
- end
100
-
101
- def test_should_match_if_name_matches_end_of_input
102
- spec = Specification.new("spec")
103
- assert spec.matches_matcher?(SpecMatcher.new("context spec", "context"))
104
- end
105
-
106
- def test_should_match_if_name_matches_entire_input
107
- spec = Specification.new("spec")
108
- assert spec.matches_matcher?(SpecMatcher.new("spec", "context"))
109
- end
110
-
111
- def test_should_not_match_if_name_does_not_match
112
- spec = Specification.new("otherspec")
113
- assert !spec.matches_matcher?(SpecMatcher.new("context spec", "context"))
114
- end
115
-
116
- def teardown
117
- @reporter.__verify
118
- end
119
- end
120
- end
121
- end
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- require 'spec/test_to_spec/ruby2ruby'
3
-
4
- R2r2r = RubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
5
- eval R2r2r
6
-
7
- class RubyToRubyToRuby
8
- class<<self
9
- eval RubyToRuby.translate(class<<RubyToRuby;self;end, :translate)
10
- end
11
- eval RubyToRuby.translate(RubyToRuby, :initialize)
12
- end
13
-
14
- class R2RTest < Test::Unit::TestCase
15
-
16
- def test_self_translation
17
- r2r2r2 = RubyToRubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
18
- r2r2r2r = RubyToRubyToRuby.translate(RubyToRubyToRuby)
19
- # File.open('1','w'){|f| f.write r2r2r}
20
- # File.open('2','w'){|f| f.write r2r2r2}
21
- # File.open('3','w'){|f| f.write r2r2r2r}
22
- assert_equal(R2r2r,r2r2r2)
23
- assert_equal(R2r2r,r2r2r2r)
24
- end
25
-
26
- def hairy_method(z,x=10,y=20*z.abs,&blok)
27
- n = 1 + 2 * 40.0 / (z - 2)
28
- retried = false
29
- begin
30
- raise ArgumentError, n if retried
31
- n -= yield x,y,z,[z,x,y].map(&blok)
32
- n /= 1.1 until n < 500
33
- n = "hop hop #{"%.4f" % n}"
34
- raise n
35
- rescue RuntimeError => e
36
- raise if n != e.message
37
- n = lambda{|i|
38
- lambda{|j| "#{i} #{z+2*2} #{j.message.reverse}"
39
- }
40
- }[n].call(e)
41
- unless retried
42
- retried = true
43
- retry
44
- end
45
- rescue ArgumentError => e
46
- e.message
47
- rescue
48
- end
49
- ensure
50
- x << "ensure a-working"
51
- end
52
-
53
- def foobar a, &block; block.call(a) end
54
- def k; foobar [1,2,3].each { |x| x*2 } do |x| x*2 end end
55
-
56
- def test_block_predecence_escape
57
- eval RubyToRuby.translate(self.class, :k).sub(" k"," l")
58
- assert_equal(k, l)
59
- end
60
-
61
- def test_hairy_method
62
- eval RubyToRuby.translate(self.class, :hairy_method).sub(" h", " f")
63
-
64
- blk = lambda{|x,y,z,arr|
65
- unless y
66
- x.to_i*2
67
- else
68
- x.to_i*y*z*arr.inject(1){|s,i| s+i}
69
- end
70
- }
71
- x1 = ""
72
- x2 = ""
73
- res = [hairy_method(-5,x1,&blk), fairy_method(-5,x2,&blk)]
74
- assert_equal(res.first, res.last)
75
- assert_equal(x1, x2)
76
- assert_equal("ensure a-working", x1)
77
- end
78
-
79
- end
@@ -1,207 +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
-
7
- module Spec
8
- module TestToSpec
9
- # This Test::Unit class verifies that the core Test::Unit assertions
10
- # can be translated to RSpec.
11
- # The various test_assert_* methods must follow a rigorous form -
12
- #
13
- # The first statement must be a Test::Unit assertion, and the second
14
- # statement its expected RSpec translation.
15
- #
16
- # For each of the test_assert_* method, a test_assert_*_translation
17
- # method is dynamically added, which will test that the translation
18
- # of the 1st statement is effectively equal to the second one.
19
- class SexpTransformerAssertionTest < Test::Unit::TestCase
20
- def setup
21
- @t = SexpTransformer.new
22
- end
23
-
24
- def test_assert
25
- assert(:foo == :foo)
26
- (:foo == :foo).should_be true
27
- end
28
-
29
- def test_assert_with_message
30
- assert(:foo == :foo, "msg")
31
- (:foo == :foo).should_be true
32
- end
33
-
34
- def test_assert_nil
35
- assert_nil([].index(5))
36
- ([].index(5)).should_be nil
37
- end
38
-
39
- def test_assert_nil_with_message
40
- assert_nil([].index(5), "msg")
41
- ([].index(5)).should_be nil
42
- end
43
-
44
- def test_assert_not_nil
45
- assert_not_nil([5].index(5))
46
- ([5].index(5)).should_not_be nil
47
- end
48
-
49
- def test_assert_not_nil_with_message
50
- assert_not_nil(3, "msg")
51
- 3.should_not_be nil
52
- end
53
-
54
- def test_assert_equal
55
- assert_equal(2, 1+1)
56
- (1+1).should_equal 2
57
- end
58
-
59
- def test_assert_equal_with_message
60
- assert_equal(2, 1+1, "1+1 should equal 2")
61
- (1+1).should_equal 2
62
- end
63
-
64
- def test_assert_equal_with_each
65
- [0,1,2].each_with_index do |b, c|
66
- assert_equal c, b
67
- end
68
- [0,1,2].each_with_index do |b, c|
69
- b.should_equal c
70
- end
71
- end
72
-
73
- def test_assert_not_equal
74
- assert_not_equal(2+3, 1)
75
- 1.should_not_equal 2+3
76
- end
77
-
78
- def test_assert_not_equal_with_message
79
- assert_not_equal(2+3, 1, "msg")
80
- 1.should_not_equal 2+3
81
- end
82
-
83
- def test_assert_same
84
- assert_same(2, 1+1)
85
- (1+1).should_be 2
86
- end
87
-
88
- def test_assert_same_with_msg
89
- assert_same(2, 1+1, "msg")
90
- (1+1).should_be 2
91
- end
92
-
93
- def test_assert_not_same
94
- assert_not_same(2+3, 1)
95
- 1.should_not_be 2+3
96
- end
97
-
98
- def test_assert_not_same_with_message
99
- assert_not_same(2+3, 1, "msg")
100
- 1.should_not_be 2+3
101
- end
102
-
103
- def test_assert_instance_of
104
- assert_instance_of Fixnum, 2
105
- 2.should_be_instance_of Fixnum
106
- end
107
-
108
- def test_assert_kind_of
109
- assert_kind_of Fixnum, 2
110
- 2.should_be_kind_of Fixnum
111
- end
112
-
113
- def test_assert_match
114
- assert_match(/foo/, 'foo')
115
- 'foo'.should_match(/foo/)
116
- end
117
-
118
- def test_assert_no_match
119
- assert_no_match(/foo/, 'bar')
120
- 'bar'.should_not_match(/foo/)
121
- end
122
-
123
- def test_assert_respond_to
124
- assert_respond_to 2, :to_f
125
- 2.should_respond_to :to_f
126
- end
127
-
128
- def test_assert_respond_to_with_message
129
- assert_respond_to 2, :to_f, "msg"
130
- 2.should_respond_to :to_f
131
- end
132
-
133
- def test_assert_in_delta
134
- assert_in_delta 123.5, 123.45, 0.1
135
- 123.45.should_be_close 123.5, 0.1
136
- end
137
-
138
- def test_assert_in_delta_with_message
139
- assert_in_delta 123.5, 123.45, 0.1, "123.45 should be close to 123.5"
140
- 123.45.should_be_close 123.5, 0.1
141
- end
142
-
143
- def test_assert_raise
144
- assert_raise(ZeroDivisionError){ 1/0 }
145
- lambda {1/0}.should_raise(ZeroDivisionError)
146
- end
147
-
148
- def test_assert_raise_with_message
149
- assert_raise(ZeroDivisionError, "msg"){ 1/0 }
150
- lambda {1/0}.should_raise(ZeroDivisionError)
151
- end
152
-
153
- def test_assert_raises
154
- assert_raises(ZeroDivisionError){ 1/0 }
155
- lambda {1/0}.should_raise(ZeroDivisionError)
156
- end
157
-
158
- def test_assert_nothing_raised
159
- assert_nothing_raised{ 0/1 }
160
- lambda {0/1}.should_not_raise
161
- end
162
-
163
- def test_assert_throws
164
- assert_throws(:foo){ throw :foo }
165
- lambda {throw :foo}.should_throw(:foo)
166
- end
167
-
168
- def test_assert_nothing_thrown
169
- assert_nothing_thrown{ 0/1 }
170
- lambda {0/1}.should_not_throw
171
- end
172
-
173
- def test_assert_block
174
- assert_block{:foo != :bar}
175
- lambda{:foo != :bar}.should_be true
176
- end
177
-
178
- # Returns the body of one of my methods as a Sexp
179
- def self.body(sym)
180
- t = ParseTree.new.parse_tree_for_method(self, sym)
181
- t[2][1][2..-1]
182
- end
183
-
184
- # Verifies that the 1st statement in test method +m+ is properly translated
185
- # to the 2nd statement.
186
- def should_translate(m)
187
- body = self.class.body(m)
188
- assert_equal 2, body.length
189
- test_unit_sexp = body[0]
190
- rspec_sexp = body[1]
191
- translation = @t.process(test_unit_sexp)
192
- verify_sexp_equal(rspec_sexp, translation)
193
- end
194
-
195
- # Dynamically define extra test methods
196
- methods = self.instance_methods(false).reject do |m|
197
- m == "test_translations" || !(m =~ /^test_assert/)
198
- end
199
- methods.each do |m|
200
- define_method "#{m}_translation" do
201
- should_translate(m)
202
- end
203
- end
204
-
205
- end
206
- end
207
- end