Skip to content

Commit 1b9b18e

Browse files
committed
Replace should_receive with expect...to receive
1 parent 5b1d25f commit 1b9b18e

11 files changed

+94
-94
lines changed

spec/actions/create_file_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def silence!
103103

104104
it "shows conflict status to the user" do
105105
expect(create_file("doc/config.rb")).not_to be_identical
106-
$stdin.should_receive(:gets).and_return('s')
106+
expect($stdin).to receive(:gets).and_return('s')
107107
file = File.join(destination_root, 'doc/config.rb')
108108

109109
content = invoke!
@@ -114,21 +114,21 @@ def silence!
114114

115115
it "creates the file if the file collision menu returns true" do
116116
create_file("doc/config.rb")
117-
$stdin.should_receive(:gets).and_return('y')
117+
expect($stdin).to receive(:gets).and_return('y')
118118
expect(invoke!).to match(/force doc\/config\.rb/)
119119
end
120120

121121
it "skips the file if the file collision menu returns false" do
122122
create_file("doc/config.rb")
123-
$stdin.should_receive(:gets).and_return('n')
123+
expect($stdin).to receive(:gets).and_return('n')
124124
expect(invoke!).to match(/skip doc\/config\.rb/)
125125
end
126126

127127
it "executes the block given to show file content" do
128128
create_file("doc/config.rb")
129-
$stdin.should_receive(:gets).and_return('d')
130-
$stdin.should_receive(:gets).and_return('n')
131-
@base.shell.should_receive(:system).with(/diff -u/)
129+
expect($stdin).to receive(:gets).and_return('d')
130+
expect($stdin).to receive(:gets).and_return('n')
131+
expect(@base.shell).to receive(:system).with(/diff -u/)
132132
invoke!
133133
end
134134
end

spec/actions/file_manipulation_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ def file
2929

3030
describe "#chmod" do
3131
it "executes the command given" do
32-
FileUtils.should_receive(:chmod_R).with(0755, file)
32+
expect(FileUtils).to receive(:chmod_R).with(0755, file)
3333
action :chmod, "foo", 0755
3434
end
3535

3636
it "does not execute the command if pretending" do
37-
FileUtils.should_not_receive(:chmod_R)
37+
expect(FileUtils).not_to receive(:chmod_R)
3838
runner(:pretend => true)
3939
action :chmod, "foo", 0755
4040
end
4141

4242
it "logs status" do
43-
FileUtils.should_receive(:chmod_R).with(0755, file)
43+
expect(FileUtils).to receive(:chmod_R).with(0755, file)
4444
expect(action(:chmod, "foo", 0755)).to eq(" chmod foo\n")
4545
end
4646

4747
it "does not log status if required" do
48-
FileUtils.should_receive(:chmod_R).with(0755, file)
48+
expect(FileUtils).to receive(:chmod_R).with(0755, file)
4949
expect(action(:chmod, "foo", 0755, :verbose => false)).to be_empty
5050
end
5151
end
@@ -178,7 +178,7 @@ def file
178178
end
179179

180180
it "converts encoded instructions" do
181-
runner.should_receive(:file_name).and_return("rdoc")
181+
expect(runner).to receive(:file_name).and_return("rdoc")
182182
action :template, "doc/%file_name%.rb.tt"
183183
file = File.join(destination_root, "doc/rdoc.rb")
184184
expect(File.exists?(file)).to be_true

spec/actions_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,19 @@ def file
216216

217217
it "accepts a URL as the path" do
218218
@file = "http://gist.github.com/103208.txt"
219-
runner.should_receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
219+
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
220220
action(:apply, @file)
221221
end
222222

223223
it "accepts a secure URL as the path" do
224224
@file = "https://gist.github.com/103208.txt"
225-
runner.should_receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
225+
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
226226
action(:apply, @file)
227227
end
228228

229229
it "accepts a local file path with spaces" do
230230
@file = File.expand_path("fixtures/path with spaces", File.dirname(__FILE__))
231-
runner.should_receive(:open).with(@file).and_return(@template)
231+
expect(runner).to receive(:open).with(@file).and_return(@template)
232232
action(:apply, @file)
233233
end
234234

@@ -254,7 +254,7 @@ def file
254254

255255
describe "#run" do
256256
before do
257-
runner.should_receive(:system).with("ls")
257+
expect(runner).to receive(:system).with("ls")
258258
end
259259

260260
it "executes the command given" do
@@ -270,15 +270,15 @@ def file
270270
end
271271

272272
it "accepts a color as status" do
273-
runner.shell.should_receive(:say_status).with(:run, 'ls from "."', :yellow)
273+
expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow)
274274
action :run, "ls", :verbose => :yellow
275275
end
276276
end
277277

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

284284
it "executes the ruby script" do
@@ -296,35 +296,35 @@ def file
296296

297297
describe "#thor" do
298298
it "executes the thor command" do
299-
runner.should_receive(:system).with("thor list")
299+
expect(runner).to receive(:system).with("thor list")
300300
action :thor, :list, :verbose => true
301301
end
302302

303303
it "converts extra arguments to command arguments" do
304-
runner.should_receive(:system).with("thor list foo bar")
304+
expect(runner).to receive(:system).with("thor list foo bar")
305305
action :thor, :list, "foo", "bar"
306306
end
307307

308308
it "converts options hash to switches" do
309-
runner.should_receive(:system).with("thor list foo bar --foo")
309+
expect(runner).to receive(:system).with("thor list foo bar --foo")
310310
action :thor, :list, "foo", "bar", :foo => true
311311

312-
runner.should_receive(:system).with("thor list --foo 1 2 3")
312+
expect(runner).to receive(:system).with("thor list --foo 1 2 3")
313313
action :thor, :list, :foo => [1,2,3]
314314
end
315315

316316
it "logs status" do
317-
runner.should_receive(:system).with("thor list")
317+
expect(runner).to receive(:system).with("thor list")
318318
expect(action(:thor, :list)).to eq(" run thor list from \".\"\n")
319319
end
320320

321321
it "does not log status if required" do
322-
runner.should_receive(:system).with("thor list --foo 1 2 3")
322+
expect(runner).to receive(:system).with("thor list --foo 1 2 3")
323323
expect(action(:thor, :list, :foo => [1,2,3], :verbose => false)).to be_empty
324324
end
325325

326326
it "captures the output when :capture is given" do
327-
runner.should_receive(:`).with("thor foo bar")
327+
expect(runner).to receive(:`).with("thor foo bar")
328328
action(:thor, "foo", "bar", :capture => true)
329329
end
330330
end

spec/command_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def command(options={})
4242

4343
it "does not invoke an existing method" do
4444
mock = mock()
45-
mock.class.should_receive(:handle_no_command_error).with("to_s")
45+
expect(mock.class).to receive(:handle_no_command_error).with("to_s")
4646
Thor::DynamicCommand.new('to_s').run(mock)
4747
end
4848
end
@@ -58,7 +58,7 @@ def command(options={})
5858
describe "#run" do
5959
it "runs a command by calling a method in the given instance" do
6060
mock = mock()
61-
mock.should_receive(:can_has).and_return {|*args| args }
61+
expect(mock).to receive(:can_has).and_return {|*args| args }
6262
expect(command.run(mock, [1, 2, 3])).to eq([1, 2, 3])
6363
end
6464

spec/group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
end
3737

3838
it "invokes help message if any of the shortcuts are given" do
39-
MyCounter.should_receive(:help)
39+
expect(MyCounter).to receive(:help)
4040
MyCounter.start(["-h"])
4141
end
4242
end

spec/runner_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def when_no_thorfiles_exist
4646

4747
it "raises error if a class/command cannot be found for a setup without thorfiles" do
4848
when_no_thorfiles_exist do
49-
Thor::Runner.should_receive :exit
49+
expect(Thor::Runner).to receive :exit
5050
content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
5151
expect(content.strip).to eq('Could not find command "unknown".')
5252
end
@@ -93,7 +93,7 @@ def when_no_thorfiles_exist
9393
it "raises an error if class/command can't be found in a setup without thorfiles" do
9494
when_no_thorfiles_exist do
9595
ARGV.replace ["unknown"]
96-
Thor::Runner.should_receive :exit
96+
expect(Thor::Runner).to receive :exit
9797
content = capture(:stderr){ Thor::Runner.start }
9898
expect(content.strip).to eq('Could not find command "unknown".')
9999
end
@@ -192,7 +192,7 @@ def when_no_thorfiles_exist
192192
describe "uninstall" do
193193
before do
194194
path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
195-
FileUtils.should_receive(:rm_rf).with(path)
195+
expect(FileUtils).to receive(:rm_rf).with(path)
196196
end
197197

198198
it "uninstalls existing thor modules" do
@@ -202,7 +202,7 @@ def when_no_thorfiles_exist
202202

203203
describe "installed" do
204204
before do
205-
Dir.should_receive(:[]).and_return([])
205+
expect(Dir).to receive(:[]).and_return([])
206206
end
207207

208208
it "displays the modules installed in a pretty way" do
@@ -219,15 +219,15 @@ def when_no_thorfiles_exist
219219
$stdin.stub(:gets).and_return("Y")
220220

221221
path = File.join(Thor::Util.thor_root, Digest::MD5.hexdigest(@location + "random"))
222-
File.should_receive(:open).with(path, "w")
222+
expect(File).to receive(:open).with(path, "w")
223223
end
224224

225225
it "updates existing thor files" do
226226
path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
227227
if File.directory? path
228-
FileUtils.should_receive(:rm_rf).with(path)
228+
expect(FileUtils).to receive(:rm_rf).with(path)
229229
else
230-
File.should_receive(:delete).with(path)
230+
expect(File).to receive(:delete).with(path)
231231
end
232232
silence(:stdout) { Thor::Runner.start(["update", "random"]) }
233233
end

0 commit comments

Comments
 (0)