我想要做的是在命令行上运行ruby sayhello.rb
,然后接收Hello from Rspec
。用RSpec测试输出到命令行
我已经得到了这一点:
class Hello
def speak
puts 'Hello from RSpec'
end
end
hi = Hello.new #brings my object into existence
hi.speak
现在我想要写在rspec的测试,以检查命令行输出实际上是“从RSpec的你好” ,而不是“我喜欢的Unix “
不工作。我目前在我的sayhello_spec.rb文件中有这个
require_relative 'sayhello.rb' #points to file so I can 'see' it
describe "sayhello.rb" do
it "should say 'Hello from Rspec' when ran" do
STDOUT.should_receive(:puts).with('Hello from RSpec')
end
end
请问有人能指出我正确的方向吗?
建立在这一: DEF expect_stdout(字符串,&块); output = capture_stdout(&block); output.should包含字符串; 结束 – 2013-11-27 13:47:34