[rspec-users] Selectively ignoring exceptions in examples

Alex Chaffee alex at stinky.com
Mon Aug 29 19:09:50 EDT 2011

On Mon, Aug 29, 2011 at 9:24 AM, Ash Moran <ash.moran at patchspace.co.uk> wrote:
>   it "prints an error" do
>     ignoring_errors {
>       run_command(%w[ missing_wallet.dat ])
>     }
>     stream_bundle.captured_error.should eq "Couldn't find wallet file: missing_wallet.dat\n"
>   end
> Now obviously that wouldn't be hard to add as a helper method. But it got me thinking…
> * Do any of you do this?

I do. So often that I wrote a helper and put it in Wrong.

I don't quite get what "stream_bundle.captured_error" is in your
example, but I think the above example would become

rescuing {
  run_command(%w[ missing_wallet.dat ])
}.message.should == "Couldn't find whatever"

We've also got "capturing" for grabbing console output, e.g.

capturing { puts "hi" }.should == "hi"


out, err = capturing(:stdout, :stderr) { ... }

See https://github.com/sconover/wrong

Alex Chaffee - alex at stinky.com

More information about the rspec-users mailing list