Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使用rspec测试可执行文件_Ruby_Rspec_Tdd - Fatal编程技术网

Ruby 使用rspec测试可执行文件

Ruby 使用rspec测试可执行文件,ruby,rspec,tdd,Ruby,Rspec,Tdd,有什么方法可以使用rspec测试通用可执行文件吗? 我喜欢rspec中定义测试的方式 类似于 it "should return error" do program.output.should == "Error in program" end Rspec 3.0输出匹配器: 期望{its_my_mthd}输出(“its the message for the world”)。输出到stdout 期望{its_my_mthd}.输出(“它的魔鬼消息错误”)。到\u stderr Min

有什么方法可以使用rspec测试通用可执行文件吗? 我喜欢rspec中定义测试的方式

类似于

it "should return error" do
    program.output.should == "Error in program"
end

Rspec 3.0输出匹配器:

期望{its_my_mthd}输出(“its the message for the world”)。输出到stdout
期望{its_my_mthd}.输出(“它的魔鬼消息错误”)。到\u stderr

Minitest还有一种称为capture_io的功能:

out, err = capture_io do
  my_method
end

assert_equals "its the message for the world", out
assert_equals "its devils message error", err

它的mthd是什么?如何为我的系统命令指定参数?这也适用于在backticks中执行的shell命令。