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're executing your code before entering the test block, so the expectations are not being met. You need to run the code within the test block after setting expectations (e.g. by moving the require_relative
statement after the STDOUT....
statement), as follows:
describe "sayhello.rb" do
it "should say 'Hello from Rspec' when ran" do
STDOUT.should_receive(:puts).with('Hello from RSpec')
require_relative 'sayhello.rb' #load/run the file
end
end