bte*_*les 6 ruby command-line rspec
我正在尝试从命令行工具测试输出.如何使用rspec"伪造"命令行调用?执行以下操作不起作用:
it "should call the command line and return 'text'" do
@p = Pig.new
@p.should_receive(:run).with('my_command_line_tool_call').and_return('result text')
end
Run Code Online (Sandbox Code Playgroud)
如何创建该存根?
小智 12
使用新消息期望语法:
require "dummy"
describe Dummy do
it "command_line should call ls" do
d = Dummy.new
expect(d).to receive(:system).with("ls")
d.command_line
end
end
Run Code Online (Sandbox Code Playgroud)
class Dummy
def command_line
system("ls")
end
end
Run Code Online (Sandbox Code Playgroud)
这是我做的一个简单例子.我叫LS从我哑类.用rspec测试
require "rubygems"
require "spec"
class Dummy
def command_line
system("ls")
end
end
describe Dummy do
it "command_line should call ls" do
d = Dummy.new
d.should_receive("system").with("ls")
d.command_line
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8395 次 |
| 最近记录: |