How to test puts in rspec

前端 未结 5 1228
遇见更好的自我
遇见更好的自我 2021-02-02 08:15

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
         


        
5条回答
  •  自闭症患者
    2021-02-02 08:47

    Based on previous answers/comments, a solution using the new syntax without a gem would look like this:

    describe "sayhello.rb" do
      it "should say 'Hello from Rspec' when run" do        
        expect(STDOUT).to receive(:puts).with('Hello from RSpec')
        require_relative 'sayhello.rb'  # load/run the file 
      end
    end
    

提交回复
热议问题