Skip to content

Commit

Permalink
Less hacks in command_executor_spec (fastlane#15131)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotdoom authored and Josh Holtz committed Aug 13, 2019
1 parent 592b00b commit 2b9877b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions fastlane_core/spec/command_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
end

it 'handles reading which throws a EIO exception', requires_pty: true do
explodes_on_strip = 'danger! lasers!'
fake_std_in = ['a_filename', explodes_on_strip]

# In reality the exception is raised by the `each` call, but for easier mocking
# we manually raise the exception when the line is cleaned up with `strip` afterward
expect(explodes_on_strip).to receive(:strip).and_raise(Errno::EIO)

child_process_id = 1
expect(Process).to receive(:wait).with(child_process_id)

# Hacky approach because $? is not be defined since we skip the actual spawn
allow_message_expectations_on_nil
expect($?).to receive(:exitstatus).and_return(0)
fake_std_in = [
"a_filename\n"
]
expect(fake_std_in).to receive(:each).and_yield(*fake_std_in).and_raise(Errno::EIO)

# Make a fake child process so we have a valid PID and $? is set correctly
expect(PTY).to receive(:spawn) do |command, &block|
expect(command).to eq('ls')

# PTY uses "$?" to get exitcode, which is filled in by Process.wait(),
# so we have to spawn a real process unless we want to mock methods
# on nil.
child_process_id = Process.spawn('echo foo', out: File::NULL)
expect(Process).to receive(:wait).with(child_process_id)

block.yield(fake_std_in, 'not_really_std_out', child_process_id)
end

Expand Down

0 comments on commit 2b9877b

Please sign in to comment.