Skip to content

Commit

Permalink
Merge pull request #977 from rajcybage/more_rspec_fix
Browse files Browse the repository at this point in the history
rspec refactor for ffi to use expect inspite of should to make it better
  • Loading branch information
BanzaiMan committed Sep 16, 2013
2 parents a37d562 + 80730f2 commit 815f778
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
30 changes: 15 additions & 15 deletions spec/ffi/buffer_spec.rb
Expand Up @@ -11,13 +11,13 @@
:float => 4, :double => 8
}.each_pair do |t, s|
it "Buffer.alloc_in(#{t}, #{i}).total == #{i * s}" do
Buffer.alloc_in(t, i).total.should == i * s
expect(Buffer.alloc_in(t, i).total).to eq(i * s)
end
it "Buffer.alloc_out(#{t}, #{i}).total == #{i * s}" do
Buffer.alloc_out(t, i).total.should == i * s
expect(Buffer.alloc_out(t, i).total).to eq(i * s)
end
it "Buffer.alloc_inout(#{t}, #{i}).total == #{i * s}" do
Buffer.alloc_inout(t, i).total.should == i * s
expect(Buffer.alloc_inout(t, i).total).to eq(i * s)
end
end
end
Expand All @@ -28,7 +28,7 @@
(0..127).each do |i|
(0..bufsize-1).each do |offset|
it "put_char(#{offset}, #{i}).get_char(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_char(offset, i).get_char(offset).should == i
expect(Buffer.alloc_in(bufsize).put_char(offset, i).get_char(offset)).to eq(i)
end
end
end
Expand All @@ -48,7 +48,7 @@
[0, 1, 128, 32767].each do |i|
(0..bufsize-2).each do |offset|
it "put_short(#{offset}, #{i}).get_short(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_short(offset, i).get_short(offset).should == i
expect(Buffer.alloc_in(bufsize).put_short(offset, i).get_short(offset)).to eq i
end
end
end
Expand All @@ -58,7 +58,7 @@
[ 0, 1, 128, 32767, 65535, 0xfee1, 0xdead, 0xbeef, 0xcafe ].each do |i|
(0..bufsize-2).each do |offset|
it "put_ushort(#{offset}, #{i}).get_ushort(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_ushort(offset, i).get_ushort(offset).should == i
expect(Buffer.alloc_in(bufsize).put_ushort(offset, i).get_ushort(offset)).to eq i
end
end
end
Expand All @@ -68,7 +68,7 @@
[0, 1, 128, 32767, 0x7ffffff ].each do |i|
(0..bufsize-4).each do |offset|
it "put_int(#{offset}, #{i}).get_int(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_int(offset, i).get_int(offset).should == i
expect(Buffer.alloc_in(bufsize).put_int(offset, i).get_int(offset)).to eq i
end
end
end
Expand All @@ -78,7 +78,7 @@
[ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i|
(0..bufsize-4).each do |offset|
it "put_uint(#{offset}, #{i}).get_uint(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_uint(offset, i).get_uint(offset).should == i
expect(Buffer.alloc_in(bufsize).put_uint(offset, i).get_uint(offset)).to eq i
end
end
end
Expand All @@ -88,7 +88,7 @@
[0, 1, 128, 32767, 0x7ffffff ].each do |i|
(0..bufsize-LongSize).each do |offset|
it "put_long(#{offset}, #{i}).get_long(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_long(offset, i).get_long(offset).should == i
expect(Buffer.alloc_in(bufsize).put_long(offset, i).get_long(offset)).to eq i
end
end
end
Expand All @@ -98,7 +98,7 @@
[ 0, 1, 128, 32767, 65535, 0xfee1dead, 0xcafebabe, 0xffffffff ].each do |i|
(0..bufsize-LongSize).each do |offset|
it "put_ulong(#{offset}, #{i}).get_ulong(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_ulong(offset, i).get_ulong(offset).should == i
expect(Buffer.alloc_in(bufsize).put_ulong(offset, i).get_ulong(offset)).to eq i
end
end
end
Expand All @@ -108,7 +108,7 @@
[0, 1, 128, 32767, 0x7ffffffffffffff ].each do |i|
(0..bufsize-8).each do |offset|
it "put_long_long(#{offset}, #{i}).get_long_long(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_long_long(offset, i).get_long_long(offset).should == i
expect(Buffer.alloc_in(bufsize).put_long_long(offset, i).get_long_long(offset)).to eq i
end
end
end
Expand All @@ -118,7 +118,7 @@
[ 0, 1, 128, 32767, 65535, 0xdeadcafebabe, 0x7fffffffffffffff ].each do |i|
(0..bufsize-8).each do |offset|
it "put_ulong_long(#{offset}, #{i}).get_ulong_long(#{offset}) == #{i}" do
Buffer.alloc_in(bufsize).put_ulong_long(offset, i).get_ulong_long(offset).should == i
expect(Buffer.alloc_in(bufsize).put_ulong_long(offset, i).get_ulong_long(offset)).to eq i
end
end
end
Expand All @@ -129,8 +129,8 @@
p.put_uint(0, 0xdeadbeef)
buf = Buffer.alloc_inout 8
p2 = buf.put_pointer(0, p).get_pointer(0)
p2.should_not be_nil
p2.should == p
p2.get_uint(0).should == 0xdeadbeef
expect(p2).to_not be_nil
expect(p2).to eq p
expect(p2.get_uint(0)).to eq 0xdeadbeef
end
end
4 changes: 2 additions & 2 deletions spec/ffi/io_spec.rb
Expand Up @@ -3,9 +3,9 @@
if false # disabled for #390
describe "FFI::IO.for_fd" do
it "produces an IO wrapping the specified file descriptor" do
lambda do
expect do
FFI::IO.for_fd(2, "r")
end.should_not raise_error
end.to_not raise_error
end
end
end
22 changes: 11 additions & 11 deletions spec/ffi/memorypointer_spec.rb
Expand Up @@ -5,19 +5,19 @@

describe "MemoryPointer#total" do
it "MemoryPointer.new(:char, 1).total == 1" do
MemoryPointer.new(:char, 1).total.should == 1
expect(MemoryPointer.new(:char, 1).total).to eq 1
end
it "MemoryPointer.new(:short, 1).total == 2" do
MemoryPointer.new(:short, 1).total.should == 2
expect(MemoryPointer.new(:short, 1).total).to eq 2
end
it "MemoryPointer.new(:int, 1).total == 4" do
MemoryPointer.new(:int, 1).total.should == 4
expect(MemoryPointer.new(:int, 1).total).to eq 4
end
it "MemoryPointer.new(:long_long, 1).total == 8" do
MemoryPointer.new(:long_long, 1).total.should == 8
expect(MemoryPointer.new(:long_long, 1).total).to eq 8
end
it "MemoryPointer.new(1024).total == 1024" do
MemoryPointer.new(1024).total.should == 1024
expect(MemoryPointer.new(1024).total).to eq 1024
end
end
describe "MemoryPointer#read_array_of_long" do
Expand All @@ -26,8 +26,8 @@
ptr[0].write_long 1234
ptr[1].write_long 5678
l = ptr.read_array_of_long(2)
l[0].should == 1234
l[1].should == 5678
expect(l[0]).to eq 1234
expect(l[1]).to eq 5678
end
end
describe "MemoryPointer argument" do
Expand All @@ -40,14 +40,14 @@ module Ptr
it "Pointer passed correctly" do
p = MemoryPointer.new :int, 1
ret = Ptr.memset(p, 0, p.total)
ret.should == p
expect(ret).to eq p
end
it "Data passed to native function" do
p = MemoryPointer.new :int, 1
p2 = MemoryPointer.new :int, 1
p2.put_int(0, 0xdeadbeef)
Ptr.memcpy(p, p2, p.total)
p.get_int(0).should == p2.get_int(0)
expect(p.get_int(0)).to eq p2.get_int(0)
end
end
describe "MemoryPointer return value" do
Expand All @@ -60,7 +60,7 @@ module Stdio
end
it "fopen returns non-nil" do
fp = Stdio.fopen("/dev/null", "w")
fp.should_not be_nil
Stdio.fclose(fp).should == 0 unless fp.nil? or fp.null?
expect(fp).to_not be_nil
expect(Stdio.fclose(fp)).to eq 0 unless fp.nil? or fp.null?
end
end

0 comments on commit 815f778

Please sign in to comment.