mspec 1.5.16 → 1.5.17
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 +1 -1
- data/bin/mkspec +1 -1
- data/bin/mspec +1 -1
- data/bin/mspec-ci +1 -1
- data/bin/mspec-run +1 -1
- data/bin/mspec-tag +1 -1
- data/lib/mspec/commands/mkspec.rb +28 -11
- data/lib/mspec/guards.rb +1 -0
- data/lib/mspec/guards/specified.rb +66 -0
- data/lib/mspec/helpers/io.rb +15 -0
- data/lib/mspec/mocks/mock.rb +6 -1
- data/lib/mspec/mocks/proxy.rb +15 -4
- data/lib/mspec/utils/name_map.rb +6 -0
- data/lib/mspec/version.rb +1 -1
- data/spec/commands/mkspec_spec.rb +44 -15
- data/spec/guards/specified_spec.rb +102 -0
- data/spec/helpers/io_spec.rb +56 -0
- data/spec/mocks/mock_spec.rb +9 -0
- data/spec/mocks/proxy_spec.rb +23 -0
- metadata +4 -2
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
20
20
|
s.authors = ["Brian Ford"]
|
21
|
-
s.date = %q{2010-
|
21
|
+
s.date = %q{2010-03-13}
|
22
22
|
s.email = %q{bford@engineyard.com}
|
23
23
|
s.has_rdoc = true
|
24
24
|
s.extra_rdoc_files = %w[ README LICENSE ]
|
data/bin/mkspec
CHANGED
data/bin/mspec
CHANGED
data/bin/mspec-ci
CHANGED
data/bin/mspec-run
CHANGED
data/bin/mspec-tag
CHANGED
@@ -16,13 +16,14 @@ class MkSpec
|
|
16
16
|
@config = {
|
17
17
|
:constants => [],
|
18
18
|
:requires => [],
|
19
|
-
:base => "
|
19
|
+
:base => "core",
|
20
|
+
:version => nil
|
20
21
|
}
|
21
|
-
@map = NameMap.new
|
22
|
+
@map = NameMap.new true
|
22
23
|
end
|
23
24
|
|
24
25
|
def options(argv=ARGV)
|
25
|
-
options = MSpecOptions.new "mkspec [options]"
|
26
|
+
options = MSpecOptions.new "mkspec [options]", 32
|
26
27
|
|
27
28
|
options.on("-c", "--constant", "CONSTANT",
|
28
29
|
"Class or Module to generate spec stubs for") do |name|
|
@@ -36,6 +37,10 @@ class MkSpec
|
|
36
37
|
"A library to require") do |file|
|
37
38
|
config[:requires] << file
|
38
39
|
end
|
40
|
+
options.on("-V", "--version-guard", "VERSION",
|
41
|
+
"Specify version for ruby_version_is guards") do |version|
|
42
|
+
config[:version] = version
|
43
|
+
end
|
39
44
|
options.version MSpec::VERSION
|
40
45
|
options.help
|
41
46
|
|
@@ -45,7 +50,7 @@ class MkSpec
|
|
45
50
|
options.doc " 2. To create spec stubs for Fixnum\n"
|
46
51
|
options.doc " $ mkspec -c Fixnum\n"
|
47
52
|
options.doc " 3. To create spec stubs for Complex in 'superspec/complex'\n"
|
48
|
-
options.doc " $ mkspec -c Complex -
|
53
|
+
options.doc " $ mkspec -c Complex -r complex -b superspec"
|
49
54
|
options.doc ""
|
50
55
|
|
51
56
|
options.parse argv
|
@@ -71,13 +76,24 @@ class MkSpec
|
|
71
76
|
parents = '../' * ($1.split('/').length + 1)
|
72
77
|
|
73
78
|
File.open file, 'w' do |f|
|
74
|
-
f.puts "require File.
|
79
|
+
f.puts "require File.expand_path('../#{parents}spec_helper', __FILE__)"
|
75
80
|
config[:requires].each do |lib|
|
76
81
|
f.puts "require '#{lib}'"
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
86
|
+
def write_version(f)
|
87
|
+
f.puts ""
|
88
|
+
if version = config[:version]
|
89
|
+
f.puts "ruby_version_is #{version} do"
|
90
|
+
yield " "
|
91
|
+
f.puts "end"
|
92
|
+
else
|
93
|
+
yield ""
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
81
97
|
def write_spec(file, meth, exists)
|
82
98
|
if exists
|
83
99
|
out = `#{ruby} #{MSPEC_HOME}/bin/mspec-run --dry-run -fs -e '#{meth}' #{file}`
|
@@ -85,12 +101,13 @@ class MkSpec
|
|
85
101
|
end
|
86
102
|
|
87
103
|
File.open file, 'a' do |f|
|
88
|
-
f
|
89
|
-
|
90
|
-
describe "#{meth}" do
|
91
|
-
it "needs to be reviewed for spec completeness"
|
92
|
-
end
|
104
|
+
write_version(f) do |indent|
|
105
|
+
f.puts <<-EOS
|
106
|
+
#{indent}describe "#{meth}" do
|
107
|
+
#{indent} it "needs to be reviewed for spec completeness"
|
108
|
+
#{indent}end
|
93
109
|
EOS
|
110
|
+
end
|
94
111
|
end
|
95
112
|
|
96
113
|
puts file
|
@@ -107,7 +124,7 @@ EOS
|
|
107
124
|
def run
|
108
125
|
config[:requires].each { |lib| require lib }
|
109
126
|
constants = config[:constants]
|
110
|
-
constants =
|
127
|
+
constants = Object.constants if constants.empty?
|
111
128
|
|
112
129
|
@map.map({}, constants).each do |mod, methods|
|
113
130
|
name = mod.chop
|
data/lib/mspec/guards.rb
CHANGED
@@ -11,6 +11,7 @@ require 'mspec/guards/noncompliance'
|
|
11
11
|
require 'mspec/guards/platform'
|
12
12
|
require 'mspec/guards/quarantine'
|
13
13
|
require 'mspec/guards/runner'
|
14
|
+
require 'mspec/guards/specified'
|
14
15
|
require 'mspec/guards/support'
|
15
16
|
require 'mspec/guards/superuser'
|
16
17
|
require 'mspec/guards/tty'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'mspec/guards/guard'
|
2
|
+
|
3
|
+
class UnspecifiedGuard < SpecGuard
|
4
|
+
def match?
|
5
|
+
not standard?
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class SpecifiedOnGuard < SpecGuard
|
10
|
+
def match?
|
11
|
+
if @args.include? :ruby
|
12
|
+
raise Exception, "improper use of specified_on guard"
|
13
|
+
end
|
14
|
+
not standard? and implementation?(*@args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Object
|
19
|
+
# This guard wraps one or more #specified_on guards to group them and
|
20
|
+
# document the specs. The purpose of the guard is for situations where MRI
|
21
|
+
# either does not specify Ruby behavior or where MRI's behavior is all but
|
22
|
+
# impossible to spec, for example due to relying on platform-specific
|
23
|
+
# behavior that is not easily testable from Ruby code. In such cases, it
|
24
|
+
# may be desirable for implementations to explore a specified set of
|
25
|
+
# behaviors that are explicitly documented in the specs.
|
26
|
+
#
|
27
|
+
# unspecified do
|
28
|
+
# specified_on :rubinius, :ironruby do
|
29
|
+
# it "returns true when passed :foo" do
|
30
|
+
# # ...
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# it "returns false when passed :bar" do
|
34
|
+
# # ...
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# specified_on :jruby do
|
39
|
+
# it "returns true when passed :bar" do
|
40
|
+
# # ...
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# Note that these guards do not change the policy of the #compliant_on,
|
46
|
+
# #not_compliant_on, #deviates_on, #extended_on, and #not_supported_on
|
47
|
+
# guards.
|
48
|
+
#
|
49
|
+
def unspecified
|
50
|
+
g = UnspecifiedGuard.new
|
51
|
+
g.name = :unspecified
|
52
|
+
yield if g.yield?
|
53
|
+
ensure
|
54
|
+
g.unregister
|
55
|
+
end
|
56
|
+
|
57
|
+
# This guard wraps specs for one or more particular implementations. See the
|
58
|
+
# #unspecified guard for further documentation.
|
59
|
+
def specified_on(*args)
|
60
|
+
g = SpecifiedOnGuard.new(*args)
|
61
|
+
g.name = :specified_on
|
62
|
+
yield if g.yield?
|
63
|
+
ensure
|
64
|
+
g.unregister
|
65
|
+
end
|
66
|
+
end
|
data/lib/mspec/helpers/io.rb
CHANGED
@@ -19,3 +19,18 @@ class IOStub < String
|
|
19
19
|
self
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
class Object
|
24
|
+
# Creates a "bare" file descriptor (i.e. one that is not associated
|
25
|
+
# with any Ruby object). The file descriptor can safely be passed
|
26
|
+
# to IO.new without creating a Ruby object alias to the fd.
|
27
|
+
def new_fd(name, mode="w:utf-8")
|
28
|
+
IO.sysopen name, fmode(mode)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates an IO instance for a temporary file name. The file
|
32
|
+
# must be deleted.
|
33
|
+
def new_io(name, mode="w:utf-8")
|
34
|
+
IO.new new_fd(name, fmode(mode))
|
35
|
+
end
|
36
|
+
end
|
data/lib/mspec/mocks/mock.rb
CHANGED
data/lib/mspec/mocks/proxy.rb
CHANGED
@@ -24,9 +24,12 @@ class NumericMockObject < Numeric
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class MockProxy
|
27
|
+
attr_reader :raising, :yielding
|
28
|
+
|
27
29
|
def initialize(type=nil)
|
28
30
|
@multiple_returns = nil
|
29
31
|
@returning = nil
|
32
|
+
@raising = nil
|
30
33
|
@yielding = []
|
31
34
|
@arguments = :any_args
|
32
35
|
@type = type || :mock
|
@@ -122,15 +125,23 @@ class MockProxy
|
|
122
125
|
self
|
123
126
|
end
|
124
127
|
|
128
|
+
def and_raise(exception)
|
129
|
+
if exception.kind_of? String
|
130
|
+
@raising = RuntimeError.new exception
|
131
|
+
else
|
132
|
+
@raising = exception
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def raising?
|
137
|
+
@raising != nil
|
138
|
+
end
|
139
|
+
|
125
140
|
def and_yield(*args)
|
126
141
|
@yielding << args
|
127
142
|
self
|
128
143
|
end
|
129
144
|
|
130
|
-
def yielding
|
131
|
-
@yielding
|
132
|
-
end
|
133
|
-
|
134
145
|
def yielding?
|
135
146
|
!@yielding.empty?
|
136
147
|
end
|
data/lib/mspec/utils/name_map.rb
CHANGED
data/lib/mspec/version.rb
CHANGED
@@ -74,6 +74,30 @@ describe "The -r, --require LIBRARY option" do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
describe "The -V, --version-guard VERSION option" do
|
78
|
+
before :each do
|
79
|
+
@options = MSpecOptions.new
|
80
|
+
MSpecOptions.stub!(:new).and_return(@options)
|
81
|
+
@script = MkSpec.new
|
82
|
+
@config = @script.config
|
83
|
+
end
|
84
|
+
|
85
|
+
it "is enabled by #options" do
|
86
|
+
@options.stub!(:on)
|
87
|
+
@options.should_receive(:on).with("-V", "--version-guard", "VERSION",
|
88
|
+
an_instance_of(String))
|
89
|
+
@script.options
|
90
|
+
end
|
91
|
+
|
92
|
+
it "sets the version for the ruby_version_is guards to VERSION" do
|
93
|
+
["-r", "--require"].each do |opt|
|
94
|
+
@config[:requires] = []
|
95
|
+
@script.options [opt, "libspec"]
|
96
|
+
@config[:requires].should include("libspec")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
77
101
|
describe MkSpec, "#options" do
|
78
102
|
before :each do
|
79
103
|
@options = MSpecOptions.new
|
@@ -143,13 +167,13 @@ describe MkSpec, "#write_requires" do
|
|
143
167
|
end
|
144
168
|
|
145
169
|
it "writes the spec_helper require line" do
|
146
|
-
@file.should_receive(:puts).with("require File.
|
170
|
+
@file.should_receive(:puts).with("require File.expand_path('../../../../spec_helper', __FILE__)")
|
147
171
|
@script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
|
148
172
|
end
|
149
173
|
|
150
174
|
it "writes require lines for each library specified on the command line" do
|
151
175
|
@file.stub!(:puts)
|
152
|
-
@file.should_receive(:puts).with("require File.
|
176
|
+
@file.should_receive(:puts).with("require File.expand_path('../../../../spec_helper', __FILE__)")
|
153
177
|
@file.should_receive(:puts).with("require 'complex'")
|
154
178
|
@script.config[:requires] << 'complex'
|
155
179
|
@script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
|
@@ -158,8 +182,7 @@ end
|
|
158
182
|
|
159
183
|
describe MkSpec, "#write_spec" do
|
160
184
|
before :each do
|
161
|
-
@file =
|
162
|
-
@file.stub!(:puts)
|
185
|
+
@file = IOStub.new
|
163
186
|
File.stub!(:open).and_yield(@file)
|
164
187
|
|
165
188
|
@script = MkSpec.new
|
@@ -198,26 +221,40 @@ describe MkSpec, "#write_spec" do
|
|
198
221
|
end
|
199
222
|
|
200
223
|
it "writes a template spec to the file if the spec file does not exist" do
|
201
|
-
@file.should_receive(:puts)
|
224
|
+
@file.should_receive(:puts).twice
|
202
225
|
@script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
203
226
|
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", false)
|
204
227
|
end
|
205
228
|
|
206
229
|
it "writes a template spec to the file if it exists but contains no spec for the method" do
|
207
230
|
@response.should_receive(:=~).and_return(false)
|
208
|
-
@file.should_receive(:puts)
|
231
|
+
@file.should_receive(:puts).twice
|
209
232
|
@script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
210
233
|
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
211
234
|
end
|
212
235
|
|
213
236
|
it "writes a template spec" do
|
214
|
-
@
|
237
|
+
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
238
|
+
@file.should == <<EOS
|
215
239
|
|
216
240
|
describe "Object#inspect" do
|
217
241
|
it "needs to be reviewed for spec completeness"
|
218
242
|
end
|
219
243
|
EOS
|
244
|
+
end
|
245
|
+
|
246
|
+
it "writes a template spec with version guard" do
|
247
|
+
@script.config[:version] = '""..."1.9"'
|
220
248
|
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
249
|
+
@file.should == <<EOS
|
250
|
+
|
251
|
+
ruby_version_is ""..."1.9" do
|
252
|
+
describe "Object#inspect" do
|
253
|
+
it "needs to be reviewed for spec completeness"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
EOS
|
257
|
+
|
221
258
|
end
|
222
259
|
end
|
223
260
|
|
@@ -283,14 +320,6 @@ describe MkSpec, "#run" do
|
|
283
320
|
@script.run
|
284
321
|
end
|
285
322
|
|
286
|
-
it "creates a map of Object.constants if not constants are specified" do
|
287
|
-
@script.config[:constants] = []
|
288
|
-
Object.stub!(:constants).and_return(["Object"])
|
289
|
-
@map.should_receive(:filter).with(["Object"]).and_return(["Object"])
|
290
|
-
@map.should_receive(:map).with({}, ["Object"]).and_return({})
|
291
|
-
@script.run
|
292
|
-
end
|
293
|
-
|
294
323
|
it "calls #create_directory for each class/module in the map" do
|
295
324
|
@script.should_receive(:create_directory).with("MkSpec").twice
|
296
325
|
@script.run
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/guards/specified'
|
3
|
+
|
4
|
+
describe Object, "#unspecified" do
|
5
|
+
before :each do
|
6
|
+
ScratchPad.clear
|
7
|
+
|
8
|
+
@guard = UnspecifiedGuard.new
|
9
|
+
UnspecifiedGuard.stub!(:new).and_return(@guard)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does not yield if #standard? returns true" do
|
13
|
+
@guard.should_receive(:standard?).and_return(true)
|
14
|
+
unspecified { ScratchPad.record :yield }
|
15
|
+
ScratchPad.recorded.should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "yields if #standard? returns false" do
|
19
|
+
@guard.should_receive(:standard?).and_return(false)
|
20
|
+
unspecified { ScratchPad.record :yield }
|
21
|
+
ScratchPad.recorded.should == :yield
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets the name of the guard to :unspecified" do
|
25
|
+
@guard.should_receive(:standard?).and_return(true)
|
26
|
+
unspecified { }
|
27
|
+
@guard.name.should == :unspecified
|
28
|
+
end
|
29
|
+
|
30
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
31
|
+
guard = UnspecifiedGuard.new :rubinius
|
32
|
+
UnspecifiedGuard.stub!(:new).and_return(guard)
|
33
|
+
guard.should_receive(:match?).and_return(true)
|
34
|
+
guard.should_receive(:unregister)
|
35
|
+
|
36
|
+
lambda do
|
37
|
+
unspecified { raise Exception }
|
38
|
+
end.should raise_error(Exception)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Object, "#specified_on" do
|
43
|
+
before :each do
|
44
|
+
ScratchPad.clear
|
45
|
+
end
|
46
|
+
|
47
|
+
it "raises an Exception when passed :ruby" do
|
48
|
+
lambda {
|
49
|
+
specifed_on(:ruby) { ScratchPad.record :yield }
|
50
|
+
}.should raise_error(Exception)
|
51
|
+
ScratchPad.recorded.should_not == :yield
|
52
|
+
end
|
53
|
+
|
54
|
+
it "does not yield when #standard? returns true" do
|
55
|
+
guard = SpecifiedOnGuard.new
|
56
|
+
SpecifiedOnGuard.stub!(:new).and_return(guard)
|
57
|
+
guard.should_receive(:standard?).and_return(true)
|
58
|
+
|
59
|
+
specified_on(:rubinius) { ScratchPad.record :yield }
|
60
|
+
ScratchPad.recorded.should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not yield when #standard? returns false and #implementation? returns false" do
|
64
|
+
guard = SpecifiedOnGuard.new :rubinius
|
65
|
+
SpecifiedOnGuard.stub!(:new).and_return(guard)
|
66
|
+
guard.should_receive(:standard?).and_return(false)
|
67
|
+
guard.should_receive(:implementation?).with(:rubinius).and_return(false)
|
68
|
+
|
69
|
+
specified_on(:rubinius) { ScratchPad.record :yield }
|
70
|
+
ScratchPad.recorded.should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "yields when #standard? returns false and #implementation? returns true" do
|
74
|
+
guard = SpecifiedOnGuard.new :rubinius
|
75
|
+
SpecifiedOnGuard.stub!(:new).and_return(guard)
|
76
|
+
guard.should_receive(:standard?).and_return(false)
|
77
|
+
guard.should_receive(:implementation?).with(:rubinius).and_return(true)
|
78
|
+
|
79
|
+
specified_on(:rubinius) { ScratchPad.record :yield }
|
80
|
+
ScratchPad.recorded.should == :yield
|
81
|
+
end
|
82
|
+
|
83
|
+
it "sets the name of the guard to :specified_on" do
|
84
|
+
guard = SpecifiedOnGuard.new :rubinius
|
85
|
+
SpecifiedOnGuard.stub!(:new).and_return(guard)
|
86
|
+
guard.should_receive(:match?).and_return(false)
|
87
|
+
|
88
|
+
specified_on(:rubinius) { }
|
89
|
+
guard.name.should == :specified_on
|
90
|
+
end
|
91
|
+
|
92
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
93
|
+
guard = SpecifiedOnGuard.new :rubinius
|
94
|
+
SpecifiedOnGuard.stub!(:new).and_return(guard)
|
95
|
+
guard.should_receive(:match?).and_return(true)
|
96
|
+
guard.should_receive(:unregister)
|
97
|
+
|
98
|
+
lambda do
|
99
|
+
specified_on(:rubinius) { raise Exception }
|
100
|
+
end.should raise_error(Exception)
|
101
|
+
end
|
102
|
+
end
|
data/spec/helpers/io_spec.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/helpers/io'
|
3
|
+
require 'mspec/helpers/fs'
|
4
|
+
require 'mspec/helpers/tmp'
|
2
5
|
|
3
6
|
describe IOStub do
|
4
7
|
before :each do
|
@@ -41,3 +44,56 @@ describe IOStub do
|
|
41
44
|
@out.flush.should == @out
|
42
45
|
end
|
43
46
|
end
|
47
|
+
|
48
|
+
describe Object, "#new_fd" do
|
49
|
+
before :each do
|
50
|
+
@name = tmp("io_specs")
|
51
|
+
end
|
52
|
+
|
53
|
+
after :each do
|
54
|
+
@io.close unless @io.closed?
|
55
|
+
rm_r @name
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns a Fixnum that can be used to create an IO instance" do
|
59
|
+
fd = new_fd @name
|
60
|
+
fd.should be_an_instance_of(Fixnum)
|
61
|
+
|
62
|
+
@io = IO.new fd
|
63
|
+
@io.sync = true
|
64
|
+
@io.print "io data"
|
65
|
+
|
66
|
+
IO.read(@name).should == "io data"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe Object, "#new_io" do
|
71
|
+
before :each do
|
72
|
+
@name = tmp("io_specs.txt")
|
73
|
+
end
|
74
|
+
|
75
|
+
after :each do
|
76
|
+
@io.close if @io and !@io.closed?
|
77
|
+
rm_r @name
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns an IO instance" do
|
81
|
+
@io = new_io @name
|
82
|
+
@io.should be_an_instance_of(IO)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "opens the IO for reading if passed 'r'" do
|
86
|
+
touch(@name) { |f| f.print "io data" }
|
87
|
+
@io = new_io @name, "r"
|
88
|
+
@io.read.should == "io data"
|
89
|
+
lambda { @io.puts "more data" }.should raise_error(IOError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "opens the IO for writing if passed 'w'" do
|
93
|
+
@io = new_io @name, "w"
|
94
|
+
@io.sync = true
|
95
|
+
|
96
|
+
@io.print "io data"
|
97
|
+
IO.read(@name).should == "io data"
|
98
|
+
end
|
99
|
+
end
|
data/spec/mocks/mock_spec.rb
CHANGED
@@ -207,6 +207,8 @@ describe Mock, ".install_method" do
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
+
class MockAndRaiseError < Exception; end
|
211
|
+
|
210
212
|
describe Mock, ".verify_call" do
|
211
213
|
before :each do
|
212
214
|
MSpec.stub!(:actions)
|
@@ -304,6 +306,13 @@ describe Mock, ".verify_call" do
|
|
304
306
|
Mock.verify_call(@mock, :method_call) {|*a|}
|
305
307
|
}.should_not raise_error(SpecExpectationNotMetError)
|
306
308
|
end
|
309
|
+
|
310
|
+
it "raises an exception when expected to" do
|
311
|
+
@proxy.and_raise(MockAndRaiseError)
|
312
|
+
lambda {
|
313
|
+
Mock.verify_call @mock, :method_call
|
314
|
+
}.should raise_error(MockAndRaiseError)
|
315
|
+
end
|
307
316
|
end
|
308
317
|
|
309
318
|
describe Mock, ".verify_count" do
|
data/spec/mocks/proxy_spec.rb
CHANGED
@@ -330,6 +330,29 @@ describe MockProxy, "#and_yield" do
|
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
|
+
describe MockProxy, "#raising" do
|
334
|
+
before :each do
|
335
|
+
@proxy = MockProxy.new
|
336
|
+
end
|
337
|
+
|
338
|
+
it "returns nil by default" do
|
339
|
+
@proxy.raising.should be_nil
|
340
|
+
end
|
341
|
+
|
342
|
+
it "returns the exception object passed to #and_raise" do
|
343
|
+
exc = mock("exception")
|
344
|
+
@proxy.and_raise(exc)
|
345
|
+
@proxy.raising.should equal(exc)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "returns an instance of RuntimeError when a String is passed to #and_raise" do
|
349
|
+
@proxy.and_raise("an error")
|
350
|
+
exc = @proxy.raising
|
351
|
+
exc.should be_an_instance_of(RuntimeError)
|
352
|
+
exc.message.should == "an error"
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
333
356
|
describe MockProxy, "#yielding" do
|
334
357
|
before :each do
|
335
358
|
@proxy = MockProxy.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Ford
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/mspec/guards/platform.rb
|
48
48
|
- lib/mspec/guards/quarantine.rb
|
49
49
|
- lib/mspec/guards/runner.rb
|
50
|
+
- lib/mspec/guards/specified.rb
|
50
51
|
- lib/mspec/guards/superuser.rb
|
51
52
|
- lib/mspec/guards/support.rb
|
52
53
|
- lib/mspec/guards/tty.rb
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- spec/guards/platform_spec.rb
|
181
182
|
- spec/guards/quarantine_spec.rb
|
182
183
|
- spec/guards/runner_spec.rb
|
184
|
+
- spec/guards/specified_spec.rb
|
183
185
|
- spec/guards/superuser_spec.rb
|
184
186
|
- spec/guards/support_spec.rb
|
185
187
|
- spec/guards/tty_spec.rb
|