Skip to content

Commit

Permalink
be explicit in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpdoyle committed Mar 23, 2016
1 parent 3650d65 commit 8c07a83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
10 changes: 5 additions & 5 deletions lib/ember_cli/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def run!(command)

def redirect(stream, pipes:)
pipes.each do |pipe|
Thread.new do
Thread.current.abort_on_exception = true

IO.copy_stream(stream, pipe)
end
# Thread.new do
# Thread.current.abort_on_exception = true
#
IO.copy_stream(stream, pipe)
# end
end
end
end
Expand Down
34 changes: 18 additions & 16 deletions spec/lib/ember_cli/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,33 @@
describe "#run!" do
context "when the command fails" do
it "writes output to `out` streams" do
output_streams = Array.new(2) { StringIO.new }
stdout = StringIO.new
logfile = StringIO.new
runner = EmberCli::Runner.new(
err: [],
out: output_streams,
out: [stdout, logfile],
)

expect { runner.run!(command_with_error(out: "out")) }.
to raise_error(SystemExit)

ouput_strings = output_streams.each(&:rewind).map(&:read)

ouput_strings.each do |output|
expect(output.split).to eq(%w[out out])
end
expect(split_output_from_stream(stdout)).to eq(%w[out out])
expect(split_output_from_stream(logfile)).to eq(%w[out out])
end

it "writes errors to `err` streams" do
error_streams = Array.new(2) { StringIO.new }
stderr = StringIO.new
logfile = StringIO.new
runner = EmberCli::Runner.new(
err: error_streams,
err: [stderr, logfile],
out: [],
)

expect { runner.run!(command_with_error(err: "err")) }.
to raise_error(SystemExit)

error_strings = error_streams.each(&:rewind).map(&:read)

error_strings.each do |error|
expect(error.split).to eq(%w[err err])
end
expect(split_output_from_stream(stderr)).to eq(%w[err err])
expect(split_output_from_stream(logfile)).to eq(%w[err err])
end
end

Expand All @@ -48,8 +44,14 @@
[err, out].each(&:rewind)

expect(status).to be_success
expect(err.read).to be_empty
expect(out.read).to eq("out\n")
expect(split_output_from_stream(err)).to be_empty
expect(split_output_from_stream(out)).to eq(%w[out])
end

def split_output_from_stream(stream)
stream.rewind

stream.read.split
end

def command(output)
Expand Down

0 comments on commit 8c07a83

Please sign in to comment.