I want to do is run ruby sayhello.rb
on the command line, then receive Hello from Rspec
.
I\'ve got that with this:
class Hello
You can solve this using Rails' active_support library, which adds a capture method:
require 'active_support/core_ext/kernel/reporting'
require_relative 'sayhello'
describe Hello do
it "says 'Hello from RSpec' when ran" do
output = capture(:stdout) do
hi = Hello.new
hi.speak
end
expect(output).to include 'Hello from RSpec'
end
end