From e70b13d6ef20351541649532d6705bac0acec170 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sat, 2 Jun 2018 14:44:52 +0200 Subject: [PATCH] Fix integer parameter range specs They raised NoMethodError before, but this issue was hidden by raise_error without class argument. I think the intension was here, that integer parameters out of range can either raise a RangeError or are truncated to the integer size. This is what the test verifies now. --- spec/ffi/number_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/ffi/number_spec.rb b/spec/ffi/number_spec.rb index acb956226..ed091d4f5 100644 --- a/spec/ffi/number_spec.rb +++ b/spec/ffi/number_spec.rb @@ -145,32 +145,32 @@ module LibTest describe "Integer parameter range checking" do [ 128, -129 ].each do |i| it ":char call(:char (#{i}))" do - expect { expect(LibTest.ret_int8_t(i)).to eq(i) }.to raise_error + expect { expect(LibTest.ret_s8(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end [ -1, 256 ].each do |i| it ":uchar call(:uchar (#{i}))" do - expect { expect(LibTest.ret_u_int8_t(i)).to eq(i) }.to raise_error + expect { expect(LibTest.ret_u8(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end [ 0x8000, -0x8001 ].each do |i| it ":short call(:short (#{i}))" do - expect { expect(LibTest.ret_int16_t(i)).to eq(i) }.to raise_error + expect { expect(LibTest.ret_s16(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end [ -1, 0x10000 ].each do |i| it ":ushort call(:ushort (#{i}))" do - expect { expect(LibTest.ret_u_int16_t(i)).to eq(i) }.to raise_error + expect { expect(LibTest.ret_u16(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end [ 0x80000000, -0x80000001 ].each do |i| it ":int call(:int (#{i}))" do - expect { expect(LibTest.ret_int32_t(i)).to eq(i) }.to raise_error + expect { expect(LibTest.ret_s32(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end [ -1, 0x100000000 ].each do |i| - it ":ushort call(:ushort (#{i}))" do - expect { expect(LibTest.ret_u_int32_t(i)).to eq(i) }.to raise_error + it ":uint call(:uint (#{i}))" do + expect { expect(LibTest.ret_u32(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) } end end end