Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created February 9, 2012 05:00
Show Gist options
  • Select an option

  • Save mgreenly/1777441 to your computer and use it in GitHub Desktop.

Select an option

Save mgreenly/1777441 to your computer and use it in GitHub Desktop.
sinking stdout in rspec
class Foo
def run
puts "usage: foo"
0
end
end
RSpec.configure do |config|
config.before(:all) do
@null_out = File.open('/dev/null', 'w')
@orig_out = $stdout
end
config.before(:each) do
$stdout = @null_out
end
config.after(:each) do
$stdout = @orig_out
end
end
describe Foo do
it { subject.run.should eq(0) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment