How to test puts in rspec -
i want run ruby sayhello.rb on command line, receive hello rspec.
i've got this:
class hello def speak puts 'hello rspec' end end hi = hello.new #brings object existence hi.speak now want write test in rspec check command line output in fact "hello rspec" , not "i unix"
not working. have in sayhello_spec.rb file
require_relative 'sayhello.rb' #points file can 'see' describe "sayhello.rb" "should 'hello rspec' when ran" stdout.should_receive(:puts).with('hello rspec') end end also, need see test should in rspec please.
you're executing code before entering test block, expectations not being met. need run code within test block after setting expectations (e.g. moving require_relative statement after stdout.... statement), follows:
describe "sayhello.rb" "should 'hello rspec' when ran" stdout.should_receive(:puts).with('hello rspec') require_relative 'sayhello.rb' #load/run file end end
Comments
Post a Comment