As we know, STAF is a fantastic test automation framework which supports Java, Python, C++ perfectly except Ruby. but there still a solution for this, in the following post, there is an interface for the original Ruby:
http://sourceforge.net/tracker/index.php?func=detail&aid=643842&group_id=33142&atid=407383
But while I’m trying to compile this library according to this post on Ubuntu, i got:
root@ubuntu:~/Downloads/rubystaf# ruby extconf.rb
checking for STAFRegister() in -lSTAF... no
creating Makefile
It because of missing the required libraries, so include the path to STAF installation path:
root@ubuntu:~/Downloads/rubystaf# ruby extconf.rb --with-staf-dir=/usr/local/staf/ --with-staf-lib=/usr/local/staf/lib
checking for STAFRegister() in -lSTAF... yes
creating Makefile
Then we can create the “Makefile” successfully
Next, run “make” to make the library, but some errors occur here
root@ubuntu:~/Downloads/rubystaf# make
gcc -I. -I/usr/local/ruby/include/ruby-1.9.1/i686-linux -I/usr/local/ruby/include/ruby-1.9.1/ruby/backward -I/usr/local/ruby/include/ruby-1.9.1 -I. -I/usr/local/staf//include -D_FILE_OFFSET_BITS=64 -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -o STAFHandle.o -c STAFHandle.c
STAFHandle.c: In function ‘sh_new’:
STAFHandle.c:74: error: ‘rb_get_argv’ declared as function returning an array
STAFHandle.c:74: error: conflicting types for ‘rb_get_argv’
/usr/local/ruby/include/ruby-1.9.1/ruby/intern.h:571: note: previous declaration of ‘rb_get_argv’ was here
STAFHandle.c:90: warning: initialization makes pointer from integer without a cast
STAFHandle.c:101: error: subscripted value is neither array nor pointer
STAFHandle.c:102: error: subscripted value is neither array nor pointer
STAFHandle.c: In function ‘sh_submit’:
STAFHandle.c:122: warning: assignment makes pointer from integer without a cast
STAFHandle.c:123: warning: assignment makes pointer from integer without a cast
STAFHandle.c:124: warning: assignment makes pointer from integer without a cast
make: *** [STAFHandle.o] Error 1
As we can see, there is a conflicting types in line 74, 101 and 102, because in ruby 1.9.x “rb_argv” was changed to “rb_get_argv”, so just rename the variant name from “rb_argv” to “rb_get_argv” and make again:
http://www.ruby-forum.com/topic/153426
root@ubuntu:~/Downloads/rubystaf# make
gcc -I. -I/usr/local/ruby/include/ruby-1.9.1/i686-linux -I/usr/local/ruby/include/ruby-1.9.1/ruby/backward -I/usr/local/ruby/include/ruby-1.9.1 -I. -I/usr/local/staf//include -D_FILE_OFFSET_BITS=64 -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -o STAFHandle.o -c STAFHandle.c
gcc -shared -o STAFHandle.so STAFHandle.o -L. -L/usr/local/ruby/lib -Wl,-R/usr/local/ruby/lib -L/usr/local/staf/lib -Wl,-R/usr/local/staf/lib -L/usr/local/staf//lib -Wl,-R/usr/local/staf//lib -L. -rdynamic -Wl,-export-dynamic -lSTAF -lpthread -lrt -ldl -lcrypt -lm -lc
After this step, we should see “STAFHandle.so” in the build path, now for using this library, just simply copy “STAFException.rb”, “STAFResult.rb” and “STAFHandle.so” under the directory named “staf”
For the testing, we can create a new ruby file and run the code below:
$LOAD_PATH << '.'
require 'STAFCommand.rb'
staf_result = STAF::STAFCommand.new 'local', 'ping', 'ping'
puts "STAF rc: #{staf_result.rc}"
puts "STAF result: #{staf_result.result}"
puts "Error message: #{staf_result.errorMsg}"
If no error come up, that means you have build the STAFHandle for Ruby properly~
NOTE:
If you are using Ruby 1.9.x, you will receive:
ruby: symbol lookup error: /root/Downloads/rubystaf/staf/STAFHandle.so: undefined symbol: STR2CSTR
It because STR2CSTR was deprecated in ruby 1.9.x, so we need to use StringValuePtr instead, so you need to open the ”STAFHandle.c” to replace all STR2CSTR and compile again
refer to: http://isitruby19.com/sqlite3-ruby