gir_ffi 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +16 -0
  3. data/README.md +24 -11
  4. data/TODO.md +10 -2
  5. data/gir_ffi.gemspec +2 -2
  6. data/lib/ffi-glib/array.rb +1 -1
  7. data/lib/ffi-glib/hash_table.rb +0 -4
  8. data/lib/ffi-gobject.rb +10 -6
  9. data/lib/ffi-gobject/object.rb +17 -0
  10. data/lib/ffi-gobject/ruby_closure.rb +1 -1
  11. data/lib/ffi-gobject/value.rb +28 -4
  12. data/lib/ffi-gobject_introspection.rb +4 -0
  13. data/lib/ffi-gobject_introspection/g_error.rb +2 -2
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +1 -3
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_registered_type_info.rb +2 -0
  17. data/lib/ffi-gobject_introspection/i_repository.rb +4 -4
  18. data/lib/ffi-gobject_introspection/lib.rb +57 -32
  19. data/lib/gir_ffi.rb +1 -1
  20. data/lib/gir_ffi/boxed_base.rb +40 -0
  21. data/lib/gir_ffi/builders/argument_builder.rb +11 -3
  22. data/lib/gir_ffi/builders/base_argument_builder.rb +4 -0
  23. data/lib/gir_ffi/builders/boxed_builder.rb +29 -0
  24. data/lib/gir_ffi/builders/callback_builder.rb +3 -1
  25. data/lib/gir_ffi/builders/callback_return_value_builder.rb +9 -1
  26. data/lib/gir_ffi/builders/field_builder.rb +68 -18
  27. data/lib/gir_ffi/builders/function_builder.rb +12 -2
  28. data/lib/gir_ffi/builders/mapping_method_builder.rb +7 -5
  29. data/lib/gir_ffi/builders/marshalling_method_builder.rb +1 -1
  30. data/lib/gir_ffi/builders/module_builder.rb +1 -1
  31. data/lib/gir_ffi/builders/registered_type_builder.rb +0 -9
  32. data/lib/gir_ffi/builders/return_value_builder.rb +0 -1
  33. data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -1
  34. data/lib/gir_ffi/builders/struct_builder.rb +4 -16
  35. data/lib/gir_ffi/builders/union_builder.rb +2 -13
  36. data/lib/gir_ffi/builders/user_defined_builder.rb +6 -6
  37. data/lib/gir_ffi/builders/vfunc_argument_builder.rb +44 -0
  38. data/lib/gir_ffi/builders/vfunc_builder.rb +3 -1
  39. data/lib/gir_ffi/callback_base.rb +5 -2
  40. data/lib/gir_ffi/class_base.rb +6 -7
  41. data/lib/gir_ffi/enum_base.rb +5 -0
  42. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
  43. data/lib/gir_ffi/field_argument_info.rb +4 -0
  44. data/lib/gir_ffi/in_out_pointer.rb +1 -1
  45. data/lib/gir_ffi/in_pointer.rb +2 -2
  46. data/lib/gir_ffi/info_ext/i_arg_info.rb +12 -2
  47. data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
  48. data/lib/gir_ffi/info_ext/i_callback_info.rb +7 -2
  49. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
  50. data/lib/gir_ffi/info_ext/i_function_info.rb +1 -1
  51. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +7 -2
  52. data/lib/gir_ffi/info_ext/i_type_info.rb +21 -9
  53. data/lib/gir_ffi/info_ext/i_unresolved_info.rb +5 -0
  54. data/lib/gir_ffi/interface_base.rb +5 -0
  55. data/lib/gir_ffi/object_base.rb +5 -0
  56. data/lib/gir_ffi/receiver_argument_info.rb +5 -0
  57. data/lib/gir_ffi/registered_type_base.rb +5 -0
  58. data/lib/gir_ffi/return_value_info.rb +3 -1
  59. data/lib/gir_ffi/sized_array.rb +1 -1
  60. data/lib/gir_ffi/struct_base.rb +2 -24
  61. data/lib/gir_ffi/type_map.rb +5 -1
  62. data/lib/gir_ffi/union_base.rb +2 -2
  63. data/lib/gir_ffi/version.rb +1 -1
  64. data/lib/gir_ffi/zero_terminated.rb +1 -1
  65. data/test/base_test_helper.rb +6 -6
  66. data/test/ffi-glib/hash_table_test.rb +7 -7
  67. data/test/ffi-glib/iconv_test.rb +2 -3
  68. data/test/ffi-glib/main_loop_test.rb +2 -2
  69. data/test/ffi-gobject/gobject_test.rb +1 -1
  70. data/test/ffi-gobject/object_test.rb +5 -14
  71. data/test/ffi-gobject/value_test.rb +30 -6
  72. data/test/ffi-gobject_introspection/i_base_info_test.rb +6 -6
  73. data/test/ffi-gobject_introspection/i_repository_test.rb +2 -4
  74. data/test/gir_ffi/arg_helper_test.rb +1 -1
  75. data/test/gir_ffi/builder_test.rb +18 -12
  76. data/test/gir_ffi/builders/argument_builder_test.rb +2 -5
  77. data/test/gir_ffi/builders/callback_builder_test.rb +1 -1
  78. data/test/gir_ffi/builders/callback_return_value_builder_test.rb +11 -10
  79. data/test/gir_ffi/builders/field_builder_test.rb +0 -2
  80. data/test/gir_ffi/builders/function_builder_test.rb +156 -147
  81. data/test/gir_ffi/builders/interface_builder_test.rb +1 -1
  82. data/test/gir_ffi/builders/module_builder_test.rb +2 -2
  83. data/test/gir_ffi/builders/object_builder_test.rb +2 -2
  84. data/test/gir_ffi/builders/property_builder_test.rb +5 -5
  85. data/test/gir_ffi/builders/return_value_builder_test.rb +30 -30
  86. data/test/gir_ffi/builders/struct_builder_test.rb +14 -14
  87. data/test/gir_ffi/builders/user_defined_builder_test.rb +21 -22
  88. data/test/gir_ffi/builders/vfunc_builder_test.rb +57 -0
  89. data/test/gir_ffi/class_base_test.rb +8 -8
  90. data/test/gir_ffi/ffi_ext/pointer_test.rb +4 -4
  91. data/test/gir_ffi/g_type_test.rb +1 -1
  92. data/test/gir_ffi/in_pointer_test.rb +2 -2
  93. data/test/gir_ffi/info_ext/i_callable_info_test.rb +3 -3
  94. data/test/gir_ffi/info_ext/i_callback_info_test.rb +2 -2
  95. data/test/gir_ffi/info_ext/i_field_info_test.rb +8 -8
  96. data/test/gir_ffi/info_ext/i_function_info_test.rb +13 -13
  97. data/test/gir_ffi/info_ext/i_type_info_test.rb +131 -132
  98. data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +2 -2
  99. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
  100. data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
  101. data/test/gir_ffi/interface_base_test.rb +3 -3
  102. data/test/gir_ffi/object_base_test.rb +3 -3
  103. data/test/gir_ffi/sized_array_test.rb +2 -2
  104. data/test/gir_ffi/type_map_test.rb +3 -3
  105. data/test/gir_ffi/unintrospectable_type_info_test.rb +14 -14
  106. data/test/gir_ffi/user_defined_property_info_test.rb +1 -1
  107. data/test/gir_ffi/user_defined_type_info_test.rb +25 -12
  108. data/test/gir_ffi/zero_terminated_test.rb +0 -1
  109. data/test/gir_ffi_test.rb +3 -3
  110. data/test/gir_ffi_test_helper.rb +4 -0
  111. data/test/integration/generated_gimarshallingtests_test.rb +31 -25
  112. data/test/integration/generated_gio_test.rb +1 -1
  113. data/test/integration/generated_gobject_test.rb +1 -1
  114. data/test/integration/generated_regress_test.rb +18 -22
  115. metadata +11 -8
@@ -55,14 +55,14 @@ describe GirFFI::ClassBase do
55
55
  end
56
56
 
57
57
  it 'returns false when comparing to an object of a different class and same pointer' do
58
- stub(other = Object.new).to_ptr { object.to_ptr }
58
+ allow(other = Object.new).to receive(:to_ptr).and_return object.to_ptr
59
59
 
60
60
  object.wont_be :==, other
61
61
  other.wont_be :==, object
62
62
  end
63
63
 
64
64
  it 'returns false when comparing to an object of a different class and different pointer' do
65
- stub(other = Object.new).to_ptr { FFI::MemoryPointer.new(:int32) }
65
+ allow(other = Object.new).to receive(:to_ptr).and_return FFI::MemoryPointer.new(:int32)
66
66
 
67
67
  object.wont_be :==, other
68
68
  other.wont_be :==, object
@@ -72,11 +72,11 @@ describe GirFFI::ClassBase do
72
72
 
73
73
  describe '.setup_and_call' do
74
74
  it 'looks up class methods in all builders' do
75
- mock(builder = Object.new).setup_method('foo') { 'foo' }
75
+ expect(builder = Object.new).to receive(:setup_method).with('foo').and_return 'foo'
76
76
  klass = Class.new GirFFI::ClassBase
77
77
  klass.const_set :GIR_FFI_BUILDER, builder
78
78
 
79
- mock(sub_builder = Object.new).setup_method('foo') { nil }
79
+ expect(sub_builder = Object.new).to receive(:setup_method).with('foo').and_return nil
80
80
  sub_klass = Class.new klass do
81
81
  def self.foo; end
82
82
  end
@@ -86,7 +86,7 @@ describe GirFFI::ClassBase do
86
86
  end
87
87
 
88
88
  it 'calls the method given by the result of .setup_method' do
89
- mock(builder = Object.new).setup_method('foo') { 'bar' }
89
+ expect(builder = Object.new).to receive(:setup_method).with('foo').and_return 'bar'
90
90
  klass = Class.new GirFFI::ClassBase do
91
91
  def self.bar
92
92
  'correct-result'
@@ -104,11 +104,11 @@ describe GirFFI::ClassBase do
104
104
 
105
105
  describe '#setup_and_call' do
106
106
  it 'looks up instance methods in all builders' do
107
- mock(builder = Object.new).setup_instance_method('foo') { 'foo' }
107
+ expect(builder = Object.new).to receive(:setup_instance_method).with('foo').and_return 'foo'
108
108
  klass = Class.new GirFFI::ClassBase
109
109
  klass.const_set :GIR_FFI_BUILDER, builder
110
110
 
111
- mock(sub_builder = Object.new).setup_instance_method('foo') { nil }
111
+ expect(sub_builder = Object.new).to receive(:setup_instance_method).with('foo').and_return nil
112
112
  sub_klass = Class.new klass do
113
113
  def foo; end
114
114
 
@@ -125,7 +125,7 @@ describe GirFFI::ClassBase do
125
125
  end
126
126
 
127
127
  it 'calls the method given by the result of .setup_instance_method' do
128
- mock(builder = Object.new).setup_instance_method('foo') { 'bar' }
128
+ expect(builder = Object.new).to receive(:setup_instance_method).with('foo').and_return 'bar'
129
129
  klass = Class.new GirFFI::ClassBase do
130
130
  def bar
131
131
  'correct-result'
@@ -5,12 +5,12 @@ describe GirFFI::FFIExt::Pointer do
5
5
  describe '#to_object' do
6
6
  it 'finds the wrapping class by gtype and wraps the pointer in it' do
7
7
  ptr = klass.new
8
- mock(ptr).null? { false }
8
+ expect(ptr).to receive(:null?).and_return false
9
9
  object_class = Class.new
10
10
 
11
- mock(GObject).type_from_instance_pointer(ptr) { 0xdeadbeef }
12
- mock(GirFFI::Builder).build_by_gtype(0xdeadbeef) { object_class }
13
- mock(object_class).direct_wrap(ptr) { 'good-result' }
11
+ expect(GObject).to receive(:type_from_instance_pointer).with(ptr).and_return 0xdeadbeef
12
+ expect(GirFFI::Builder).to receive(:build_by_gtype).with(0xdeadbeef).and_return object_class
13
+ expect(object_class).to receive(:direct_wrap).with(ptr).and_return 'good-result'
14
14
 
15
15
  ptr.to_object.must_equal 'good-result'
16
16
  end
@@ -3,7 +3,7 @@ require 'gir_ffi_test_helper'
3
3
  require 'gir_ffi/g_type'
4
4
 
5
5
  describe GirFFI::GType do
6
- let(:gobject_gtype) { GObject::Object.get_gtype }
6
+ let(:gobject_gtype) { GObject::Object.gtype }
7
7
  let(:gobject_type_query) { GObject.type_query gobject_gtype }
8
8
 
9
9
  describe '#to_i' do
@@ -16,7 +16,7 @@ describe GirFFI::InPointer do
16
16
  it 'handles enum types' do
17
17
  e = Module.new do
18
18
  extend GirFFI::EnumBase
19
- self::Enum = FFI::Enum.new [:foo, :bar, :baz]
19
+ self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
20
20
  end
21
21
  ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
22
22
  ptr.read_array_of_int32(3).must_equal [1, 0, 2]
@@ -146,7 +146,7 @@ describe GirFFI::InPointer do
146
146
 
147
147
  it 'handles enum types' do
148
148
  e = Module.new do
149
- self::Enum = FFI::Enum.new [:foo, :bar, :baz]
149
+ self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
150
150
  def self.[] val
151
151
  self::Enum[val]
152
152
  end
@@ -11,9 +11,9 @@ describe GirFFI::InfoExt::ICallableInfo do
11
11
  describe '#argument_ffi_types' do
12
12
  describe 'for a simple callable with several arguments' do
13
13
  before do
14
- stub(arg_info1 = Object.new).to_ffitype { :type1 }
15
- stub(arg_info2 = Object.new).to_ffitype { :type2 }
16
- stub(callable_info).args { [arg_info1, arg_info2] }
14
+ allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
15
+ allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
16
+ allow(callable_info).to receive(:args).and_return [arg_info1, arg_info2]
17
17
  end
18
18
 
19
19
  it 'returns the ffi types of the arguments' do
@@ -10,8 +10,8 @@ describe GirFFI::InfoExt::ICallbackInfo do
10
10
 
11
11
  describe '#return_ffi_type' do
12
12
  it 'returns the callback ffi type of the return type' do
13
- stub(return_type_info = Object.new).to_callback_ffitype { :some_type }
14
- stub(callback_info).return_type { return_type_info }
13
+ allow(return_type_info = Object.new).to receive(:to_callback_ffi_type).and_return :some_type
14
+ allow(callback_info).to receive(:return_type).and_return return_type_info
15
15
 
16
16
  callback_info.return_ffi_type.must_equal :some_type
17
17
  end
@@ -9,11 +9,11 @@ describe GirFFI::InfoExt::IFieldInfo do
9
9
  let(:field_info) { klass.new }
10
10
  describe '#layout_specification' do
11
11
  it 'returns an array of name, typespec and offset' do
12
- mock(type = Object.new).to_ffitype { :bar }
12
+ expect(type = Object.new).to receive(:to_ffi_type).and_return :bar
13
13
 
14
- mock(field_info).name { 'foo' }
15
- mock(field_info).field_type { type }
16
- mock(field_info).offset { 0 }
14
+ expect(field_info).to receive(:name).and_return 'foo'
15
+ expect(field_info).to receive(:field_type).and_return type
16
+ expect(field_info).to receive(:offset).and_return 0
17
17
 
18
18
  result = field_info.layout_specification
19
19
 
@@ -21,11 +21,11 @@ describe GirFFI::InfoExt::IFieldInfo do
21
21
  end
22
22
 
23
23
  it 'keeps a complex typespec intact' do
24
- mock(type = Object.new).to_ffitype { [:bar, 2] }
24
+ expect(type = Object.new).to receive(:to_ffi_type).and_return [:bar, 2]
25
25
 
26
- mock(field_info).name { 'foo' }
27
- mock(field_info).field_type { type }
28
- mock(field_info).offset { 0 }
26
+ expect(field_info).to receive(:name).and_return 'foo'
27
+ expect(field_info).to receive(:field_type).and_return type
28
+ expect(field_info).to receive(:offset).and_return 0
29
29
 
30
30
  result = field_info.layout_specification
31
31
 
@@ -11,15 +11,15 @@ describe GirFFI::InfoExt::IFunctionInfo do
11
11
 
12
12
  describe '#argument_ffi_types' do
13
13
  before do
14
- stub(arg_info1 = Object.new).to_ffitype { :type1 }
15
- stub(arg_info2 = Object.new).to_ffitype { :type2 }
16
- stub(function_info).args { [arg_info1, arg_info2] }
14
+ allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
15
+ allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
16
+ allow(function_info).to receive(:args).and_return [arg_info1, arg_info2]
17
17
  end
18
18
 
19
19
  describe 'for a simple function with several arguments' do
20
20
  before do
21
- stub(function_info).method? { false }
22
- stub(function_info).throws? { false }
21
+ allow(function_info).to receive(:method?).and_return false
22
+ allow(function_info).to receive(:throws?).and_return false
23
23
  end
24
24
 
25
25
  it 'returns the ffi types of the arguments' do
@@ -29,8 +29,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
29
29
 
30
30
  describe 'for a throwing function with several arguments' do
31
31
  before do
32
- stub(function_info).method? { false }
33
- stub(function_info).throws? { true }
32
+ allow(function_info).to receive(:method?).and_return false
33
+ allow(function_info).to receive(:throws?).and_return true
34
34
  end
35
35
 
36
36
  it 'appends :pointer to represent the error argument' do
@@ -40,8 +40,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
40
40
 
41
41
  describe 'for a method with several arguments' do
42
42
  before do
43
- stub(function_info).method? { true }
44
- stub(function_info).throws? { false }
43
+ allow(function_info).to receive(:method?).and_return true
44
+ allow(function_info).to receive(:throws?).and_return false
45
45
  end
46
46
 
47
47
  it 'prepends :pointer to represent the method reciever' do
@@ -51,8 +51,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
51
51
 
52
52
  describe 'for a throwing method with several arguments' do
53
53
  before do
54
- stub(function_info).method? { true }
55
- stub(function_info).throws? { true }
54
+ allow(function_info).to receive(:method?).and_return true
55
+ allow(function_info).to receive(:throws?).and_return true
56
56
  end
57
57
 
58
58
  it 'adds :pointer for both the reciever and the error argument' do
@@ -63,8 +63,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
63
63
 
64
64
  describe '#return_ffi_type' do
65
65
  it 'returns the ffi type of the return type' do
66
- stub(return_type_info = Object.new).to_ffitype { :some_type }
67
- stub(function_info).return_type { return_type_info }
66
+ allow(return_type_info = Object.new).to receive(:to_ffi_type).and_return :some_type
67
+ allow(function_info).to receive(:return_type).and_return return_type_info
68
68
 
69
69
  function_info.return_ffi_type.must_equal :some_type
70
70
  end
@@ -21,72 +21,72 @@ describe GirFFI::InfoExt::ITypeInfo do
21
21
  'test_ghash_nested_everything_return').return_type
22
22
  }
23
23
 
24
- describe '#to_ffitype' do
24
+ describe '#to_ffi_type' do
25
25
  it 'returns an array with elements subtype and size for type :array' do
26
- mock(type_info).pointer? { false }
27
- stub(type_info).tag { :array }
28
- mock(type_info).array_fixed_size { 2 }
26
+ expect(type_info).to receive(:pointer?).and_return false
27
+ allow(type_info).to receive(:tag).and_return :array
28
+ expect(type_info).to receive(:array_fixed_size).and_return 2
29
29
 
30
- mock(elmtype_info).to_ffitype { :foo }
31
- mock(type_info).param_type(0) { elmtype_info }
30
+ expect(elmtype_info).to receive(:to_ffi_type).and_return :foo
31
+ expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
32
32
 
33
- result = type_info.to_ffitype
33
+ result = type_info.to_ffi_type
34
34
  assert_equal [:foo, 2], result
35
35
  end
36
36
 
37
37
  describe 'for an :interface type' do
38
38
  before do
39
- stub(type_info).interface { iface_info }
40
- stub(type_info).tag { :interface }
41
- stub(type_info).pointer? { false }
39
+ allow(type_info).to receive(:interface).and_return iface_info
40
+ allow(type_info).to receive(:tag).and_return :interface
41
+ allow(type_info).to receive(:pointer?).and_return false
42
42
  end
43
43
 
44
- it "maps a the interface's ffitype" do
45
- stub(iface_info).to_ffitype { :foo }
44
+ it "maps a the interface's ffi_type" do
45
+ allow(iface_info).to receive(:to_ffi_type).and_return :foo
46
46
 
47
- type_info.to_ffitype.must_equal :foo
47
+ type_info.to_ffi_type.must_equal :foo
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
52
  describe '#element_type' do
53
53
  it 'returns the element type for lists' do
54
- stub(elmtype_info).tag { :foo }
55
- mock(elmtype_info).pointer? { false }
54
+ allow(elmtype_info).to receive(:tag).and_return :foo
55
+ expect(elmtype_info).to receive(:pointer?).and_return false
56
56
 
57
- mock(type_info).tag { :glist }
58
- mock(type_info).param_type(0) { elmtype_info }
57
+ expect(type_info).to receive(:tag).and_return :glist
58
+ expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
59
59
 
60
60
  result = type_info.element_type
61
61
  result.must_equal :foo
62
62
  end
63
63
 
64
64
  it 'returns the key and value types for ghashes' do
65
- stub(keytype_info).tag { :foo }
66
- mock(keytype_info).pointer? { false }
67
- stub(valtype_info).tag { :bar }
68
- mock(valtype_info).pointer? { false }
65
+ allow(keytype_info).to receive(:tag).and_return :foo
66
+ expect(keytype_info).to receive(:pointer?).and_return false
67
+ allow(valtype_info).to receive(:tag).and_return :bar
68
+ expect(valtype_info).to receive(:pointer?).and_return false
69
69
 
70
- mock(type_info).tag { :ghash }
71
- mock(type_info).param_type(0) { keytype_info }
72
- mock(type_info).param_type(1) { valtype_info }
70
+ expect(type_info).to receive(:tag).and_return :ghash
71
+ expect(type_info).to receive(:param_type).with(0).and_return keytype_info
72
+ expect(type_info).to receive(:param_type).with(1).and_return valtype_info
73
73
 
74
74
  result = type_info.element_type
75
75
  result.must_equal [:foo, :bar]
76
76
  end
77
77
 
78
78
  it 'returns nil for other types' do
79
- mock(type_info).tag { :foo }
79
+ expect(type_info).to receive(:tag).and_return :foo
80
80
 
81
81
  result = type_info.element_type
82
82
  result.must_be_nil
83
83
  end
84
84
 
85
85
  it 'returns [:pointer, :void] if the element type is a pointer with tag :void' do
86
- stub(elmtype_info).tag_or_class { [:pointer, :void] }
86
+ allow(elmtype_info).to receive(:tag_or_class).and_return [:pointer, :void]
87
87
 
88
- mock(type_info).tag { :glist }
89
- mock(type_info).param_type(0) { elmtype_info }
88
+ expect(type_info).to receive(:tag).and_return :glist
89
+ expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
90
90
 
91
91
  assert_equal [:pointer, :void], type_info.element_type
92
92
  end
@@ -95,7 +95,7 @@ describe GirFFI::InfoExt::ITypeInfo do
95
95
  describe '#flattened_tag' do
96
96
  describe 'for a simple type' do
97
97
  it 'returns the type tag' do
98
- stub(type_info).tag { :uint32 }
98
+ allow(type_info).to receive(:tag).and_return :uint32
99
99
 
100
100
  type_info.flattened_tag.must_equal :uint32
101
101
  end
@@ -103,15 +103,15 @@ describe GirFFI::InfoExt::ITypeInfo do
103
103
 
104
104
  describe 'for a zero-terminated array' do
105
105
  before do
106
- stub(type_info).tag { :array }
107
- stub(type_info).param_type(0) { elmtype_info }
108
- stub(type_info).zero_terminated? { true }
106
+ allow(type_info).to receive(:tag).and_return :array
107
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
108
+ allow(type_info).to receive(:zero_terminated?).and_return true
109
109
  end
110
110
 
111
111
  describe 'of utf8' do
112
112
  it 'returns :strv' do
113
- stub(elmtype_info).tag { :utf8 }
114
- stub(elmtype_info).pointer? { true }
113
+ allow(elmtype_info).to receive(:tag).and_return :utf8
114
+ allow(elmtype_info).to receive(:pointer?).and_return true
115
115
 
116
116
  type_info.flattened_tag.must_equal :strv
117
117
  end
@@ -119,8 +119,8 @@ describe GirFFI::InfoExt::ITypeInfo do
119
119
 
120
120
  describe 'of filename' do
121
121
  it 'returns :strv' do
122
- stub(elmtype_info).tag { :filename }
123
- stub(elmtype_info).pointer? { true }
122
+ allow(elmtype_info).to receive(:tag).and_return :filename
123
+ allow(elmtype_info).to receive(:pointer?).and_return true
124
124
 
125
125
  type_info.flattened_tag.must_equal :strv
126
126
  end
@@ -128,8 +128,8 @@ describe GirFFI::InfoExt::ITypeInfo do
128
128
 
129
129
  describe 'of another type' do
130
130
  it 'returns :zero_terminated' do
131
- stub(elmtype_info).tag { :foo }
132
- stub(elmtype_info).pointer? { false }
131
+ allow(elmtype_info).to receive(:tag).and_return :foo
132
+ allow(elmtype_info).to receive(:pointer?).and_return false
133
133
 
134
134
  type_info.flattened_tag.must_equal :zero_terminated
135
135
  end
@@ -138,9 +138,9 @@ describe GirFFI::InfoExt::ITypeInfo do
138
138
 
139
139
  describe 'for a fixed length c-like array' do
140
140
  it 'returns :c' do
141
- mock(type_info).tag { :array }
142
- mock(type_info).zero_terminated? { false }
143
- mock(type_info).array_type { :c }
141
+ expect(type_info).to receive(:tag).and_return :array
142
+ expect(type_info).to receive(:zero_terminated?).and_return false
143
+ expect(type_info).to receive(:array_type).and_return :c
144
144
 
145
145
  type_info.flattened_tag.must_equal :c
146
146
  end
@@ -148,9 +148,9 @@ describe GirFFI::InfoExt::ITypeInfo do
148
148
 
149
149
  describe 'for a GLib array' do
150
150
  it 'returns :c' do
151
- mock(type_info).tag { :array }
152
- mock(type_info).zero_terminated? { false }
153
- mock(type_info).array_type { :array }
151
+ expect(type_info).to receive(:tag).and_return :array
152
+ expect(type_info).to receive(:zero_terminated?).and_return false
153
+ expect(type_info).to receive(:array_type).and_return :array
154
154
 
155
155
  type_info.flattened_tag.must_equal :array
156
156
  end
@@ -160,8 +160,8 @@ describe GirFFI::InfoExt::ITypeInfo do
160
160
  describe '#tag_or_class' do
161
161
  describe 'for a simple type' do
162
162
  it "returns the type's tag" do
163
- stub(type_info).tag { :foo }
164
- mock(type_info).pointer? { false }
163
+ allow(type_info).to receive(:tag).and_return :foo
164
+ expect(type_info).to receive(:pointer?).and_return false
165
165
 
166
166
  type_info.tag_or_class.must_equal :foo
167
167
  end
@@ -169,8 +169,8 @@ describe GirFFI::InfoExt::ITypeInfo do
169
169
 
170
170
  describe 'for utf8 strings' do
171
171
  it 'returns the tag :utf8' do
172
- stub(type_info).tag { :utf8 }
173
- mock(type_info).pointer? { true }
172
+ allow(type_info).to receive(:tag).and_return :utf8
173
+ expect(type_info).to receive(:pointer?).and_return true
174
174
 
175
175
  type_info.tag_or_class.must_equal :utf8
176
176
  end
@@ -178,8 +178,8 @@ describe GirFFI::InfoExt::ITypeInfo do
178
178
 
179
179
  describe 'for filename strings' do
180
180
  it 'returns the tag :filename' do
181
- stub(type_info).tag { :filename }
182
- mock(type_info).pointer? { true }
181
+ allow(type_info).to receive(:tag).and_return :filename
182
+ expect(type_info).to receive(:pointer?).and_return true
183
183
 
184
184
  type_info.tag_or_class.must_equal :filename
185
185
  end
@@ -189,16 +189,16 @@ describe GirFFI::InfoExt::ITypeInfo do
189
189
  let(:interface) { Object.new }
190
190
 
191
191
  before do
192
- stub(type_info).tag { :interface }
193
- stub(type_info).interface { iface_info }
194
- mock(type_info).pointer? { false }
192
+ allow(type_info).to receive(:tag).and_return :interface
193
+ allow(type_info).to receive(:interface).and_return iface_info
194
+ expect(type_info).to receive(:pointer?).and_return false
195
195
 
196
- mock(GirFFI::Builder).build_class(iface_info) { interface }
196
+ expect(GirFFI::Builder).to receive(:build_class).with(iface_info).and_return interface
197
197
  end
198
198
 
199
199
  describe 'when the interface type is :enum' do
200
200
  it 'returns the built interface module' do
201
- stub(iface_info).info_type { :enum }
201
+ allow(iface_info).to receive(:info_type).and_return :enum
202
202
 
203
203
  type_info.tag_or_class.must_equal interface
204
204
  end
@@ -206,7 +206,7 @@ describe GirFFI::InfoExt::ITypeInfo do
206
206
 
207
207
  describe 'when the interface type is :object' do
208
208
  it 'returns the built interface class' do
209
- stub(iface_info).info_type { :object }
209
+ allow(iface_info).to receive(:info_type).and_return :object
210
210
 
211
211
  type_info.tag_or_class.must_equal interface
212
212
  end
@@ -214,12 +214,11 @@ describe GirFFI::InfoExt::ITypeInfo do
214
214
 
215
215
  describe 'when the interface type is :struct' do
216
216
  it 'returns the built interface class' do
217
- stub(iface_info).info_type { :struct }
217
+ allow(iface_info).to receive(:info_type).and_return :struct
218
218
 
219
219
  type_info.tag_or_class.must_equal interface
220
220
  end
221
221
  end
222
-
223
222
  end
224
223
 
225
224
  describe 'for a callback' do
@@ -230,8 +229,8 @@ describe GirFFI::InfoExt::ITypeInfo do
230
229
 
231
230
  describe 'for a pointer to simple type :foo' do
232
231
  it 'returns [:pointer, :foo]' do
233
- stub(type_info).tag { :foo }
234
- mock(type_info).pointer? { true }
232
+ allow(type_info).to receive(:tag).and_return :foo
233
+ expect(type_info).to receive(:pointer?).and_return true
235
234
 
236
235
  type_info.tag_or_class.must_equal [:pointer, :foo]
237
236
  end
@@ -239,8 +238,8 @@ describe GirFFI::InfoExt::ITypeInfo do
239
238
 
240
239
  describe 'for a pointer to :void' do
241
240
  it 'returns [:pointer, :void]' do
242
- stub(type_info).tag { :void }
243
- stub(type_info).pointer? { true }
241
+ allow(type_info).to receive(:tag).and_return :void
242
+ allow(type_info).to receive(:pointer?).and_return true
244
243
 
245
244
  type_info.tag_or_class.must_equal [:pointer, :void]
246
245
  end
@@ -258,24 +257,24 @@ describe GirFFI::InfoExt::ITypeInfo do
258
257
  end
259
258
  end
260
259
 
261
- describe '#to_callback_ffitype' do
260
+ describe '#to_callback_ffi_type' do
262
261
  describe 'for an :interface argument' do
263
262
  before do
264
- stub(type_info).interface { iface_info }
265
- stub(type_info).tag { :interface }
266
- stub(type_info).pointer? { false }
263
+ allow(type_info).to receive(:interface).and_return iface_info
264
+ allow(type_info).to receive(:tag).and_return :interface
265
+ allow(type_info).to receive(:pointer?).and_return false
267
266
  end
268
267
 
269
268
  it 'correctly maps a :union argument to :pointer' do
270
- stub(iface_info).info_type { :union }
269
+ allow(iface_info).to receive(:info_type).and_return :union
271
270
 
272
- type_info.to_callback_ffitype.must_equal :pointer
271
+ type_info.to_callback_ffi_type.must_equal :pointer
273
272
  end
274
273
 
275
274
  it 'correctly maps a :flags argument to :int32' do
276
- stub(iface_info).info_type { :flags }
275
+ allow(iface_info).to receive(:info_type).and_return :flags
277
276
 
278
- type_info.to_callback_ffitype.must_equal :int32
277
+ type_info.to_callback_ffi_type.must_equal :int32
279
278
  end
280
279
  end
281
280
  end
@@ -283,7 +282,7 @@ describe GirFFI::InfoExt::ITypeInfo do
283
282
  describe '#extra_conversion_arguments' do
284
283
  describe 'for normal types' do
285
284
  before do
286
- stub(type_info).tag { :foo }
285
+ allow(type_info).to receive(:tag).and_return :foo
287
286
  end
288
287
 
289
288
  it 'returns an empty array' do
@@ -293,7 +292,7 @@ describe GirFFI::InfoExt::ITypeInfo do
293
292
 
294
293
  describe 'for a string' do
295
294
  before do
296
- stub(type_info).tag { :utf8 }
295
+ allow(type_info).to receive(:tag).and_return :utf8
297
296
  end
298
297
 
299
298
  it 'returns an array containing :utf8' do
@@ -303,13 +302,13 @@ describe GirFFI::InfoExt::ITypeInfo do
303
302
 
304
303
  describe 'for a fixed-size array' do
305
304
  before do
306
- stub(type_info).tag { :array }
307
- stub(type_info).zero_terminated? { false }
308
- stub(type_info).array_type { :c }
309
- stub(type_info).array_fixed_size { 3 }
305
+ allow(type_info).to receive(:tag).and_return :array
306
+ allow(type_info).to receive(:zero_terminated?).and_return false
307
+ allow(type_info).to receive(:array_type).and_return :c
308
+ allow(type_info).to receive(:array_fixed_size).and_return 3
310
309
 
311
- stub(type_info).param_type(0) { elmtype_info }
312
- stub(elmtype_info).tag_or_class { :foo }
310
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
311
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
313
312
  end
314
313
 
315
314
  it 'returns an array containing the element type' do
@@ -319,11 +318,11 @@ describe GirFFI::InfoExt::ITypeInfo do
319
318
 
320
319
  describe 'for a zero-terminated array' do
321
320
  before do
322
- stub(type_info).tag { :array }
323
- stub(type_info).zero_terminated? { true }
321
+ allow(type_info).to receive(:tag).and_return :array
322
+ allow(type_info).to receive(:zero_terminated?).and_return true
324
323
 
325
- stub(type_info).param_type(0) { elmtype_info }
326
- stub(elmtype_info).tag_or_class { :foo }
324
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
325
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
327
326
  end
328
327
 
329
328
  it 'returns an array containing the element type' do
@@ -333,12 +332,12 @@ describe GirFFI::InfoExt::ITypeInfo do
333
332
 
334
333
  describe 'for a GArray' do
335
334
  before do
336
- stub(type_info).tag { :array }
337
- stub(type_info).zero_terminated? { false }
338
- stub(type_info).array_type { :array }
335
+ allow(type_info).to receive(:tag).and_return :array
336
+ allow(type_info).to receive(:zero_terminated?).and_return false
337
+ allow(type_info).to receive(:array_type).and_return :array
339
338
 
340
- stub(type_info).param_type(0) { elmtype_info }
341
- stub(elmtype_info).tag_or_class { :foo }
339
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
340
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
342
341
  end
343
342
 
344
343
  it 'returns an array containing the element type' do
@@ -348,12 +347,12 @@ describe GirFFI::InfoExt::ITypeInfo do
348
347
 
349
348
  describe 'for a GHashTable' do
350
349
  before do
351
- stub(type_info).tag { :ghash }
352
- stub(type_info).param_type(0) { keytype_info }
353
- stub(type_info).param_type(1) { valtype_info }
350
+ allow(type_info).to receive(:tag).and_return :ghash
351
+ allow(type_info).to receive(:param_type).with(0).and_return keytype_info
352
+ allow(type_info).to receive(:param_type).with(1).and_return valtype_info
354
353
 
355
- stub(keytype_info).tag_or_class { :foo }
356
- stub(valtype_info).tag_or_class { :bar }
354
+ allow(keytype_info).to receive(:tag_or_class).and_return :foo
355
+ allow(valtype_info).to receive(:tag_or_class).and_return :bar
357
356
  end
358
357
 
359
358
  it 'returns an array containing the element type pair' do
@@ -363,10 +362,10 @@ describe GirFFI::InfoExt::ITypeInfo do
363
362
 
364
363
  describe 'for a GList' do
365
364
  before do
366
- stub(type_info).tag { :glist }
365
+ allow(type_info).to receive(:tag).and_return :glist
367
366
 
368
- stub(type_info).param_type(0) { elmtype_info }
369
- stub(elmtype_info).tag_or_class { :foo }
367
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
368
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
370
369
  end
371
370
 
372
371
  it 'returns an array containing the element type' do
@@ -376,10 +375,10 @@ describe GirFFI::InfoExt::ITypeInfo do
376
375
 
377
376
  describe 'for a GSList' do
378
377
  before do
379
- stub(type_info).tag { :gslist }
378
+ allow(type_info).to receive(:tag).and_return :gslist
380
379
 
381
- stub(type_info).param_type(0) { elmtype_info }
382
- stub(elmtype_info).tag_or_class { :foo }
380
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
381
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
383
382
  end
384
383
 
385
384
  it 'returns an array containing the element type' do
@@ -389,12 +388,12 @@ describe GirFFI::InfoExt::ITypeInfo do
389
388
 
390
389
  describe 'for a GPtrArray' do
391
390
  before do
392
- stub(type_info).tag { :array }
393
- stub(type_info).zero_terminated? { false }
394
- stub(type_info).array_type { :ptr_array }
391
+ allow(type_info).to receive(:tag).and_return :array
392
+ allow(type_info).to receive(:zero_terminated?).and_return false
393
+ allow(type_info).to receive(:array_type).and_return :ptr_array
395
394
 
396
- stub(type_info).param_type(0) { elmtype_info }
397
- stub(elmtype_info).tag_or_class { :foo }
395
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
396
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
398
397
  end
399
398
 
400
399
  it 'returns an array containing the element type' do
@@ -404,11 +403,11 @@ describe GirFFI::InfoExt::ITypeInfo do
404
403
 
405
404
  describe 'for a :callback' do
406
405
  before do
407
- stub(interface_type_info = Object.new).namespace { 'Bar' }
408
- stub(interface_type_info).name { 'Foo' }
406
+ allow(interface_type_info = Object.new).to receive(:namespace).and_return 'Bar'
407
+ allow(interface_type_info).to receive(:name).and_return 'Foo'
409
408
 
410
- stub(type_info).tag { :callback }
411
- stub(type_info).interface { interface_type_info }
409
+ allow(type_info).to receive(:tag).and_return :callback
410
+ allow(type_info).to receive(:interface).and_return interface_type_info
412
411
  end
413
412
 
414
413
  it 'returns an empty array' do
@@ -419,7 +418,7 @@ describe GirFFI::InfoExt::ITypeInfo do
419
418
 
420
419
  describe '#argument_class_name' do
421
420
  before do
422
- stub(type_info).tag { tag }
421
+ allow(type_info).to receive(:tag).and_return tag
423
422
  end
424
423
 
425
424
  describe 'for :gint32' do
@@ -434,9 +433,9 @@ describe GirFFI::InfoExt::ITypeInfo do
434
433
  let(:tag) { :interface }
435
434
 
436
435
  before do
437
- stub(type_info).interface { iface_info }
438
- stub(iface_info).info_type { interface_type }
439
- stub(iface_info).full_type_name { 'Bar::Foo' }
436
+ allow(type_info).to receive(:interface).and_return iface_info
437
+ allow(iface_info).to receive(:info_type).and_return interface_type
438
+ allow(iface_info).to receive(:full_type_name).and_return 'Bar::Foo'
440
439
  end
441
440
 
442
441
  describe 'for :struct' do
@@ -489,13 +488,13 @@ describe GirFFI::InfoExt::ITypeInfo do
489
488
  describe 'for arrays' do
490
489
  let(:tag) { :array }
491
490
  before do
492
- stub(type_info).param_type(0) { elmtype_info }
493
- stub(elmtype_info).tag_or_class { :foo }
491
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
492
+ allow(elmtype_info).to receive(:tag_or_class).and_return :foo
494
493
  end
495
494
 
496
495
  describe 'for :zero_terminated' do
497
496
  before do
498
- stub(type_info).zero_terminated? { true }
497
+ allow(type_info).to receive(:zero_terminated?).and_return true
499
498
  end
500
499
 
501
500
  it 'equals GirFFI::ZeroTerminated' do
@@ -505,8 +504,8 @@ describe GirFFI::InfoExt::ITypeInfo do
505
504
 
506
505
  describe 'for :byte_array' do
507
506
  before do
508
- stub(type_info).zero_terminated? { false }
509
- stub(type_info).array_type { :byte_array }
507
+ allow(type_info).to receive(:zero_terminated?).and_return false
508
+ allow(type_info).to receive(:array_type).and_return :byte_array
510
509
  end
511
510
 
512
511
  it 'equals GLib::ByteArray' do
@@ -516,8 +515,8 @@ describe GirFFI::InfoExt::ITypeInfo do
516
515
 
517
516
  describe 'for :ptr_array' do
518
517
  before do
519
- stub(type_info).zero_terminated? { false }
520
- stub(type_info).array_type { :ptr_array }
518
+ allow(type_info).to receive(:zero_terminated?).and_return false
519
+ allow(type_info).to receive(:array_type).and_return :ptr_array
521
520
  end
522
521
 
523
522
  it 'equals GLib::PtrArray' do
@@ -527,8 +526,8 @@ describe GirFFI::InfoExt::ITypeInfo do
527
526
 
528
527
  describe 'for :array' do
529
528
  before do
530
- stub(type_info).zero_terminated? { false }
531
- stub(type_info).array_type { :array }
529
+ allow(type_info).to receive(:zero_terminated?).and_return false
530
+ allow(type_info).to receive(:array_type).and_return :array
532
531
  end
533
532
 
534
533
  it 'equals GLib::Array' do
@@ -572,8 +571,8 @@ describe GirFFI::InfoExt::ITypeInfo do
572
571
 
573
572
  describe '#g_type' do
574
573
  before do
575
- stub(type_info).tag { tag }
576
- stub(type_info).pointer? { pointer? }
574
+ allow(type_info).to receive(:tag).and_return tag
575
+ allow(type_info).to receive(:pointer?).and_return pointer?
577
576
  end
578
577
 
579
578
  describe 'for :void' do
@@ -645,8 +644,8 @@ describe GirFFI::InfoExt::ITypeInfo do
645
644
 
646
645
  describe 'for pointer to GArray' do
647
646
  before do
648
- stub(type_info).zero_terminated? { false }
649
- stub(type_info).array_type { :array }
647
+ allow(type_info).to receive(:zero_terminated?).and_return false
648
+ allow(type_info).to receive(:array_type).and_return :array
650
649
  end
651
650
 
652
651
  it 'equals the GArray type' do
@@ -656,8 +655,8 @@ describe GirFFI::InfoExt::ITypeInfo do
656
655
 
657
656
  describe 'for a C array' do
658
657
  before do
659
- stub(type_info).zero_terminated? { false }
660
- stub(type_info).array_type { :c }
658
+ allow(type_info).to receive(:zero_terminated?).and_return false
659
+ allow(type_info).to receive(:array_type).and_return :c
661
660
  end
662
661
 
663
662
  it 'equals the gpointer type' do
@@ -667,14 +666,14 @@ describe GirFFI::InfoExt::ITypeInfo do
667
666
 
668
667
  describe 'for a zero-terminated array' do
669
668
  before do
670
- stub(type_info).param_type(0) { elmtype_info }
671
- stub(type_info).zero_terminated? { true }
669
+ allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
670
+ allow(type_info).to receive(:zero_terminated?).and_return true
672
671
  end
673
672
 
674
673
  describe 'of utf8' do
675
674
  it 'equals the GStrv type' do
676
- stub(elmtype_info).tag { :utf8 }
677
- stub(elmtype_info).pointer? { true }
675
+ allow(elmtype_info).to receive(:tag).and_return :utf8
676
+ allow(elmtype_info).to receive(:pointer?).and_return true
678
677
 
679
678
  GObject.type_name(type_info.g_type).must_equal 'GStrv'
680
679
  end
@@ -682,8 +681,8 @@ describe GirFFI::InfoExt::ITypeInfo do
682
681
 
683
682
  describe 'of filename' do
684
683
  it 'equals the GStrv type' do
685
- stub(elmtype_info).tag { :filename }
686
- stub(elmtype_info).pointer? { true }
684
+ allow(elmtype_info).to receive(:tag).and_return :filename
685
+ allow(elmtype_info).to receive(:pointer?).and_return true
687
686
 
688
687
  GObject.type_name(type_info.g_type).must_equal 'GStrv'
689
688
  end