rspec 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGES +9 -5
  2. data/Rakefile +35 -29
  3. data/bin/spec +0 -5
  4. data/doc/README +5 -0
  5. data/doc/config.yaml +2 -0
  6. data/doc/plugin/syntax.rb +38 -0
  7. data/doc/reference/rspec reference.page +0 -0
  8. data/doc/src/community.page +8 -0
  9. data/doc/src/default.css +198 -0
  10. data/doc/src/default.template +34 -0
  11. data/doc/src/documentation/api.page +251 -0
  12. data/doc/src/documentation/index.page +8 -0
  13. data/doc/src/documentation/mocks.page +207 -0
  14. data/doc/src/documentation/specs.page +20 -0
  15. data/doc/src/download.page +8 -0
  16. data/doc/src/examples.page +9 -0
  17. data/doc/src/images/ul.gif +0 -0
  18. data/doc/src/index.page +8 -0
  19. data/doc/src/tools/index.page +8 -0
  20. data/doc/src/tools/rails.page +8 -0
  21. data/doc/src/tools/rake.page +8 -0
  22. data/doc/src/tools/rcov.page +8 -0
  23. data/doc/src/tools/spec_runner.page +8 -0
  24. data/doc/src/tools/specdoc.page +8 -0
  25. data/doc/src/tools/test2rspec.page +8 -0
  26. data/doc/src/ul.gif +0 -0
  27. data/doc/src/why_rspec.page +8 -0
  28. data/examples/mocking_spec.rb +2 -2
  29. data/examples/spec_framework_spec.rb +4 -4
  30. data/lib/spec/api/helper/have_helper.rb +55 -55
  31. data/lib/spec/api/mock.rb +111 -38
  32. data/lib/spec/runner/backtrace_tweaker.rb +4 -4
  33. data/lib/spec/runner/context.rb +2 -1
  34. data/lib/spec/runner/context_runner.rb +3 -3
  35. data/lib/spec/runner/option_parser.rb +8 -4
  36. data/lib/spec/runner/simple_text_reporter.rb +29 -19
  37. data/lib/spec/runner/specification.rb +2 -1
  38. data/lib/spec/version.rb +1 -1
  39. data/test/rake/rcov_testtask.rb +45 -0
  40. data/test/spec/api/helper/arbitrary_predicate_test.rb +39 -24
  41. data/test/spec/api/helper/equality_test.rb +19 -0
  42. data/test/spec/api/helper/should_have_test.rb +183 -0
  43. data/test/spec/api/mock_arg_constraints_test.rb +90 -0
  44. data/test/spec/api/mock_test.rb +101 -21
  45. data/test/spec/runner/context_runner_test.rb +3 -3
  46. data/test/spec/runner/context_test.rb +2 -5
  47. data/test/spec/runner/execution_context_test.rb +1 -1
  48. data/test/spec/runner/option_parser_test.rb +16 -8
  49. data/test/spec/runner/simple_text_reporter_test.rb +57 -33
  50. data/test/spec/runner/specification_test.rb +7 -7
  51. data/test/spec/tool/command_line_test.rb +4 -4
  52. data/test/test_helper.rb +2 -2
  53. metadata +37 -8
  54. data/README +0 -38
  55. data/TODO +0 -9
  56. data/TUTORIAL +0 -259
  57. data/WHY_RSPEC +0 -115
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+ class PassingConstraintsTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @mock = Mock.new("test mock")
9
+ end
10
+
11
+ def test_should_handle_anything
12
+ @mock.should.receive(:random_call).at.least(:once).with(:anything)
13
+ @mock.random_call()
14
+ @mock.random_call(1)
15
+ @mock.random_call("a", 2)
16
+ @mock.random_call([], {}, "joe", 7)
17
+ @mock.__verify
18
+ end
19
+
20
+ def test_should_handle_anything_in_multi_args
21
+ @mock.should.receive(:random_call).with("a", :anything, "c")
22
+ @mock.random_call("a", "whatever", "c")
23
+ @mock.__verify
24
+ end
25
+
26
+ def test_should_accept_fixnum_as_numeric
27
+ @mock.should.receive(:random_call).with(:numeric)
28
+ @mock.random_call(1)
29
+ @mock.__verify
30
+ end
31
+
32
+ def test_should_accept_float_as_numeric
33
+ @mock.should.receive(:random_call).with(:numeric)
34
+ @mock.random_call(1.5)
35
+ @mock.__verify
36
+ end
37
+
38
+ def test_should_match_true_for_boolean
39
+ @mock.should.receive(:random_call).with(:boolean)
40
+ @mock.random_call(true)
41
+ @mock.__verify
42
+ end
43
+
44
+ def test_should_match_false_for_boolean
45
+ @mock.should.receive(:random_call).with(:boolean)
46
+ @mock.random_call(false)
47
+ @mock.__verify
48
+ end
49
+
50
+ def test_should_match_string
51
+ @mock.should.receive(:random_call).with(:string)
52
+ @mock.random_call("a string")
53
+ @mock.__verify
54
+ end
55
+
56
+ end
57
+
58
+ class FailingConstraintsTest < Test::Unit::TestCase
59
+
60
+ def setup
61
+ @mock = Mock.new("test mock")
62
+ end
63
+
64
+ def test_should_reject_non_numeric
65
+ @mock.should.receive(:random_call).with(:numeric)
66
+ assert_raise(MockExpectationError) do
67
+ @mock.random_call("1")
68
+ @mock.__verify
69
+ end
70
+ end
71
+
72
+ def test_should_reject_non_boolean
73
+ @mock.should.receive(:random_call).with(:boolean)
74
+ assert_raise(MockExpectationError) do
75
+ @mock.random_call("false")
76
+ @mock.__verify
77
+ end
78
+ end
79
+
80
+ def test_should_reject_non_string
81
+ @mock.should.receive(:random_call).with(:string)
82
+ assert_raise(MockExpectationError) do
83
+ @mock.random_call(123)
84
+ @mock.__verify
85
+ end
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -10,7 +10,7 @@ module Spec
10
10
  end
11
11
 
12
12
  def test_should_report_line_number_of_expectation_of_unreceived_message
13
- @mock.should_receive(:wont_happen).with("x", 3)
13
+ @mock.should.receive(:wont_happen).with("x", 3)
14
14
 
15
15
  begin
16
16
  @mock.__verify
@@ -21,33 +21,33 @@ module Spec
21
21
  end
22
22
 
23
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 }
24
+ @mock.should.receive(:random_call).with("a","b","c").and.return { |a,b,c| c+b+a }
25
25
  assert_equal "cba", @mock.random_call("a","b","c")
26
26
  # TODO: remove __verify when migrating to self-hosting. Verify happens transparently in teardown. (AH)
27
27
  @mock.__verify
28
28
  end
29
29
 
30
30
  def test_should_allow_parameter_as_return_value
31
- @mock.should_receive(:random_call).with("a","b","c").and_return("booh")
31
+ @mock.should.receive(:random_call).with("a","b","c").and.return("booh")
32
32
  assert_equal "booh", @mock.random_call("a","b","c")
33
33
  @mock.__verify
34
34
  end
35
35
 
36
36
  def test_return_nil_if_no_return_value_set
37
- @mock.should_receive(:random_call).with("a","b","c")
37
+ @mock.should.receive(:random_call).with("a","b","c")
38
38
  assert_nil @mock.random_call("a","b","c")
39
39
  @mock.__verify
40
40
  end
41
41
 
42
42
  def test_should_test_multiple_calls_to_method_with_same_parameters
43
- @mock.should_receive(:random_call).twice.with("a","b","c")
43
+ @mock.should.receive(:random_call).twice.with("a","b","c")
44
44
  @mock.random_call("a","b","c")
45
45
  @mock.random_call("a","b","c")
46
46
  @mock.__verify
47
47
  end
48
48
 
49
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")
50
+ @mock.should.receive(:random_call).with("a","b","c").and.return("booh")
51
51
  assert_raise(MockExpectationError) {
52
52
  @mock.random_call("a","d","c")
53
53
  }
@@ -67,7 +67,7 @@ module Spec
67
67
 
68
68
  # TODO: rename to should_raise_exception_telling_what_message_was_not_received
69
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")
70
+ @mock.should.receive(:random_call).twice.with("a","b","c").and.return("booh")
71
71
  @mock.random_call("a","b","c")
72
72
  assert_raise(MockExpectationError) do
73
73
  @mock.__verify
@@ -75,7 +75,7 @@ module Spec
75
75
  end
76
76
 
77
77
  def test_should_use_block_for_expectation_if_provided
78
- @mock.should_receive(:random_call) do | a, b |
78
+ @mock.should.receive(:random_call) do | a, b |
79
79
  a.should.equal("a")
80
80
  b.should.equal("b")
81
81
  "booh"
@@ -85,21 +85,21 @@ module Spec
85
85
  end
86
86
 
87
87
  def test_failing_expectation_block_throws
88
- @mock.should_receive(:random_call) {| a | a.should.be true}
88
+ @mock.should.receive(:random_call) {| a | a.should.be true}
89
89
  assert_raise(MockExpectationError) do
90
90
  @mock.random_call false
91
91
  end
92
92
  end
93
93
 
94
94
  def test_two_return_values
95
- @mock.should_receive(:multi_call).twice.with_no_args.and_return_consecutively([1, 2])
95
+ @mock.should.receive(:multi_call).twice.with(:nothing).and.return([1, 2])
96
96
  assert_equal(1, @mock.multi_call)
97
97
  assert_equal(2, @mock.multi_call)
98
98
  @mock.__verify
99
99
  end
100
100
 
101
101
  def test_repeating_final_return_value
102
- @mock.should_receive(:multi_call).at_least_once.with_no_args.and_return_consecutively([1, 2])
102
+ @mock.should.receive(:multi_call).at.least(:once).with(:nothing).and.return([1, 2])
103
103
  assert_equal(1, @mock.multi_call)
104
104
  assert_equal(2, @mock.multi_call)
105
105
  assert_equal(2, @mock.multi_call)
@@ -107,7 +107,7 @@ module Spec
107
107
  end
108
108
 
109
109
  def test_should_throw_on_call_of_never_method
110
- @mock.should_receive(:random_call).never
110
+ @mock.should.receive(:random_call).never
111
111
  assert_raise(MockExpectationError) do
112
112
  @mock.random_call
113
113
  @mock.__verify
@@ -115,47 +115,127 @@ module Spec
115
115
  end
116
116
 
117
117
  def test_should_throw_if_at_least_once_method_not_called
118
- @mock.should_receive(:random_call).at_least_once
118
+ @mock.should.receive(:random_call).at.least(:once)
119
119
  assert_raise(MockExpectationError) do
120
120
  @mock.__verify
121
121
  end
122
122
  end
123
123
 
124
124
  def test_should_not_throw_if_any_number_of_times_method_not_called
125
- @mock.should_receive(:random_call).any_number_of_times
125
+ @mock.should.receive(:random_call).any.number.of.times
126
126
  @mock.__verify
127
127
  end
128
128
 
129
129
  def test_should_not_throw_if_any_number_of_times_method_is_called
130
- @mock.should_receive(:random_call).any_number_of_times
130
+ @mock.should.receive(:random_call).any.number.of.times
131
131
  @mock.random_call
132
132
  @mock.__verify
133
133
  end
134
134
 
135
135
  def test_should_not_throw_if_at_least_once_method_is_called_twice
136
- @mock.should_receive(:random_call).at_least_once
136
+ @mock.should.receive(:random_call).at.least(:once)
137
137
  @mock.random_call
138
138
  @mock.random_call
139
139
  @mock.__verify
140
140
  end
141
141
 
142
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)
143
+ @mock.should.receive(:random_call).once.with(1)
144
+ @mock.should.receive(:random_call).once.with(2)
145
145
  @mock.random_call(1)
146
146
  @mock.random_call(2)
147
147
  @mock.__verify
148
148
  end
149
149
 
150
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)
151
+ @mock.should.receive(:random_call).twice.with(1)
152
+ @mock.should.receive(:random_call).once.with(2)
153
153
  @mock.random_call(1)
154
154
  @mock.random_call(2)
155
155
  @mock.random_call(1)
156
156
  @mock.__verify
157
157
  end
158
-
158
+
159
+ def test_should_not_throw_if_at_least_twice_method_is_called_twice
160
+ @mock.should.receive(:random_call).at.least(:twice)
161
+ @mock.random_call
162
+ @mock.random_call
163
+ @mock.__verify
164
+ end
165
+
166
+ def test_should_not_throw_if_at_least_twice_method_is_called_three_times
167
+ @mock.should.receive(:random_call).at.least(:twice)
168
+ @mock.random_call
169
+ @mock.random_call
170
+ @mock.random_call
171
+ @mock.__verify
172
+ end
173
+
174
+ def test_should_throw_if_at_least_twice_method_is_called_once
175
+ @mock.should.receive(:random_call).at.least(:twice)
176
+ @mock.random_call
177
+ assert_raise(MockExpectationError) do
178
+ @mock.__verify
179
+ end
180
+ end
181
+
182
+ def test_should_throw_if_at_least_twice_method_is_never_called
183
+ @mock.should.receive(:random_call).at.least(:twice)
184
+ assert_raise(MockExpectationError) do
185
+ @mock.__verify
186
+ end
187
+ end
188
+
189
+ def test_should_throw_if_at_least_5_times_method_is_never_called
190
+ @mock.should.receive(:random_call).at.least(5).times
191
+ assert_raise(MockExpectationError) do
192
+ @mock.__verify
193
+ end
194
+ end
195
+
196
+ def test_should_throw_if_at_least_5_times_method_is_called_once
197
+ @mock.should.receive(:random_call).at.least(5).times
198
+ @mock.random_call
199
+ assert_raise(MockExpectationError) do
200
+ @mock.__verify
201
+ end
202
+ end
203
+
204
+ def test_should_not_throw_if_at_least_5_times_method_is_called_5_times
205
+ @mock.should.receive(:random_call).at.least(5).times
206
+ @mock.random_call
207
+ @mock.random_call
208
+ @mock.random_call
209
+ @mock.random_call
210
+ @mock.random_call
211
+ @mock.__verify
212
+ end
213
+
214
+ def test_should_not_throw_if_at_least_5_times_method_is_called_6_times
215
+ @mock.should.receive(:random_call).at.least(5).times
216
+ @mock.random_call
217
+ @mock.random_call
218
+ @mock.random_call
219
+ @mock.random_call
220
+ @mock.random_call
221
+ @mock.random_call
222
+ @mock.__verify
223
+ end
224
+
225
+ def test_raising
226
+ @mock.should.receive(:random_call).and.raise(RuntimeError)
227
+ assert_raise(RuntimeError) do
228
+ @mock.random_call
229
+ end
230
+ end
231
+
232
+ def test_throwing
233
+ @mock.should.receive(:random_call).and.throw(:blech)
234
+ assert_throws(:blech) do
235
+ @mock.random_call
236
+ end
237
+ end
238
+
159
239
  end
160
240
  end
161
241
  end
@@ -5,9 +5,9 @@ module Spec
5
5
  def test_should_call_run_doc_on_context
6
6
  context1 = Api::Mock.new "context1"
7
7
  context2 = Api::Mock.new "context2"
8
- context1.should_receive(:run_docs)
9
- context2.should_receive(:run_docs)
10
- runner = ContextRunner.new ["-d"]
8
+ context1.should.receive(:run_docs)
9
+ context2.should.receive(:run_docs)
10
+ runner = ContextRunner.new ["-d"], false, StringIO.new
11
11
  runner.add_context context1
12
12
  runner.add_context context2
13
13
  runner.run
@@ -10,19 +10,16 @@ module Spec
10
10
  end
11
11
 
12
12
  def test_should_add_itself_to_listener_on_run
13
- @listener.should_receive(:add_context).with "context"
13
+ @listener.should.receive(:add_context).with "context", :anything
14
14
  @context.run(@listener)
15
15
  @listener.__verify
16
16
  end
17
17
 
18
18
  def test_should_add_itself_to_listener_on_run_docs
19
- @listener.should_receive(:add_context).with "context"
19
+ @listener.should.receive(:add_context).with "context"
20
20
  @context.run_docs(@listener)
21
21
  @listener.__verify
22
22
  end
23
-
24
- def test_should_execute_setup_from_inherited_context
25
- end
26
23
 
27
24
  end
28
25
  end
@@ -4,7 +4,7 @@ module Spec
4
4
  class ExecutionContextTest < Test::Unit::TestCase
5
5
  def test_should_add_new_mock_to_spec_when_mock_message_received
6
6
  spec = Api::Mock.new "spec"
7
- spec.should_receive(:add_mock) {|mock| mock.should.be.instance.of Api::Mock}
7
+ spec.should.receive(:add_mock) {|mock| mock.instance_of? Api::Mock}
8
8
  ec = ExecutionContext.new spec
9
9
  mock = ec.mock("a mock")
10
10
  end
@@ -5,46 +5,54 @@ module Spec
5
5
  module Runner
6
6
  class OptionParserTest < Test::Unit::TestCase
7
7
 
8
+ def setup
9
+ @err = StringIO.new
10
+ end
11
+
8
12
  def test_verbose_should_be_true_by_default
9
- options = OptionParser.parse([])
13
+ options = OptionParser.parse([], false, @err)
10
14
  assert(!options.verbose)
11
15
  end
12
16
 
13
17
  def test_out_should_be_stdout_by_default
14
- options = OptionParser.parse([])
18
+ options = OptionParser.parse([], false, @err)
15
19
  assert_equal(STDOUT, options.out)
16
20
  end
17
21
 
18
22
  def test_verbose_should_be_settable_with_v
19
- options = OptionParser.parse(["-v"])
23
+ options = OptionParser.parse(["-v"], false, @err)
20
24
  assert(options.verbose)
21
25
  end
22
26
 
23
27
  def test_verbose_should_be_settable_with_verbose
24
- options = OptionParser.parse(["--verbose"])
28
+ options = OptionParser.parse(["--verbose"], false, @err)
25
29
  assert(options.verbose)
26
30
  end
27
31
 
28
32
  def test_doc_should_be_false_by_default
29
- options = OptionParser.parse([])
33
+ options = OptionParser.parse([], false, @err)
30
34
  assert(!options.doc)
31
35
  end
32
36
 
33
37
  def test_doc_should_be_settable_with_d
34
- options = OptionParser.parse(["-d"])
38
+ options = OptionParser.parse(["-d"], false, @err)
35
39
  assert(options.doc)
36
40
  end
37
41
 
38
42
  def test_out_should_be_settable_with_o
39
- options = OptionParser.parse(["-o","test.txt"])
43
+ options = OptionParser.parse(["-o","test.txt"], false, @err)
40
44
  assert_equal("test.txt", options.out)
41
45
  end
42
46
 
43
47
  def test_out_should_be_settable_with_of
44
- options = OptionParser.parse(["--of","test.txt"])
48
+ options = OptionParser.parse(["--of","test.txt"], false, @err)
45
49
  assert_equal("test.txt", options.out)
46
50
  end
47
51
 
52
+ def test_should_print_usage_if_no_dir_specified
53
+ options = OptionParser.parse([], false, @err)
54
+ assert_match(/Usage: spec/, @err.string)
55
+ end
48
56
  end
49
57
  end
50
58
  end
@@ -25,22 +25,23 @@ module Spec
25
25
  end
26
26
 
27
27
  def test_should_account_for_context_in_stats_for_pass
28
- @reporter.add_context Context.new("context") {}
28
+ @reporter.add_context "context", "calling line"
29
29
  @reporter.dump
30
30
  assert_match(/1 context, 0 specifications, 0 failures/, @io.string)
31
31
  end
32
32
 
33
33
  def test_should_account_for_spec_in_stats_for_pass
34
- @reporter.add_spec Specification.new("spec") {}
34
+ @reporter.add_spec Specification.new("spec"), "calling line", {}
35
35
  @reporter.dump
36
36
  assert_match(/0 contexts, 1 specification, 0 failures/, @io.string)
37
37
  end
38
38
 
39
39
  def test_should_account_for_spec_and_error_in_stats_for_pass
40
- @backtrace_tweaker.should_receive(:tweak_backtrace)
41
- @reporter.add_spec Specification.new("spec"), [RuntimeError.new]
40
+ @backtrace_tweaker.should.receive(:tweak_backtrace)
41
+ @reporter.add_context "context", "calling line"
42
+ @reporter.add_spec Specification.new("spec"), "calling line", [RuntimeError.new]
42
43
  @reporter.dump
43
- assert_match(/0 contexts, 1 specification, 1 failure/, @io.string)
44
+ assert_match(/1 context, 1 specification, 1 failure/, @io.string)
44
45
  end
45
46
 
46
47
  def test_should_handle_multiple_contexts_same_name
@@ -52,23 +53,52 @@ module Spec
52
53
  end
53
54
 
54
55
  def test_should_handle_multiple_specs_same_name
55
- @backtrace_tweaker.should_receive(:tweak_backtrace)
56
- @reporter.add_context Context.new("context") {}
57
- @reporter.add_spec Specification.new("spec") {}
58
- @reporter.add_spec Specification.new("spec"), [RuntimeError.new]
59
- @reporter.add_context Context.new("context") {}
60
- @reporter.add_spec Specification.new("spec") {}
61
- @reporter.add_spec Specification.new("spec"), [RuntimeError.new]
56
+ @backtrace_tweaker.should.receive(:tweak_backtrace)
57
+ @reporter.add_context "context", "calling line"
58
+ @reporter.add_spec "spec", "calling line"
59
+ @reporter.add_spec "spec", "calling line", [RuntimeError.new]
60
+ @reporter.add_context "context", "calling line"
61
+ @reporter.add_spec "spec", "calling line"
62
+ @reporter.add_spec "spec", "calling line", [RuntimeError.new]
62
63
  @reporter.dump
63
64
  assert_match(/2 contexts, 4 specifications, 2 failures/, @io.string)
64
65
  end
65
66
 
66
67
  def test_should_delegate_to_backtrace_tweaker
67
- @backtrace_tweaker.should_receive(:tweak_backtrace)
68
- @reporter.add_spec Specification.new("spec"), [RuntimeError.new]
68
+ @backtrace_tweaker.should.receive(:tweak_backtrace)
69
+ @reporter.add_context "context", "calling line"
70
+ @reporter.add_spec "spec", "calling line", [RuntimeError.new]
69
71
  @backtrace_tweaker.__verify
70
72
  end
71
-
73
+
74
+ end
75
+
76
+ class FailureDumpTest < Test::Unit::TestCase
77
+
78
+ def setup
79
+ @io = StringIO.new
80
+ @reporter = SimpleTextReporter.new(@io)
81
+ @reporter.add_context "failing context", "calling line for context"
82
+ @reporter.add_spec "failing spec", "calling line for spec", [RuntimeError.new]
83
+ @reporter.dump
84
+ end
85
+
86
+ def test_should_include_context
87
+ assert_match(/failing context/, @io.string)
88
+ end
89
+
90
+ def test_should_include_context_calling_line
91
+ assert_match(/\[calling line for context\]/, @io.string)
92
+ end
93
+
94
+ def test_should_include_spec
95
+ assert_match(/failing spec/, @io.string)
96
+ end
97
+
98
+ def test_should_include_spec_calling_line
99
+ assert_match(/[calling line for spec]/, @io.string)
100
+ end
101
+
72
102
  end
73
103
 
74
104
  class SimpleTextReporterQuietOutputTest < Test::Unit::TestCase
@@ -76,51 +106,45 @@ module Spec
76
106
  def setup
77
107
  @io = StringIO.new
78
108
  @reporter = SimpleTextReporter.new(@io)
109
+ @reporter.add_context "context", "calling line for context"
79
110
  end
80
111
 
81
112
  def test_should_remain_silent_when_context_name_provided
82
- @reporter.add_context "context"
83
113
  assert_equal("\n", @io.string)
84
114
  end
85
115
 
86
116
  def test_should_output_dot_when_spec_passed
87
- @reporter.add_spec "spec"
88
- assert_equal(".", @io.string)
117
+ @reporter.add_spec "spec", "calling line"
118
+ assert_equal("\n.", @io.string)
89
119
  end
90
120
 
91
121
  def test_should_output_F_when_spec_failed
92
- @reporter.add_spec "spec", [RuntimeError.new]
93
- assert_equal("F", @io.string)
122
+ @reporter.add_spec "spec", "calling line", [RuntimeError.new]
123
+ assert_equal("\nF", @io.string)
94
124
  end
95
-
125
+
96
126
  end
97
127
 
98
-
99
128
  class SimpleTextReporterVerboseOutputTest < Test::Unit::TestCase
100
129
 
101
130
  def setup
102
131
  @io = StringIO.new
103
132
  @reporter = SimpleTextReporter.new(@io, true)
133
+ @reporter.add_context "context", "calling line for context"
104
134
  end
105
135
 
106
136
  def test_should_output_when_context_name_provided
107
- @reporter.add_context "context"
108
- assert_equal("\ncontext\n", @io.string)
137
+ assert_match(/\ncontext\n/, @io.string)
109
138
  end
110
139
 
111
140
  def test_should_output_spec_name_when_spec_passed
112
- @reporter.add_spec "spec"
113
- assert_equal("- spec\n", @io.string)
141
+ @reporter.add_spec "spec", "calling line"
142
+ assert_match(/- spec\n/, @io.string)
114
143
  end
115
144
 
116
145
  def test_should_output_failure_when_spec_failed
117
- error = RuntimeError.new
118
- begin
119
- raise error
120
- rescue
121
- end
122
- @reporter.add_spec "spec", [error]
123
- assert_equal("- spec (FAILED)\n#{error.message} (#{error.class.name})\n#{error.backtrace.join("\n")}\n", @io.string)
146
+ @reporter.add_spec "spec", "calling line", [RuntimeError.new]
147
+ assert_match(/spec \(FAILED - 1\)/, @io.string)
124
148
  end
125
149
 
126
150
  end