File: script_exit_status_spec.rb

package info (click to toggle)
ruby-thor 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 904 kB
  • sloc: ruby: 9,250; makefile: 8; sh: 1
file content (29 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
describe "when the Thor class's exit_with_failure? method returns true" do
  def thor_command(command)
    gem_dir= File.expand_path("#{File.dirname(__FILE__)}/..")
    lib_path= "#{gem_dir}/lib"
    script_path= "#{gem_dir}/spec/fixtures/exit_status.thor"
    ruby_lib= ENV["RUBYLIB"].nil? ? lib_path : "#{lib_path}:#{ENV['RUBYLIB']}"

    full_command= "ruby #{script_path} #{command}"
    r,w= IO.pipe
    pid= spawn({"RUBYLIB" => ruby_lib},
               full_command,
               {out: w, err: [:child, :out]})
    w.close

    _, exit_status= Process.wait2(pid)
    r.read
    r.close

    exit_status.exitstatus
  end

  it "a command that raises a Thor::Error exits with a status of 1" do
    expect(thor_command("error")).to eq(1)
  end

  it "a command that does not raise a Thor::Error exits with a status of 0" do
    expect(thor_command("ok")).to eq(0)
  end
end