rspec 0.5.2 → 0.5.3
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.
- data/CHANGES +10 -2
- data/Rakefile +22 -30
- data/doc/src/default.css +11 -10
- data/doc/src/documentation/api.page +15 -82
- data/doc/src/documentation/mocks.page +12 -55
- data/doc/src/meta.info +4 -1
- data/examples/airport_spec.rb +0 -1
- data/examples/empty_stack_spec.rb +1 -0
- data/examples/stack_spec.rb +1 -0
- data/examples/team_spec.rb +30 -0
- data/lib/spec/api.rb +1 -0
- data/lib/spec/api/duck_type.rb +16 -0
- data/lib/spec/api/expectations.rb +4 -4
- data/lib/spec/api/mock.rb +1 -0
- data/lib/spec/runner/backtrace_tweaker.rb +1 -2
- data/lib/spec/runner/context.rb +2 -3
- data/lib/spec/runner/context_runner.rb +2 -2
- data/lib/spec/runner/execution_context.rb +4 -0
- data/lib/spec/runner/option_parser.rb +3 -2
- data/lib/spec/runner/simple_text_reporter.rb +11 -25
- data/lib/spec/runner/specification.rb +1 -2
- data/lib/spec/version.rb +1 -1
- data/test/{rake → rcov}/rcov_testtask.rb +4 -4
- data/test/rcov/rcov_verify.rb +28 -0
- data/test/spec/api/duck_type_test.rb +19 -0
- data/test/spec/api/mock_arg_constraints_test.rb +20 -0
- data/test/spec/runner/backtrace_tweaker_test.rb +16 -8
- data/test/spec/runner/context_runner_test.rb +3 -3
- data/test/spec/runner/context_test.rb +2 -2
- data/test/spec/runner/execution_context_test.rb +7 -0
- data/test/spec/runner/option_parser_test.rb +12 -2
- data/test/spec/runner/simple_text_reporter_test.rb +18 -47
- data/test/spec/runner/specification_test.rb +5 -5
- data/test/spec/tool/command_line_test.rb +0 -1
- data/test/test_helper.rb +1 -0
- metadata +9 -7
- data/doc/src/download.page +0 -7
@@ -7,7 +7,6 @@ module Spec
|
|
7
7
|
@block = block
|
8
8
|
@mocks = []
|
9
9
|
@errors = []
|
10
|
-
@calling_line = caller(0)[2].split(":in")[0]
|
11
10
|
end
|
12
11
|
|
13
12
|
def run(reporter=nil, setup_block=nil, teardown_block=nil)
|
@@ -28,7 +27,7 @@ module Spec
|
|
28
27
|
@errors << e
|
29
28
|
end
|
30
29
|
|
31
|
-
reporter.add_spec(@name, @
|
30
|
+
reporter.add_spec(@name, @errors) unless reporter.nil?
|
32
31
|
end
|
33
32
|
|
34
33
|
def run_docs(reporter)
|
data/lib/spec/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
2
|
-
class TestTask <
|
1
|
+
module RCov
|
2
|
+
class TestTask < Rake::TestTask
|
3
3
|
def define
|
4
4
|
lib_path = @libs.join(File::PATH_SEPARATOR)
|
5
|
-
desc "Run tests
|
6
|
-
task
|
5
|
+
desc "Run tests with rcov"
|
6
|
+
task 'test_with_rcov' do
|
7
7
|
run_code = ''
|
8
8
|
RakeFileUtils.verbose(@verbose) do
|
9
9
|
run_code =
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RCov
|
2
|
+
class VerifyTask < Rake::TaskLib
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :index_html
|
5
|
+
attr_accessor :threshold
|
6
|
+
|
7
|
+
def initialize(name=:rcov_verify)
|
8
|
+
@name = name
|
9
|
+
yield self if block_given?
|
10
|
+
raise "Threshold must be set" if @threshold.nil?
|
11
|
+
define
|
12
|
+
end
|
13
|
+
|
14
|
+
def define
|
15
|
+
desc "Verify that rcov coverage is at least #{threshold}"
|
16
|
+
task @name do
|
17
|
+
total_coverage = nil
|
18
|
+
File.open(index_html).each_line do |line|
|
19
|
+
if line =~ /<tt>(\d+\.\d+)%<\/tt> <\/td>/
|
20
|
+
total_coverage = eval($1)
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Api
|
5
|
+
class DuckTypeTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_should_talk_like_something_with_one_message_specified
|
8
|
+
duck_type = DuckType.new(:length)
|
9
|
+
assert(duck_type.walks_like? [])
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_talk_like_something_with_two_messages_specified
|
13
|
+
duck_type = DuckType.new(:length, :empty?)
|
14
|
+
assert(duck_type.walks_like? [])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -44,6 +44,18 @@ module Spec
|
|
44
44
|
@mock.__verify
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_should_process_duck_type_with_one_method
|
48
|
+
@mock.should.receive(:random_call).with(DuckType.new(:length))
|
49
|
+
@mock.random_call([])
|
50
|
+
@mock.__verify
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_process_duck_type_with_two_methods
|
54
|
+
@mock.should.receive(:random_call).with(DuckType.new(:abs, :div))
|
55
|
+
@mock.random_call(1)
|
56
|
+
@mock.__verify
|
57
|
+
end
|
58
|
+
|
47
59
|
end
|
48
60
|
|
49
61
|
class FailingConstraintsTest < Test::Unit::TestCase
|
@@ -76,6 +88,14 @@ module Spec
|
|
76
88
|
end
|
77
89
|
end
|
78
90
|
|
91
|
+
def test_should_reject_goose_when_expecting_a_duck
|
92
|
+
@mock.should.receive(:random_call).with(DuckType.new(:abs, :div))
|
93
|
+
assert_raise(MockExpectationError) do
|
94
|
+
@mock.random_call("I don't respond to :abs or :div")
|
95
|
+
@mock.__verify
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
79
99
|
end
|
80
100
|
end
|
81
101
|
end
|
@@ -2,18 +2,26 @@ require File.dirname(__FILE__) + '/../../test_helper'
|
|
2
2
|
module Spec
|
3
3
|
module Runner
|
4
4
|
class BacktraceTweakerTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@error = RuntimeError.new
|
7
|
+
@tweaker = BacktraceTweaker.new
|
8
|
+
end
|
9
|
+
|
5
10
|
def test_should_not_barf_on_nil_backtrace
|
6
|
-
error
|
7
|
-
tweaker = BacktraceTweaker.new
|
8
|
-
proc { tweaker.tweak_backtrace error, 'spec name' }.should.not.raise
|
11
|
+
proc { @tweaker.tweak_backtrace @error, 'spec name' }.should.not.raise
|
9
12
|
end
|
10
13
|
|
11
14
|
def test_should_remove___instance_exec
|
12
|
-
error
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
@error.set_backtrace ["./examples/airport_spec.rb:28:in `__instance_exec_1014688_1661744'"]
|
16
|
+
@tweaker.tweak_backtrace @error, 'spec name'
|
17
|
+
@error.backtrace[0].should.equal "./examples/airport_spec.rb:28:in `spec name'"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_remove_helpers
|
21
|
+
@error = RuntimeError.new
|
22
|
+
@error.set_backtrace ["/lib/spec/api/helper/any_helper.rb"]
|
23
|
+
@tweaker.tweak_backtrace @error, 'spec name'
|
24
|
+
@error.backtrace.should.be.empty
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
2
3
|
module Spec
|
3
4
|
module Runner
|
4
5
|
class ContextRunnerTest < Test::Unit::TestCase
|
@@ -21,19 +22,18 @@ module Spec
|
|
21
22
|
context2 = Api::Mock.new "context2"
|
22
23
|
context1.should.receive(:run)
|
23
24
|
context2.should.receive(:run)
|
24
|
-
runner = ContextRunner.new [], false, StringIO.new
|
25
|
+
runner = ContextRunner.new ["-o","stringio"], false, StringIO.new
|
25
26
|
runner.add_context context1
|
26
27
|
runner.add_context context2
|
27
28
|
runner.run
|
28
29
|
context1.__verify
|
29
30
|
context2.__verify
|
30
31
|
end
|
31
|
-
|
32
32
|
|
33
33
|
def test_should_call_run_for_standalone
|
34
34
|
context1 = Api::Mock.new "context1"
|
35
35
|
context1.should.receive(:run)
|
36
|
-
runner = ContextRunner.standalone context1
|
36
|
+
runner = ContextRunner.standalone context1, ["-o","stringio"]
|
37
37
|
context1.__verify
|
38
38
|
end
|
39
39
|
|
@@ -10,7 +10,7 @@ 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"
|
14
14
|
@context.run(@listener)
|
15
15
|
@listener.__verify
|
16
16
|
end
|
@@ -23,7 +23,7 @@ module Spec
|
|
23
23
|
|
24
24
|
def test_spec
|
25
25
|
@listener.should.receive(:add_context).with :any_args
|
26
|
-
@listener.should.receive(:add_spec).with "test", :anything
|
26
|
+
@listener.should.receive(:add_spec).with "test", :anything
|
27
27
|
$spec_ran = false
|
28
28
|
@context.specify("test") {$spec_ran = true}
|
29
29
|
@context.run(@listener)
|
@@ -15,6 +15,13 @@ module Spec
|
|
15
15
|
ExecutionContext.new(nil).violated
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_duck_type
|
20
|
+
ec = ExecutionContext.new(Api::Mock.new("spec", :null_object => true))
|
21
|
+
duck_type = ec.duck_type(:length)
|
22
|
+
assert(duck_type.is_a? Api::DuckType)
|
23
|
+
assert(duck_type.walks_like? [])
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
require 'stringio'
|
3
2
|
|
4
3
|
module Spec
|
5
4
|
module Runner
|
@@ -10,11 +9,17 @@ module Spec
|
|
10
9
|
@err = StringIO.new
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
12
|
+
def test_should_print_version_to_stdout
|
14
13
|
options = OptionParser.parse(["--version"], false, @err, @out)
|
15
14
|
@out.rewind
|
16
15
|
assert_match(/RSpec-\d+\.\d+\.\d+ - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n, @out.read)
|
17
16
|
end
|
17
|
+
|
18
|
+
def test_should_print_help_to_stdout
|
19
|
+
options = OptionParser.parse(["--help"], false, @err, @out)
|
20
|
+
@out.rewind
|
21
|
+
assert_match(/Usage: spec \[options\] \(FILE\|DIRECTORY\)\+/n, @out.read)
|
22
|
+
end
|
18
23
|
|
19
24
|
def test_verbose_should_be_true_by_default
|
20
25
|
options = OptionParser.parse([], false, @err, @out)
|
@@ -60,6 +65,11 @@ module Spec
|
|
60
65
|
options = OptionParser.parse([], false, @err, @out)
|
61
66
|
assert_match(/Usage: spec/, @err.string)
|
62
67
|
end
|
68
|
+
|
69
|
+
def test_out_should_be_stringio_if_set_to_stringio
|
70
|
+
options = OptionParser.parse(["-o","stringio"], false, @err, @out)
|
71
|
+
options.out.should.be.an.instance.of StringIO
|
72
|
+
end
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
require 'stringio'
|
3
2
|
|
4
3
|
module Spec
|
5
4
|
module Runner
|
@@ -25,21 +24,21 @@ module Spec
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def test_should_account_for_context_in_stats_for_pass
|
28
|
-
@reporter.add_context "context"
|
27
|
+
@reporter.add_context "context"
|
29
28
|
@reporter.dump
|
30
29
|
assert_match(/1 context, 0 specifications, 0 failures/, @io.string)
|
31
30
|
end
|
32
31
|
|
33
32
|
def test_should_account_for_spec_in_stats_for_pass
|
34
|
-
@reporter.add_spec Specification.new("spec"),
|
33
|
+
@reporter.add_spec Specification.new("spec"), {}
|
35
34
|
@reporter.dump
|
36
35
|
assert_match(/0 contexts, 1 specification, 0 failures/, @io.string)
|
37
36
|
end
|
38
37
|
|
39
38
|
def test_should_account_for_spec_and_error_in_stats_for_pass
|
40
39
|
@backtrace_tweaker.should.receive(:tweak_backtrace)
|
41
|
-
@reporter.add_context "context"
|
42
|
-
@reporter.add_spec Specification.new("spec"),
|
40
|
+
@reporter.add_context "context"
|
41
|
+
@reporter.add_spec Specification.new("spec"), [RuntimeError.new]
|
43
42
|
@reporter.dump
|
44
43
|
assert_match(/1 context, 1 specification, 1 failure/, @io.string)
|
45
44
|
end
|
@@ -54,59 +53,31 @@ module Spec
|
|
54
53
|
|
55
54
|
def test_should_handle_multiple_specs_same_name
|
56
55
|
@backtrace_tweaker.should.receive(:tweak_backtrace)
|
57
|
-
@reporter.add_context "context"
|
58
|
-
@reporter.add_spec "spec"
|
59
|
-
@reporter.add_spec "spec",
|
60
|
-
@reporter.add_context "context"
|
61
|
-
@reporter.add_spec "spec"
|
62
|
-
@reporter.add_spec "spec",
|
56
|
+
@reporter.add_context "context"
|
57
|
+
@reporter.add_spec "spec"
|
58
|
+
@reporter.add_spec "spec", [RuntimeError.new]
|
59
|
+
@reporter.add_context "context"
|
60
|
+
@reporter.add_spec "spec"
|
61
|
+
@reporter.add_spec "spec", [RuntimeError.new]
|
63
62
|
@reporter.dump
|
64
63
|
assert_match(/2 contexts, 4 specifications, 2 failures/, @io.string)
|
65
64
|
end
|
66
65
|
|
67
66
|
def test_should_delegate_to_backtrace_tweaker
|
68
67
|
@backtrace_tweaker.should.receive(:tweak_backtrace)
|
69
|
-
@reporter.add_context "context"
|
70
|
-
@reporter.add_spec "spec",
|
68
|
+
@reporter.add_context "context"
|
69
|
+
@reporter.add_spec "spec", [RuntimeError.new]
|
71
70
|
@backtrace_tweaker.__verify
|
72
71
|
end
|
73
72
|
|
74
73
|
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
|
-
|
102
|
-
end
|
103
74
|
|
104
75
|
class SimpleTextReporterQuietOutputTest < Test::Unit::TestCase
|
105
76
|
|
106
77
|
def setup
|
107
78
|
@io = StringIO.new
|
108
79
|
@reporter = SimpleTextReporter.new(@io)
|
109
|
-
@reporter.add_context "context"
|
80
|
+
@reporter.add_context "context"
|
110
81
|
end
|
111
82
|
|
112
83
|
def test_should_remain_silent_when_context_name_provided
|
@@ -114,12 +85,12 @@ module Spec
|
|
114
85
|
end
|
115
86
|
|
116
87
|
def test_should_output_dot_when_spec_passed
|
117
|
-
@reporter.add_spec "spec"
|
88
|
+
@reporter.add_spec "spec"
|
118
89
|
assert_equal("\n.", @io.string)
|
119
90
|
end
|
120
91
|
|
121
92
|
def test_should_output_F_when_spec_failed
|
122
|
-
@reporter.add_spec "spec",
|
93
|
+
@reporter.add_spec "spec", [RuntimeError.new]
|
123
94
|
assert_equal("\nF", @io.string)
|
124
95
|
end
|
125
96
|
|
@@ -130,7 +101,7 @@ module Spec
|
|
130
101
|
def setup
|
131
102
|
@io = StringIO.new
|
132
103
|
@reporter = SimpleTextReporter.new(@io, true)
|
133
|
-
@reporter.add_context "context"
|
104
|
+
@reporter.add_context "context"
|
134
105
|
end
|
135
106
|
|
136
107
|
def test_should_output_when_context_name_provided
|
@@ -138,12 +109,12 @@ module Spec
|
|
138
109
|
end
|
139
110
|
|
140
111
|
def test_should_output_spec_name_when_spec_passed
|
141
|
-
@reporter.add_spec "spec"
|
112
|
+
@reporter.add_spec "spec"
|
142
113
|
assert_match(/- spec\n/, @io.string)
|
143
114
|
end
|
144
115
|
|
145
116
|
def test_should_output_failure_when_spec_failed
|
146
|
-
@reporter.add_spec "spec",
|
117
|
+
@reporter.add_spec "spec", [RuntimeError.new]
|
147
118
|
assert_match(/spec \(FAILED - 1\)/, @io.string)
|
148
119
|
end
|
149
120
|
|
@@ -12,20 +12,20 @@ module Spec
|
|
12
12
|
self.should.not.be.instance_of Specification
|
13
13
|
self.should.be.instance_of ExecutionContext
|
14
14
|
end
|
15
|
-
@reporter.should.receive(:add_spec).with "should pass",
|
15
|
+
@reporter.should.receive(:add_spec).with "should pass", []
|
16
16
|
spec.run @reporter
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_should_add_itself_to_reporter_when_passes
|
20
20
|
spec = Specification.new("spec") {}
|
21
|
-
@reporter.should.receive(:add_spec).with "spec",
|
21
|
+
@reporter.should.receive(:add_spec).with "spec", []
|
22
22
|
spec.run(@reporter)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_should_add_itself_to_reporter_when_fails
|
26
26
|
error = RuntimeError.new
|
27
27
|
spec = Specification.new("spec") { raise error }
|
28
|
-
@reporter.should.receive(:add_spec).with "spec",
|
28
|
+
@reporter.should.receive(:add_spec).with "spec", [error]
|
29
29
|
spec.run(@reporter)
|
30
30
|
end
|
31
31
|
|
@@ -40,7 +40,7 @@ module Spec
|
|
40
40
|
mock = mock("a mock")
|
41
41
|
mock.should.receive(:poke)
|
42
42
|
end
|
43
|
-
@reporter.should.receive(:add_spec) do |spec_name,
|
43
|
+
@reporter.should.receive(:add_spec) do |spec_name, errors|
|
44
44
|
spec_name.should.equal "spec"
|
45
45
|
errors[0].message.should.match /expected poke once, but received it 0 times/
|
46
46
|
end
|
@@ -54,7 +54,7 @@ module Spec
|
|
54
54
|
teardown = lambda do
|
55
55
|
raise "in teardown"
|
56
56
|
end
|
57
|
-
@reporter.should.receive(:add_spec) do |spec,
|
57
|
+
@reporter.should.receive(:add_spec) do |spec, errors|
|
58
58
|
errors.length.should.equal 2
|
59
59
|
errors[0].message.should.equal "in body"
|
60
60
|
errors[1].message.should.equal "in teardown"
|