Skip to content

Commit

Permalink
clean up spec helpers, no top level methods please
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Apr 28, 2012
1 parent 4c0f74f commit 78bc645
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.expand_path("support/**/*.rb", File.dirname(__FILE__))].each {|f| require f}
Dir[File.expand_path("support/*.rb", File.dirname(__FILE__))].each {|f| require f}

RSpec.configure do |config|
config.include OutputStreams
config.filter_run :focused => true
config.filter_run_excluding :disabled => true
config.run_all_when_everything_filtered = true
Expand Down
36 changes: 9 additions & 27 deletions spec/support/output_streams.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
def capture_stderr(&block)
original_stderr = $stderr
$stderr = fake = StringIO.new
begin
yield
ensure
$stderr = original_stderr
end
fake.string
end

def capture_stdout(&block)
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
yield
ensure
$stdout = original_stdout
end
fake.string
end

# wrapper around raise_error that captures stderr
def should_abort_with(msg)
capture_stderr do
expect do
module OutputStreams
def capture_stdout(&block)
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
yield
end.to raise_error SystemExit, msg
ensure
$stdout = original_stdout
end
fake.string
end
end

0 comments on commit 78bc645

Please sign in to comment.