rspec 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/Rakefile +1 -1
- data/examples/add_specification_spec.rb +3 -3
- data/examples/craps_spec.rb +13 -13
- data/examples/dsl_spec.rb +2 -2
- data/examples/movie_spec.rb +5 -11
- data/lib/spec.rb +10 -0
- data/lib/spec/expectations.rb +5 -122
- data/lib/spec/have_helper.rb +56 -0
- data/lib/spec/instance_helper.rb +15 -0
- data/lib/spec/instance_negator.rb +15 -0
- data/lib/spec/kind_helper.rb +15 -0
- data/lib/spec/kind_negator.rb +15 -0
- data/lib/spec/mock.rb +0 -1
- data/lib/spec/respond_helper.rb +15 -0
- data/lib/spec/respond_negator.rb +15 -0
- data/lib/spec/should_base.rb +36 -0
- data/lib/spec/should_helper.rb +74 -0
- data/lib/spec/should_negator.rb +64 -0
- data/test/collection_owner.rb +48 -0
- data/test/context_run_test.rb +11 -11
- data/test/error_reporting_test.rb +101 -147
- data/test/expectations_for_should_have_test.rb +144 -0
- data/test/expectations_test.rb +274 -149
- data/test/gui_runner_test.rb +6 -6
- data/test/mock_test.rb +4 -4
- data/test/text_runner_test.rb +6 -6
- metadata +14 -2
data/CHANGES
CHANGED
@@ -13,6 +13,14 @@
|
|
13
13
|
* Make sure the PKG_VERSION constant in Rakefile.rb is
|
14
14
|
consistent with the latest version in this document.
|
15
15
|
|
16
|
+
== Version 0.4.0
|
17
|
+
|
18
|
+
The "two Daves walked into a bar" release.
|
19
|
+
|
20
|
+
* merge Astels' and Chelimsky's work on ShouldHelper
|
21
|
+
* this would be 0.5.0 if I updated the documentation
|
22
|
+
* it breaks all of your existing specifications. We're not sorry.
|
23
|
+
|
16
24
|
== Version 0.3.2
|
17
25
|
|
18
26
|
The "srbaker is an idiot" release.
|
data/Rakefile
CHANGED
@@ -3,13 +3,13 @@ require 'spec'
|
|
3
3
|
class AddSpecification < Spec::Context
|
4
4
|
|
5
5
|
def a_passing_spec
|
6
|
-
true.
|
6
|
+
true.should.be true
|
7
7
|
end
|
8
8
|
|
9
9
|
def a_failing_spec
|
10
|
-
true.
|
10
|
+
true.should.be false
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
AddSpecification.add_specification('another_failing_spec') { false.
|
15
|
+
AddSpecification.add_specification('another_failing_spec') { false.should.be true }
|
data/examples/craps_spec.rb
CHANGED
@@ -13,77 +13,77 @@ class CrapsSpecification < Spec::Context
|
|
13
13
|
|
14
14
|
def come_out_roll_of_1_6_wins
|
15
15
|
_load_dice([1], [6])
|
16
|
-
@game.play.
|
16
|
+
@game.play.should.be true
|
17
17
|
end
|
18
18
|
|
19
19
|
def come_out_roll_of_2_5_wins
|
20
20
|
_load_dice([2], [5])
|
21
|
-
@game.play.
|
21
|
+
@game.play.should.be true
|
22
22
|
end
|
23
23
|
|
24
24
|
def come_out_roll_of_3_4_wins
|
25
25
|
_load_dice([3], [4])
|
26
|
-
@game.play.
|
26
|
+
@game.play.should.be true
|
27
27
|
end
|
28
28
|
|
29
29
|
def come_out_roll_of_4_3_wins
|
30
30
|
_load_dice([4], [3])
|
31
|
-
@game.play.
|
31
|
+
@game.play.should.be true
|
32
32
|
end
|
33
33
|
|
34
34
|
def come_out_roll_of_5_2_wins
|
35
35
|
_load_dice([5], [2])
|
36
|
-
@game.play.
|
36
|
+
@game.play.should.be true
|
37
37
|
end
|
38
38
|
|
39
39
|
def come_out_roll_of_6_1_wins
|
40
40
|
_load_dice([6], [1])
|
41
|
-
@game.play.
|
41
|
+
@game.play.should.be true
|
42
42
|
end
|
43
43
|
|
44
44
|
# coming out roll of 11
|
45
45
|
|
46
46
|
def come_out_roll_of_5_6_wins
|
47
47
|
_load_dice([5], [6])
|
48
|
-
@game.play.
|
48
|
+
@game.play.should.be true
|
49
49
|
end
|
50
50
|
|
51
51
|
def come_out_roll_of_6_5_wins
|
52
52
|
_load_dice([6], [5])
|
53
|
-
@game.play.
|
53
|
+
@game.play.should.be true
|
54
54
|
end
|
55
55
|
|
56
56
|
# coming out roll of 2
|
57
57
|
|
58
58
|
def come_out_roll_of_1_1_looses
|
59
59
|
_load_dice([1], [1])
|
60
|
-
@game.play.
|
60
|
+
@game.play.should.be false
|
61
61
|
end
|
62
62
|
|
63
63
|
# coming out roll of 3
|
64
64
|
|
65
65
|
def come_out_roll_of_1_2_looses
|
66
66
|
_load_dice([1], [2])
|
67
|
-
@game.play.
|
67
|
+
@game.play.should.be false
|
68
68
|
end
|
69
69
|
|
70
70
|
def come_out_roll_of_2_1_looses
|
71
71
|
_load_dice([2], [1])
|
72
|
-
@game.play.
|
72
|
+
@game.play.should.be false
|
73
73
|
end
|
74
74
|
|
75
75
|
# coming out roll of 12
|
76
76
|
|
77
77
|
def come_out_roll_of_6_6_looses
|
78
78
|
_load_dice([6], [6])
|
79
|
-
@game.play.
|
79
|
+
@game.play.should.be false
|
80
80
|
end
|
81
81
|
|
82
82
|
# loosing with a point
|
83
83
|
|
84
84
|
# def second_roll_of_7_looses
|
85
85
|
# _load_dice([2, 4], [2, 3])
|
86
|
-
# @game.play.
|
86
|
+
# @game.play.should.be false
|
87
87
|
# end
|
88
88
|
|
89
89
|
# support
|
data/examples/dsl_spec.rb
CHANGED
data/examples/movie_spec.rb
CHANGED
@@ -9,11 +9,11 @@ class EmptyMovieList < Spec::Context
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def should_have_size_of_0
|
12
|
-
@list.size.
|
12
|
+
@list.size.should.equal 0
|
13
13
|
end
|
14
14
|
|
15
15
|
def should_not_include_star_wars
|
16
|
-
@list.
|
16
|
+
@list.should.not.include "Star Wars"
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -27,17 +27,11 @@ class OneMovieList < Spec::Context
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def should_have_size_of_1
|
30
|
-
@list.size.
|
30
|
+
@list.size.should.equal 1
|
31
31
|
end
|
32
32
|
|
33
33
|
def should_include_star_wars
|
34
|
-
@list.
|
34
|
+
@list.should.include "Star Wars"
|
35
35
|
end
|
36
36
|
|
37
|
-
end
|
38
|
-
|
39
|
-
if __FILE__ == $0
|
40
|
-
runner = Spec::TextRunner.new($stdout)
|
41
|
-
runner.run(EmptyMovieList)
|
42
|
-
runner.run(OneMovieList)
|
43
|
-
end
|
37
|
+
end
|
data/lib/spec.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
require 'spec/context'
|
2
|
+
require 'spec/should_base'
|
3
|
+
require 'spec/have_helper'
|
4
|
+
require 'spec/should_helper'
|
5
|
+
require 'spec/kind_helper'
|
6
|
+
require 'spec/instance_helper'
|
7
|
+
require 'spec/respond_helper'
|
8
|
+
require 'spec/should_negator'
|
9
|
+
require 'spec/kind_negator'
|
10
|
+
require 'spec/instance_negator'
|
11
|
+
require 'spec/respond_negator'
|
2
12
|
require 'spec/expectations'
|
3
13
|
require 'spec/exceptions'
|
4
14
|
require 'spec/text_runner'
|
data/lib/spec/expectations.rb
CHANGED
@@ -1,126 +1,12 @@
|
|
1
1
|
module Spec
|
2
|
-
module ExpectationHelperMethods
|
3
|
-
def should(message=nil)
|
4
|
-
message ||= "Expectation not met."
|
5
|
-
if (! yield)
|
6
|
-
raise Spec::Exceptions::ExpectationNotMetError.new(message)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def default_message(expectation, expected)
|
11
|
-
"<#{self.inspect}:#{self.class}>\n#{expectation}:\n<#{expected.inspect}:#{expected.class}>"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module ObjectExpectations
|
16
|
-
include ExpectationHelperMethods
|
17
|
-
|
18
|
-
def should_equal(expected, message=nil)
|
19
|
-
message ||= default_message("should be equal to", expected)
|
20
|
-
should(message) { self == expected }
|
21
|
-
end
|
22
|
-
|
23
|
-
def should_not_equal(expected, message=nil)
|
24
|
-
message ||= default_message("should not be equal to", expected)
|
25
|
-
should(message) { not self == expected }
|
26
|
-
end
|
27
|
-
|
28
|
-
def should_be_same_as(expected, message=nil)
|
29
|
-
message ||= default_message("should be same as", expected)
|
30
|
-
should(message) { self.equal?(expected) }
|
31
|
-
end
|
32
|
-
|
33
|
-
def should_not_be_same_as(expected, message=nil)
|
34
|
-
message ||= default_message("should not be same as", expected)
|
35
|
-
should(message) { not self.equal?(expected) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def should_match(expected, message=nil)
|
39
|
-
message ||= default_message("should match", expected)
|
40
|
-
should(message) { self =~ expected }
|
41
|
-
end
|
42
|
-
|
43
|
-
def should_not_match(expected, message=nil)
|
44
|
-
message ||= default_message("should not match", expected)
|
45
|
-
should(message) { not self =~ expected }
|
46
|
-
end
|
47
2
|
|
48
|
-
|
49
|
-
message ||= "<#{self}> should be nil"
|
50
|
-
should(message) { self.nil? }
|
51
|
-
end
|
52
|
-
|
53
|
-
def should_not_be_nil(message=nil)
|
54
|
-
message ||= "<#{self}> should not be nil"
|
55
|
-
should(message) { not self.nil? }
|
56
|
-
end
|
57
|
-
|
58
|
-
def should_be_empty(message=nil)
|
59
|
-
message ||= "<#{self.inspect}> should be empty"
|
60
|
-
should(message) { self.empty? }
|
61
|
-
end
|
62
|
-
|
63
|
-
def should_not_be_empty(message=nil)
|
64
|
-
message ||= "<#{self.inspect}> should not be empty"
|
65
|
-
should(message) { not self.empty? }
|
66
|
-
end
|
67
|
-
|
68
|
-
def should_include(sub, message=nil)
|
69
|
-
message ||= "<#{self.inspect}> should include <#{sub.inspect}>"
|
70
|
-
should(message) { self.include? sub }
|
71
|
-
end
|
3
|
+
module ObjectExpectations
|
72
4
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def should_be_true(message=nil)
|
79
|
-
message ||= "<#{self}> should be true"
|
80
|
-
should(message) { self }
|
81
|
-
end
|
5
|
+
def should
|
6
|
+
ShouldHelper.new self
|
7
|
+
end
|
8
|
+
end
|
82
9
|
|
83
|
-
def should_be_false(message=nil)
|
84
|
-
message ||= "<#{self}> should be false"
|
85
|
-
should(message) { not self }
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
module ProcExpectations
|
92
|
-
include ExpectationHelperMethods
|
93
|
-
|
94
|
-
def should_raise(exception=Exception, message=nil)
|
95
|
-
message ||= default_message("should raise", exception.class.to_s)
|
96
|
-
should(message) do
|
97
|
-
begin
|
98
|
-
self.call
|
99
|
-
false
|
100
|
-
rescue exception
|
101
|
-
true
|
102
|
-
rescue
|
103
|
-
false
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def should_not_raise(exception=Exception, message=nil)
|
109
|
-
message ||= default_message("should not raise", exception.class.to_s)
|
110
|
-
should(message) do
|
111
|
-
begin
|
112
|
-
self.call
|
113
|
-
true
|
114
|
-
rescue exception
|
115
|
-
false
|
116
|
-
rescue
|
117
|
-
true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
10
|
end
|
125
11
|
|
126
12
|
|
@@ -128,6 +14,3 @@ class Object
|
|
128
14
|
include Spec::ObjectExpectations
|
129
15
|
end
|
130
16
|
|
131
|
-
class Proc
|
132
|
-
include Spec::ProcExpectations
|
133
|
-
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Spec
|
2
|
+
|
3
|
+
class HaveHelper < ShouldBase
|
4
|
+
|
5
|
+
def initialize(target, expected=nil)
|
6
|
+
@target = target
|
7
|
+
@expected = expected
|
8
|
+
@min = false
|
9
|
+
@max = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(sym, *args)
|
13
|
+
fail_with_message(build_message(sym)) unless as_specified?(sym)
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection(sym)
|
17
|
+
@target.send(sym)
|
18
|
+
end
|
19
|
+
|
20
|
+
def actual_size(collection)
|
21
|
+
return collection.length if collection.respond_to? :length
|
22
|
+
return collection.size if collection.respond_to? :size
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_message(sym)
|
26
|
+
message = "<#{@target.class.to_s}> should have"
|
27
|
+
message += " at least" if @min
|
28
|
+
message += " at most" if @max
|
29
|
+
message += " #{@expected} #{sym} (has #{actual_size(collection(sym))})"
|
30
|
+
end
|
31
|
+
|
32
|
+
def as_specified?(sym)
|
33
|
+
return actual_size(collection(sym)) >= @expected if @min
|
34
|
+
return actual_size(collection(sym)) <= @expected if @max
|
35
|
+
return actual_size(collection(sym)) == @expected
|
36
|
+
end
|
37
|
+
|
38
|
+
def at
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def least(min)
|
43
|
+
@expected = min
|
44
|
+
@min = true
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def most(max)
|
49
|
+
@expected = max
|
50
|
+
@max = true
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spec
|
2
|
+
|
3
|
+
class InstanceHelper < ShouldBase
|
4
|
+
|
5
|
+
def initialize(target)
|
6
|
+
@target = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def of(expected_class)
|
10
|
+
fail_with_message(default_message("should be an instance of", expected_class)) unless @target.instance_of? expected_class
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spec
|
2
|
+
|
3
|
+
class InstanceNegator < ShouldBase
|
4
|
+
|
5
|
+
def initialize(target)
|
6
|
+
@target = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def of(expected_class)
|
10
|
+
fail_with_message(default_message("should not be an instance of", expected_class)) if @target.instance_of? expected_class
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spec
|
2
|
+
|
3
|
+
class KindHelper < ShouldBase
|
4
|
+
|
5
|
+
def initialize(target)
|
6
|
+
@target = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def of(expected_class)
|
10
|
+
fail_with_message(default_message("should be a kind of", expected_class)) unless @target.kind_of? expected_class
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spec
|
2
|
+
|
3
|
+
class KindNegator < ShouldBase
|
4
|
+
|
5
|
+
def initialize(target)
|
6
|
+
@target = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def of(expected_class)
|
10
|
+
fail_with_message(default_message("should not be a kind of", expected_class)) if @target.kind_of? expected_class
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|