[rspec-users] getting output of STDOUT in spec

David Chelimsky dchelimsky at gmail.com
Tue Apr 10 08:21:11 EDT 2007


On 4/10/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
> Consider the following method:
>
> def name_to_terminal
>    puts "Scott Taylor"
> end
>
> How would I spec this out?

RSpec prints to STDOUT, but the examples and implementation use an
instance of IO (mocked for the examples). So you'd have something
like:

describe Interactor do
  setup { @interactor = Interactor.new(@io = mock("IO")) }
  it "should print name to IO" do
    @io.should_receive(:<<).with("Scott Taylor")
    @interactor.print "Scott Taylor"
  end
end

>
> Scott
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list