Sha256: 3286f865f136815e12739d0339a2ffeebf82a941954e10609541a1fee4fa8296

Contents?: true

Size: 850 Bytes

Versions: 4

Compression:

Stored size: 850 Bytes

Contents

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

RSpec.describe "Object#safe_send" do

  let(:string) { "Hiya, Cowboy!" }

  it "should return the method's return value, if no error is raised" do 
    result = string.safe_send(:upcase)
    expect(result).to eq "HIYA, COWBOY!"
  end

  it "should by default return nil, if an error is raised" do
    result = string.safe_send(:this_method_does_probably_not_exist)
    expect(result).to be_nil
  end

  it "should return the specified :return_value, if an error is raised" do
    result = string.safe_send(:this_method_does_probably_not_exist, return_value: :something_else)
    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_send.rb
eitil-1.2.3 spec/eitil_core/safe_executions/safe_send.rb
eitil-1.2.2 spec/eitil_core/safe_executions/safe_send.rb
eitil-1.2.1 spec/eitil_core/safe_executions/safe_send.rb