Sha256: 4a91680777a098d3aa18e8010d37c45017939f3c953193edb11a6a27bd056f39

Contents?: true

Size: 784 Bytes

Versions: 4

Compression:

Stored size: 784 Bytes

Contents

# For some reason, the Kernel patches – which ruby mixes into Object – are not
# available to the tests, therefore load the file manually.
load (Eitil::Root + "/eitil_core/lib/eitil_core/safe_executions/safe_call.rb")

RSpec.describe "Object#safe_call" do

  it "should return the block's yield value, if no error is raised" do
    result = Object.new.safe_call { 1 + 1 }
    expect(result).to eq 2
  end

  it "should by default return nil, if an error is raised" do
    result = Object.new.safe_call { raise(StandardError) }
    expect(result).to be_nil
  end

  it "should return the specified :return_value, if an error is raised" do
    result = Object.new.safe_call(return_value: :something_else) { raise(StandardError) }
    expect(result).to eq :something_else
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eitil-1.2.4 spec/eitil_core/safe_executions/safe_call.rb
eitil-1.2.3 spec/eitil_core/safe_executions/safe_call.rb
eitil-1.2.2 spec/eitil_core/safe_executions/safe_call.rb
eitil-1.2.1 spec/eitil_core/safe_executions/safe_call.rb