spec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require File.dirname(__FILE__) + '/spec_helper.rb'

context "Ruby C array functions" do
  setup do
    declare do |vars|
      vars :VALUE, :ary
  end
  
  specify "rb_ary_new should create a new array of default size" do
    %(
    VALUE ary = rb_ary_new();
    assert_type(ary, VALUE);
    assert (rb_ary_size(ary), 16)
    )
  end

  specify "rb_ary_new should create a new array of default size" do
    decl VALUE, ary
    ary = spec.rb_ary_new
    spec.declare :VALUE, :ary
    spec.call(:rb_ary_new).should be_equal(int 16)
  end
  
  specify "rb_ary_new should create a new array of default size" do
    declare :VALUE, :ary
    declare :int, :size => 2
    
    assign ary, call.rb_ary_new2(size)
    ary.should_not be_nil
    call.rb_ary_size(ary).should be_equal(16)
  end


  specify "rb_ary_new2 should create a new array of the specified size" do
    declare :ary, :VALUE
    declare :size, :int
    
    size = 100
    ary = call.rb_ary_new2(size)
    ary.should_not be_nil
    call.rb_ary_size(ary).should == size
  end
  
  
  specify "rb_some_func should receive a foo structure and return something" do
    declare :size => int, :field1 => double, :field2 => char(5)
  end
end

C file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "cspec.h"

void context_one_context_setup(void) {
	...
}

void context_one_context_teardown(void) {
	...
}

void context_one_setup(void) {
	...
}

void context_one_teardown(void) {
	...
}

void context_one(ContextRunner *runner) {
	context_one_setup();
	cspec_context_runner()
	context_one_teardown();
}

void test_context_one_test_one(void) {
	
	...
}

void test_context_one_test_one(void) {
	...
}


int main(int argc, char *argv[]) {
	cspec_runner(argc, argv);
}