Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6c8237f357f5
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1cbe0c5c2033
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Oct 4, 2014

  1. Copy the full SHA
    3d5e2fa View commit details
  2. Merge pull request #3154 from jemc/ffi_attach_specs

    Basic specs for Rubinius::FFI::Library#attach_function
    Yorick Peterse committed Oct 4, 2014
    Copy the full SHA
    1cbe0c5 View commit details
Showing with 43 additions and 1 deletion.
  1. +43 −1 spec/core/ffi/library/attach_function_spec.rb
44 changes: 43 additions & 1 deletion spec/core/ffi/library/attach_function_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'rubinius/ffi'

describe "FFI::Library#attach_function" do
describe "Rubinius::FFI::Library#attach_function" do
it "needs to be reviewed for spec completeness"

before :each do
@libc = Module.new
@libc.extend Rubinius::FFI::Library
@libc.ffi_lib Rubinius::FFI::Library::LIBC
end

it "creates a module method wrapping the function found in the ffi_lib" do
@libc.attach_function(:strlen, [:string], :int)
string = "a string to measure"
@libc.strlen(string).should == string.size
end

it "creates a module method with a different name if given" do
@libc.attach_function(:measure_a_string, :strlen, [:string], :int)
string = "a string to measure"
@libc.measure_a_string(string).should == string.size
end

it "raises Rubinius::FFI::NotFoundError if the function could not be found" do
lambda {
@libc.attach_function(:unknown_function, [], :void)
}.should raise_error Rubinius::FFI::NotFoundError
end

describe "the attached function module method" do
before :each do
@libc.attach_function(:strlen, [:string], :int)
end

it "raises TypeError if the wrong argument type is passed" do
lambda { @libc.strlen(88) }.should raise_error TypeError
end

it "raises ArgumentError if too many arguments are passed" do
lambda { @libc.strlen("foo", "bar") }.should raise_error ArgumentError
end

it "raises ArgumentError if too few arguments are passed" do
lambda { @libc.strlen() }.should raise_error ArgumentError
end
end
end