Sha256: 687db8c4b3e4702d8e2f198ebe1370af59a1406170ae7871072134d1d9ed6e63

Contents?: true

Size: 1020 Bytes

Versions: 6

Compression:

Stored size: 1020 Bytes

Contents

# backtick_javascript: true

describe "Exit (Kernel#exit / Opal.exit())" do
  it "forwards the status code to Opal.exit(status)" do
    received_status { Kernel.exit }.should == 0

    received_status { Kernel.exit(0) }.should == 0
    received_status { Kernel.exit(1) }.should == 1
    received_status { Kernel.exit(2) }.should == 2
    received_status { Kernel.exit(123) }.should == 123

    received_status { Kernel.exit(true) }.should == 0
    received_status { Kernel.exit(false) }.should == 1

    lambda { received_status { Kernel.exit(Object.new) } }.should raise_error(TypeError)
    lambda { received_status { Kernel.exit([]) } }.should raise_error(TypeError)
    lambda { received_status { Kernel.exit(/123/) } }.should raise_error(TypeError)
  end

  def received_status
    received_status = nil
    original_exit = `Opal.exit`
    begin
      `Opal.exit = function(status) { #{received_status = `status`} }`
      yield
    ensure
      `Opal.exit = #{original_exit}`
    end
    received_status
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/core/runtime/exit_spec.rb
opal-1.8.2 spec/opal/core/runtime/exit_spec.rb
opal-1.8.1 spec/opal/core/runtime/exit_spec.rb
opal-1.8.0 spec/opal/core/runtime/exit_spec.rb
opal-1.8.0.beta1 spec/opal/core/runtime/exit_spec.rb
opal-1.8.0.alpha1 spec/opal/core/runtime/exit_spec.rb