解决方法
你可以存储内核#获取,除了它被混合到对象中,所以存在它:
class Mirror def echo print "enter something: " response = gets.chomp puts "#{response}" end end require 'rspec' describe Mirror do it "should echo" do @mirror = Mirror.new @mirror.stub!(:gets) { "phrase\n" } @mirror.should_receive(:puts).with("phrase") @mirror.echo end end