mspec 1.0.0 → 1.1.0
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/Rakefile +9 -9
- data/lib/mspec.rb +5 -0
- data/lib/mspec/commands/mspec-ci.rb +1 -2
- data/lib/mspec/commands/mspec-run.rb +1 -2
- data/lib/mspec/commands/mspec-tag.rb +1 -2
- data/lib/mspec/helpers/const_lookup.rb +5 -1
- data/lib/mspec/matchers.rb +1 -0
- data/lib/mspec/matchers/match_yaml.rb +47 -0
- data/lib/mspec/mocks/mock.rb +56 -30
- data/lib/mspec/mocks/object.rb +3 -11
- data/lib/mspec/mocks/proxy.rb +24 -3
- data/lib/mspec/runner/mspec.rb +28 -15
- data/lib/mspec/utils/options.rb +0 -7
- data/lib/mspec/utils/script.rb +15 -5
- data/lib/mspec/version.rb +1 -1
- data/spec/commands/mspec_ci_spec.rb +3 -8
- data/spec/commands/mspec_run_spec.rb +3 -8
- data/spec/commands/mspec_tag_spec.rb +3 -8
- data/spec/helpers/const_lookup_spec.rb +29 -0
- data/spec/matchers/base_spec.rb +88 -52
- data/spec/matchers/eql_spec.rb +2 -2
- data/spec/matchers/equal_spec.rb +2 -2
- data/spec/matchers/equal_utf16_spec.rb +2 -2
- data/spec/matchers/match_yaml_spec.rb +39 -0
- data/spec/mocks/mock_spec.rb +191 -23
- data/spec/mocks/proxy_spec.rb +135 -28
- data/spec/runner/formatters/spinner_spec.rb +11 -4
- data/spec/runner/mspec_spec.rb +22 -23
- data/spec/spec_helper.rb +1 -6
- data/spec/utils/options_spec.rb +0 -21
- data/spec/utils/script_spec.rb +36 -11
- metadata +4 -2
data/lib/mspec/utils/options.rb
CHANGED
@@ -122,13 +122,6 @@ class MSpecOptions
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
def add_tags_dir
|
126
|
-
on("-X", "--tags-dir DIR", String,
|
127
|
-
"Use DIR as the path prefix for locating spec tag files") do |d|
|
128
|
-
@config[:tags_dir] = d
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
125
|
def add_formatters
|
133
126
|
on("-f", "--format FORMAT", String,
|
134
127
|
"Formatter for reporting, where FORMAT is one of:") do |o|
|
data/lib/mspec/utils/script.rb
CHANGED
@@ -4,7 +4,10 @@ require 'mspec/runner/formatters/dotted'
|
|
4
4
|
|
5
5
|
class MSpecScript
|
6
6
|
def self.config
|
7
|
-
@config ||= {
|
7
|
+
@config ||= {
|
8
|
+
:path => ['.', 'spec'],
|
9
|
+
:config_ext => '.mspec'
|
10
|
+
}
|
8
11
|
end
|
9
12
|
|
10
13
|
def self.set(key, value)
|
@@ -32,11 +35,18 @@ class MSpecScript
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def load(name)
|
35
|
-
|
38
|
+
names = [name]
|
39
|
+
unless name[-6..-1] == config[:config_ext]
|
40
|
+
names << name + config[:config_ext]
|
41
|
+
end
|
42
|
+
|
43
|
+
names.each do |name|
|
44
|
+
return Kernel.load(name) if File.exist?(File.expand_path(name))
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
46
|
+
config[:path].each do |dir|
|
47
|
+
file = File.join dir, name
|
48
|
+
return Kernel.load(file) if File.exist? file
|
49
|
+
end
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
data/lib/mspec/version.rb
CHANGED
@@ -27,11 +27,6 @@ describe MSpecCI, "#options" do
|
|
27
27
|
@script.options
|
28
28
|
end
|
29
29
|
|
30
|
-
it "enables the tags dir option" do
|
31
|
-
@options.should_receive(:add_tags_dir)
|
32
|
-
@script.options
|
33
|
-
end
|
34
|
-
|
35
30
|
it "enables the dry run option" do
|
36
31
|
@options.should_receive(:add_pretend)
|
37
32
|
@script.options
|
@@ -94,9 +89,9 @@ describe MSpecCI, "#run" do
|
|
94
89
|
@script.options
|
95
90
|
end
|
96
91
|
|
97
|
-
it "registers the tags
|
98
|
-
@config[:
|
99
|
-
MSpec.should_receive(:
|
92
|
+
it "registers the tags patterns" do
|
93
|
+
@config[:tags_patterns] = [/spec/, "tags"]
|
94
|
+
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
100
95
|
@script.run
|
101
96
|
end
|
102
97
|
|
@@ -38,11 +38,6 @@ describe MSpecRun, "#options" do
|
|
38
38
|
@script.options @argv
|
39
39
|
end
|
40
40
|
|
41
|
-
it "enables the tags dir option" do
|
42
|
-
@options.should_receive(:add_tags_dir)
|
43
|
-
@script.options @argv
|
44
|
-
end
|
45
|
-
|
46
41
|
it "enables the randomize option to runs specs in random order" do
|
47
42
|
@options.should_receive(:add_randomize)
|
48
43
|
@script.options @argv
|
@@ -122,9 +117,9 @@ describe MSpecRun, "#run" do
|
|
122
117
|
@script.options
|
123
118
|
end
|
124
119
|
|
125
|
-
it "registers the tags
|
126
|
-
@config[:
|
127
|
-
MSpec.should_receive(:
|
120
|
+
it "registers the tags patterns" do
|
121
|
+
@config[:tags_patterns] = [/spec/, "tags"]
|
122
|
+
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
128
123
|
@script.run
|
129
124
|
end
|
130
125
|
|
@@ -38,11 +38,6 @@ describe MSpecTag, "#options" do
|
|
38
38
|
@script.options @argv
|
39
39
|
end
|
40
40
|
|
41
|
-
it "enables the tags dir option" do
|
42
|
-
@options.should_receive(:add_tags_dir)
|
43
|
-
@script.options @argv
|
44
|
-
end
|
45
|
-
|
46
41
|
it "enables the dry run option" do
|
47
42
|
@options.should_receive(:add_pretend)
|
48
43
|
@script.options @argv
|
@@ -107,9 +102,9 @@ describe MSpecTag, "#run" do
|
|
107
102
|
@script.options
|
108
103
|
end
|
109
104
|
|
110
|
-
it "registers the tags
|
111
|
-
@config[:
|
112
|
-
MSpec.should_receive(:
|
105
|
+
it "registers the tags patterns" do
|
106
|
+
@config[:tags_patterns] = [/spec/, "tags"]
|
107
|
+
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
113
108
|
@script.run
|
114
109
|
end
|
115
110
|
|
@@ -1,9 +1,20 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
require 'mspec/helpers/const_lookup'
|
3
3
|
|
4
|
+
CONST = 2
|
5
|
+
|
4
6
|
module ConstLookupSpecs
|
5
7
|
class A
|
6
8
|
class B
|
9
|
+
CONST = 1
|
10
|
+
end
|
11
|
+
|
12
|
+
class C; end
|
13
|
+
|
14
|
+
class D
|
15
|
+
def self.const_missing(const)
|
16
|
+
A::B::CONST
|
17
|
+
end
|
7
18
|
end
|
8
19
|
end
|
9
20
|
end
|
@@ -16,4 +27,22 @@ describe Kernel, "#const_lookup" do
|
|
16
27
|
it "returns a regular constant specified without scoping" do
|
17
28
|
const_lookup("ConstLookupSpecs").should == ConstLookupSpecs
|
18
29
|
end
|
30
|
+
|
31
|
+
it "returns an explicit toplevel constant" do
|
32
|
+
const_lookup("::ConstLookupSpecs").should == ConstLookupSpecs
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the constant from the proper scope" do
|
36
|
+
const_lookup("ConstLookupSpecs::A::B::CONST").should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises NameError if the constant is not contained within the module's scope" do
|
40
|
+
lambda {
|
41
|
+
const_lookup("ConstLookupSpecs::A::C::CONST")
|
42
|
+
}.should raise_error(NameError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns the value of #const_missing" do
|
46
|
+
const_lookup("ConstLookupSpecs::A::D::CONST").should == 1
|
47
|
+
end
|
19
48
|
end
|
data/spec/matchers/base_spec.rb
CHANGED
@@ -7,13 +7,16 @@ describe PositiveOperatorMatcher, "== operator" do
|
|
7
7
|
it "raises an ExpectationNotMetError when expected == actual returns false" do
|
8
8
|
lambda {
|
9
9
|
PositiveOperatorMatcher.new(1) == 2
|
10
|
-
}.should raise_error(ExpectationNotMetError
|
10
|
+
}.should raise_error(ExpectationNotMetError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "provides a failure message that 'Expected x to equal y'" do
|
14
|
+
Expectation.should_receive(:fail_with).with("Expected 1\n", "to equal 2\n")
|
15
|
+
PositiveOperatorMatcher.new(1) == 2
|
11
16
|
end
|
12
17
|
|
13
18
|
it "does not raise an exception when expected == actual returns true" do
|
14
|
-
|
15
|
-
PositiveOperatorMatcher.new(1) == 1
|
16
|
-
}.should_not raise_error
|
19
|
+
PositiveOperatorMatcher.new(1) == 1
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -21,13 +24,16 @@ describe PositiveOperatorMatcher, "=~ operator" do
|
|
21
24
|
it "raises an ExpectationNotMetError when expected =~ actual returns false" do
|
22
25
|
lambda {
|
23
26
|
PositiveOperatorMatcher.new('real') =~ /fake/
|
24
|
-
}.should raise_error(ExpectationNotMetError
|
27
|
+
}.should raise_error(ExpectationNotMetError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "provides a failure message that 'Expected \"x\" to match y'" do
|
31
|
+
Expectation.should_receive(:fail_with).with("Expected \"real\"\n", "to match /fake/\n")
|
32
|
+
PositiveOperatorMatcher.new('real') =~ /fake/
|
25
33
|
end
|
26
34
|
|
27
35
|
it "does not raise an exception when expected =~ actual returns true" do
|
28
|
-
|
29
|
-
PositiveOperatorMatcher.new('real') =~ /real/
|
30
|
-
}.should_not raise_error
|
36
|
+
PositiveOperatorMatcher.new('real') =~ /real/
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
@@ -35,13 +41,16 @@ describe PositiveOperatorMatcher, "> operator" do
|
|
35
41
|
it "raises an ExpectationNotMetError when expected > actual returns false" do
|
36
42
|
lambda {
|
37
43
|
PositiveOperatorMatcher.new(4) > 5
|
38
|
-
}.should raise_error(ExpectationNotMetError
|
44
|
+
}.should raise_error(ExpectationNotMetError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "provides a failure message that 'Expected x to be greater than y'" do
|
48
|
+
Expectation.should_receive(:fail_with).with("Expected 4\n", "to be greater than 5\n")
|
49
|
+
PositiveOperatorMatcher.new(4) > 5
|
39
50
|
end
|
40
51
|
|
41
52
|
it "does not raise an exception when expected > actual returns true" do
|
42
|
-
|
43
|
-
PositiveOperatorMatcher.new(5) > 4
|
44
|
-
}.should_not raise_error
|
53
|
+
PositiveOperatorMatcher.new(5) > 4
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
@@ -49,14 +58,17 @@ describe PositiveOperatorMatcher, ">= operator" do
|
|
49
58
|
it "raises an ExpectationNotMetError when expected >= actual returns false" do
|
50
59
|
lambda {
|
51
60
|
PositiveOperatorMatcher.new(4) >= 5
|
52
|
-
}.should raise_error(ExpectationNotMetError
|
61
|
+
}.should raise_error(ExpectationNotMetError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "provides a failure message that 'Expected x to be greater than or equal to y'" do
|
65
|
+
Expectation.should_receive(:fail_with).with("Expected 4\n", "to be greater than or equal to 5\n")
|
66
|
+
PositiveOperatorMatcher.new(4) >= 5
|
53
67
|
end
|
54
68
|
|
55
69
|
it "does not raise an exception when expected > actual returns true" do
|
56
|
-
|
57
|
-
|
58
|
-
PositiveOperatorMatcher.new(5) >= 5
|
59
|
-
}.should_not raise_error
|
70
|
+
PositiveOperatorMatcher.new(5) >= 4
|
71
|
+
PositiveOperatorMatcher.new(5) >= 5
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
@@ -64,13 +76,16 @@ describe PositiveOperatorMatcher, "< operater" do
|
|
64
76
|
it "raises an ExpectationNotMetError when expected < actual returns false" do
|
65
77
|
lambda {
|
66
78
|
PositiveOperatorMatcher.new(5) < 4
|
67
|
-
}.should raise_error(ExpectationNotMetError
|
79
|
+
}.should raise_error(ExpectationNotMetError)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "provides a failure message that 'Expected x to be less than y'" do
|
83
|
+
Expectation.should_receive(:fail_with).with("Expected 5\n", "to be less than 4\n")
|
84
|
+
PositiveOperatorMatcher.new(5) < 4
|
68
85
|
end
|
69
86
|
|
70
87
|
it "does not raise an exception when expected < actual returns true" do
|
71
|
-
|
72
|
-
PositiveOperatorMatcher.new(4) < 5
|
73
|
-
}.should_not raise_error
|
88
|
+
PositiveOperatorMatcher.new(4) < 5
|
74
89
|
end
|
75
90
|
end
|
76
91
|
|
@@ -78,14 +93,17 @@ describe PositiveOperatorMatcher, "<= operater" do
|
|
78
93
|
it "raises an ExpectationNotMetError when expected < actual returns false" do
|
79
94
|
lambda {
|
80
95
|
PositiveOperatorMatcher.new(5) <= 4
|
81
|
-
}.should raise_error(ExpectationNotMetError
|
96
|
+
}.should raise_error(ExpectationNotMetError)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "provides a failure message that 'Expected x to be less than or equal to y'" do
|
100
|
+
Expectation.should_receive(:fail_with).with("Expected 5\n", "to be less than or equal to 4\n")
|
101
|
+
PositiveOperatorMatcher.new(5) <= 4
|
82
102
|
end
|
83
103
|
|
84
104
|
it "does not raise an exception when expected < actual returns true" do
|
85
|
-
|
86
|
-
|
87
|
-
PositiveOperatorMatcher.new(4) <= 4
|
88
|
-
}.should_not raise_error
|
105
|
+
PositiveOperatorMatcher.new(4) <= 5
|
106
|
+
PositiveOperatorMatcher.new(4) <= 4
|
89
107
|
end
|
90
108
|
end
|
91
109
|
|
@@ -93,13 +111,16 @@ describe NegativeOperatorMatcher, "== operator" do
|
|
93
111
|
it "raises an ExpectationNotMetError when expected == actual returns true" do
|
94
112
|
lambda {
|
95
113
|
NegativeOperatorMatcher.new(1) == 1
|
96
|
-
}.should raise_error(ExpectationNotMetError
|
114
|
+
}.should raise_error(ExpectationNotMetError)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "provides a failure message that 'Expected x not to equal y'" do
|
118
|
+
Expectation.should_receive(:fail_with).with("Expected 1\n", "not to equal 1\n")
|
119
|
+
NegativeOperatorMatcher.new(1) == 1
|
97
120
|
end
|
98
121
|
|
99
122
|
it "does not raise an exception when expected == actual returns false" do
|
100
|
-
|
101
|
-
NegativeOperatorMatcher.new(1) == 2
|
102
|
-
}.should_not raise_error
|
123
|
+
NegativeOperatorMatcher.new(1) == 2
|
103
124
|
end
|
104
125
|
end
|
105
126
|
|
@@ -107,13 +128,16 @@ describe NegativeOperatorMatcher, "=~ operator" do
|
|
107
128
|
it "raises an ExpectationNotMetError when expected =~ actual returns true" do
|
108
129
|
lambda {
|
109
130
|
NegativeOperatorMatcher.new('real') =~ /real/
|
110
|
-
}.should raise_error(ExpectationNotMetError
|
131
|
+
}.should raise_error(ExpectationNotMetError)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "provides a failure message that 'Expected \"x\" not to match /y/'" do
|
135
|
+
Expectation.should_receive(:fail_with).with("Expected \"real\"\n", "not to match /real/\n")
|
136
|
+
NegativeOperatorMatcher.new('real') =~ /real/
|
111
137
|
end
|
112
138
|
|
113
139
|
it "does not raise an exception when expected =~ actual returns false" do
|
114
|
-
|
115
|
-
NegativeOperatorMatcher.new('real') =~ /fake/
|
116
|
-
}.should_not raise_error
|
140
|
+
NegativeOperatorMatcher.new('real') =~ /fake/
|
117
141
|
end
|
118
142
|
end
|
119
143
|
|
@@ -121,13 +145,16 @@ describe NegativeOperatorMatcher, "< operator" do
|
|
121
145
|
it "raises an ExpectationNotMetError when expected < actual returns true" do
|
122
146
|
lambda {
|
123
147
|
NegativeOperatorMatcher.new(4) < 5
|
124
|
-
}.should raise_error(ExpectationNotMetError
|
148
|
+
}.should raise_error(ExpectationNotMetError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "provides a failure message that 'Expected x not to be less than y'" do
|
152
|
+
Expectation.should_receive(:fail_with).with("Expected 4\n", "not to be less than 5\n")
|
153
|
+
NegativeOperatorMatcher.new(4) < 5
|
125
154
|
end
|
126
155
|
|
127
156
|
it "does not raise an exception when expected < actual returns false" do
|
128
|
-
|
129
|
-
NegativeOperatorMatcher.new(5) < 4
|
130
|
-
}.should_not raise_error
|
157
|
+
NegativeOperatorMatcher.new(5) < 4
|
131
158
|
end
|
132
159
|
end
|
133
160
|
|
@@ -135,16 +162,19 @@ describe NegativeOperatorMatcher, "<= operator" do
|
|
135
162
|
it "raises an ExpectationNotMetError when expected <= actual returns true" do
|
136
163
|
lambda {
|
137
164
|
NegativeOperatorMatcher.new(4) <= 5
|
138
|
-
}.should raise_error(ExpectationNotMetError
|
165
|
+
}.should raise_error(ExpectationNotMetError)
|
139
166
|
lambda {
|
140
167
|
NegativeOperatorMatcher.new(5) <= 5
|
141
|
-
}.should raise_error(ExpectationNotMetError
|
168
|
+
}.should raise_error(ExpectationNotMetError)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "provides a failure message that 'Expected x not to be less than or equal to y'" do
|
172
|
+
Expectation.should_receive(:fail_with).with("Expected 4\n", "not to be less than or equal to 5\n")
|
173
|
+
NegativeOperatorMatcher.new(4) <= 5
|
142
174
|
end
|
143
175
|
|
144
176
|
it "does not raise an exception when expected <= actual returns false" do
|
145
|
-
|
146
|
-
NegativeOperatorMatcher.new(5) <= 4
|
147
|
-
}.should_not raise_error
|
177
|
+
NegativeOperatorMatcher.new(5) <= 4
|
148
178
|
end
|
149
179
|
end
|
150
180
|
|
@@ -152,13 +182,16 @@ describe NegativeOperatorMatcher, "> operator" do
|
|
152
182
|
it "raises an ExpectationNotMetError when expected > actual returns true" do
|
153
183
|
lambda {
|
154
184
|
NegativeOperatorMatcher.new(5) > 4
|
155
|
-
}.should raise_error(ExpectationNotMetError
|
185
|
+
}.should raise_error(ExpectationNotMetError)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "provides a failure message that 'Expected x not to be greater than y'" do
|
189
|
+
Expectation.should_receive(:fail_with).with("Expected 5\n", "not to be greater than 4\n")
|
190
|
+
NegativeOperatorMatcher.new(5) > 4
|
156
191
|
end
|
157
192
|
|
158
193
|
it "does not raise an exception when expected > actual returns false" do
|
159
|
-
|
160
|
-
NegativeOperatorMatcher.new(4) > 5
|
161
|
-
}.should_not raise_error
|
194
|
+
NegativeOperatorMatcher.new(4) > 5
|
162
195
|
end
|
163
196
|
end
|
164
197
|
|
@@ -166,15 +199,18 @@ describe NegativeOperatorMatcher, ">= operator" do
|
|
166
199
|
it "raises an ExpectationNotMetError when expected >= actual returns true" do
|
167
200
|
lambda {
|
168
201
|
NegativeOperatorMatcher.new(5) >= 4
|
169
|
-
}.should raise_error(ExpectationNotMetError
|
202
|
+
}.should raise_error(ExpectationNotMetError)
|
170
203
|
lambda {
|
171
204
|
NegativeOperatorMatcher.new(5) >= 5
|
172
|
-
}.should raise_error(ExpectationNotMetError
|
205
|
+
}.should raise_error(ExpectationNotMetError)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "provides a failure message that 'Expected x not to be greater than or equal to y'" do
|
209
|
+
Expectation.should_receive(:fail_with).with("Expected 5\n", "not to be greater than or equal to 4\n")
|
210
|
+
NegativeOperatorMatcher.new(5) >= 4
|
173
211
|
end
|
174
212
|
|
175
213
|
it "does not raise an exception when expected >= actual returns false" do
|
176
|
-
|
177
|
-
NegativeOperatorMatcher.new(4) >= 5
|
178
|
-
}.should_not raise_error
|
214
|
+
NegativeOperatorMatcher.new(4) >= 5
|
179
215
|
end
|
180
216
|
end
|
data/spec/matchers/eql_spec.rb
CHANGED
@@ -22,12 +22,12 @@ describe EqlMatcher do
|
|
22
22
|
it "provides a useful failure message" do
|
23
23
|
matcher = EqlMatcher.new("red")
|
24
24
|
matcher.matches?("red")
|
25
|
-
matcher.failure_message.should == ["Expected \"red\"", "to have same value and type as \"red\""]
|
25
|
+
matcher.failure_message.should == ["Expected \"red\"\n", "to have same value and type as \"red\"\n"]
|
26
26
|
end
|
27
27
|
|
28
28
|
it "provides a useful negative failure message" do
|
29
29
|
matcher = EqlMatcher.new(1)
|
30
30
|
matcher.matches?(1.0)
|
31
|
-
matcher.negative_failure_message.should == ["Expected 1.0", "not to have same value or type as 1"]
|
31
|
+
matcher.negative_failure_message.should == ["Expected 1.0\n", "not to have same value or type as 1\n"]
|
32
32
|
end
|
33
33
|
end
|