Skip to content

Commit b1bc0cf

Browse files
committed
Replace stub with allow...to receive
1 parent 1b9b18e commit b1bc0cf

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

spec/actions/create_file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def create_file(destination=nil, config={}, options={})
1010
@base = MyCounter.new([1, 2], options, { :destination_root => destination_root })
11-
@base.stub(:file_name).and_return('rdoc')
11+
allow(@base).to receive(:file_name).and_return('rdoc')
1212

1313
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
1414
{ :verbose => !@silence }.merge(config))

spec/actions/create_link_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def create_link(destination=nil, config={}, options={})
1313
@base = MyCounter.new([1,2], options, { :destination_root => destination_root })
14-
@base.stub(:file_name).and_return('rdoc')
14+
allow(@base).to receive(:file_name).and_return('rdoc')
1515

1616
@tempfile = Tempfile.new("config.rb")
1717

spec/actions/directory_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
describe Thor::Actions::Directory do
55
before do
66
::FileUtils.rm_rf(destination_root)
7-
invoker.stub(:file_name).and_return("rdoc")
7+
allow(invoker).to receive(:file_name).and_return("rdoc")
88
end
99

1010
def invoker

spec/actions/empty_directory_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def base
100100
describe "#convert_encoded_instructions" do
101101
before do
102102
empty_directory("test_dir")
103-
@action.base.stub(:file_name).and_return("expected")
103+
allow(@action.base).to receive(:file_name).and_return("expected")
104104
end
105105

106106
it "accepts and executes a 'legal' %\w+% encoded instruction" do

spec/actions_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def file
208208
@foo = "FOO"
209209
say_status :cool, :padding
210210
TEMPLATE
211-
@template.stub(:read).and_return(@template)
211+
allow(@template).to receive(:read).and_return(@template)
212212

213213
@file = '/'
214-
runner.stub(:open).and_return(@template)
214+
allow(runner).to receive(:open).and_return(@template)
215215
end
216216

217217
it "accepts a URL as the path" do
@@ -277,7 +277,7 @@ def file
277277

278278
describe "#run_ruby_script" do
279279
before do
280-
Thor::Util.stub(:ruby_command).and_return("/opt/jruby")
280+
allow(Thor::Util).to receive(:ruby_command).and_return("/opt/jruby")
281281
expect(runner).to receive(:system).with("/opt/jruby script.rb")
282282
end
283283

spec/runner_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def when_no_thorfiles_exist
130130
root_file = File.join(Thor::Util.thor_root, "thor.yml")
131131

132132
# Stub load and save to avoid thor.yaml from being overwritten
133-
YAML.stub(:load_file).and_return(@original_yaml)
134-
File.stub(:exists?).with(root_file).and_return(true)
135-
File.stub(:open).with(root_file, "w")
133+
allow(YAML).to receive(:load_file).and_return(@original_yaml)
134+
allow(File).to receive(:exists?).with(root_file).and_return(true)
135+
allow(File).to receive(:open).with(root_file, "w")
136136
end
137137

138138
describe "list" do
@@ -214,9 +214,9 @@ def when_no_thorfiles_exist
214214

215215
describe "install/update" do
216216
before do
217-
FileUtils.stub(:mkdir_p)
218-
FileUtils.stub(:touch)
219-
$stdin.stub(:gets).and_return("Y")
217+
allow(FileUtils).to receive(:mkdir_p)
218+
allow(FileUtils).to receive(:touch)
219+
allow($stdin).to receive(:gets).and_return("Y")
220220

221221
path = File.join(Thor::Util.thor_root, Digest::MD5.hexdigest(@location + "random"))
222222
expect(File).to receive(:open).with(path, "w")

spec/shell/basic_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,33 +260,33 @@ def #456 Lanç...
260260
end
261261

262262
it "returns true if the user chooses default option" do
263-
$stdout.stub(:print)
263+
allow($stdout).to receive(:print)
264264
expect($stdin).to receive(:gets).and_return('')
265265
expect(shell.file_collision('foo')).to be_true
266266
end
267267

268268
it "returns false if the user chooses no" do
269-
$stdout.stub(:print)
269+
allow($stdout).to receive(:print)
270270
expect($stdin).to receive(:gets).and_return('n')
271271
expect(shell.file_collision('foo')).to be_false
272272
end
273273

274274
it "returns true if the user chooses yes" do
275-
$stdout.stub(:print)
275+
allow($stdout).to receive(:print)
276276
expect($stdin).to receive(:gets).and_return('y')
277277
expect(shell.file_collision('foo')).to be_true
278278
end
279279

280280
it "shows help usage if the user chooses help" do
281-
$stdout.stub(:print)
281+
allow($stdout).to receive(:print)
282282
expect($stdin).to receive(:gets).and_return('h')
283283
expect($stdin).to receive(:gets).and_return('n')
284284
help = capture(:stdout) { shell.file_collision('foo') }
285285
expect(help).to match(/h \- help, show this help/)
286286
end
287287

288288
it "quits if the user chooses quit" do
289-
$stdout.stub(:print)
289+
allow($stdout).to receive(:print)
290290
expect($stdout).to receive(:puts).with('Aborting...')
291291
expect($stdin).to receive(:gets).and_return('q')
292292

@@ -313,7 +313,7 @@ def #456 Lanç...
313313
end
314314

315315
it "invokes the diff command" do
316-
$stdout.stub(:print)
316+
allow($stdout).to receive(:print)
317317
expect($stdin).to receive(:gets).and_return('d')
318318
expect($stdin).to receive(:gets).and_return('n')
319319
expect(shell).to receive(:system).with(/diff -u/)

spec/shell/color_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def shell
8080
describe "#file_collision" do
8181
describe "when a block is given" do
8282
it "invokes the diff command" do
83-
$stdout.stub(:print)
84-
$stdout.stub(:tty?).and_return(true)
83+
allow($stdout).to receive(:print)
84+
allow($stdout).to receive(:tty?).and_return(true)
8585
expect($stdin).to receive(:gets).and_return('d')
8686
expect($stdin).to receive(:gets).and_return('n')
8787

spec/util_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def self.clear_user_home!
120120

121121
describe "#user_home" do
122122
before do
123-
ENV.stub(:[])
123+
allow(ENV).to receive(:[])
124124
Thor::Util.clear_user_home!
125125
end
126126

@@ -145,30 +145,30 @@ def self.clear_user_home!
145145
end
146146

147147
it "returns HOME/.thor if set" do
148-
ENV.stub(:[]).with("HOME").and_return("/home/user/")
148+
allow(ENV).to receive(:[]).with("HOME").and_return("/home/user/")
149149
expect(Thor::Util.user_home).to eq("/home/user/")
150150
end
151151

152152
it "returns path with HOMEDRIVE and HOMEPATH if set" do
153-
ENV.stub(:[]).with("HOMEDRIVE").and_return("D:/")
154-
ENV.stub(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
153+
allow(ENV).to receive(:[]).with("HOMEDRIVE").and_return("D:/")
154+
allow(ENV).to receive(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
155155
expect(Thor::Util.user_home).to eq("D:/Documents and Settings/James")
156156
end
157157

158158
it "returns APPDATA/.thor if set" do
159-
ENV.stub(:[]).with("APPDATA").and_return("/home/user/")
159+
allow(ENV).to receive(:[]).with("APPDATA").and_return("/home/user/")
160160
expect(Thor::Util.user_home).to eq("/home/user/")
161161
end
162162
end
163163

164164
describe "#thor_root_glob" do
165165
before do
166-
ENV.stub(:[])
166+
allow(ENV).to receive(:[])
167167
Thor::Util.clear_user_home!
168168
end
169169

170170
it "escapes globs in path" do
171-
ENV.stub(:[]).with("HOME").and_return("/home/user{1}/")
171+
allow(ENV).to receive(:[]).with("HOME").and_return("/home/user{1}/")
172172
expect(Dir).to receive(:[]).with("/home/user\\{1\\}/.thor/*").and_return([])
173173
expect(Thor::Util.thor_root_glob).to eq([])
174174
end

0 commit comments

Comments
 (0)