Monday, July 26, 2010


$ gem list gherkin cucumber
*** LOCAL GEMS ***
gherkin (2.2.0, 2.0.2)

$ gem install cucumber
ERROR: Error installing cucumber:
cucumber requires gherkin (~> 2.1.4, runtime)

The following command didn't work too
$gem install gherkin cucumber
You have to install gherkin 2.1.4 or 2.1.5 first.
$gem install gherkin --version 2.1.5

See "Specifying Versions" of RubyGems here

Thursday, July 22, 2010

Run cuke4duke from Eclipse

For a project using cuke4duke-maven-plugin, you can run integration test using Eclipse launcher, but you need to install the dependent packages into local repository. This is not convenient because you may change the dependent package in your workspace to make testes pass.

Just turn on "Resolve workspace artifacts" in "Run Configurations" dialog, and you don't have to install them.

Maven build without installing dependent packages in local repository

If you split your large project into several maven projects, and put them in sibling folders as follows:

+- parent
|
+- api
|
+- persistence
|
+- core

and core depends on api and persistence, while persistence depends on api. You can run maven command in parent/ to build them all without installing the packages into local maven repository:


parent $ mvn clean package

If you just want to build persistence, and you go to the folder core, then run maven, you will be asked to install api into repository. You can overcome this by running this command in parent folder:


parent $ mvn -o -am -pl groupId:core clean package

because all packages are in sibling folders, you may want to try this command:


parent $ mvn -o -am -pl ../core clean package

But this won't work and you may get an error message like "Couldn't find specified project in module list: M:\..\parent\..\core". Check this: MNG-4262.

Thursday, April 15, 2010

Debug Ruby Test::Unit::TestCase in Eclipse DLTK

It took me a while to figure out how to debug unit test using DLTK in eclipse.

Originally I tried to debug as "Ruby Test" and the breakpoints in unit test never worked, but it did stop in "rubygems.rb", you can step into the unit test file, but you cannot stop into a test method.

Because using "rdebug test-case.rb" did work in command line, I thought it might be something wrong with my gems. Tried to install a brand new ruby(mingw32 version) and install all gems ruby-debug and ruby-debug-ide. Unfortunately, it still didn't work.

Finally I found it is pretty ease to debug the unit test. The trick is "Debug as Ruby Script", you will stop at the breakpoint you set.

Wednesday, April 14, 2010

Install ibm_db on Ruby-mingw32

Here are the steps:

1. Install mingw compiled Ruby from http://rubyinstaller.org/download.html
2. Install Ruby Development Kit from http://rubyinstaller.org/download.html
3. follow the instruction of Development Kit
4. If you install IBM DB2 client in "c:\Program Files", you can do like this:

set IBM_DB_LIB=%ProgramFiles%/IBM/SQLLIB/LIB
set IBM_DB_INCLUDE=%ProgramFiles%/IBM/SQLLIB/INCLUDE
gem install ibm_db

Because there is a space in "Program Files", adding quotes or escaping the space like "\ " do not work for me.

Install ibm_db on Cygwin 1.7

Here is how to install ibm_db on Cygwin 1.7


bash-3.2$ export IBM_DB_INCLUDE=/cygdrive/c/Program\ Files/IBM/SQLLIB/include
bash-3.2$ export IBM_DB_LIB=/cygdrive/c/Program\ Files/IBM/SQLLIB/lib
bash-3.2$ gem install ibm_db

Tuesday, April 13, 2010

Compile ruby-odbc on Cygwin 1.7

The ruby-odbc gem won't compile in Cygwin 1.7 because the uft8 version failed.

You can solve this by run the followings in a shell
$ export cflags="-DHAVE_SQLCONFIGDATASOURCEW -DHAVE_SQLWRITEFILEDSNW -DHAVE_SQLREADFILEDSNW -DHAVE_SQLINSTALLERERROR -DHAVE_SQLINSTALLERERRORW"
$ gem install ruby-odbc
And you can also use this modified "extconf.rb"

require 'mkmf'

if ! defined? PLATFORM
PLATFORM = RUBY_PLATFORM
end

def have_library_ex(lib, func="main", headers=nil)
checking_for "#{func}() in -l#{lib}" do
libs = append_library($libs, lib)
if !func.nil? && !func.empty? && COMMON_LIBS.include?(lib)
true
elsif try_func(func, libs, headers)
$libs = libs
true
else
false
end
end
end

def try_func_nolink(func, libs, headers = nil, &b)
headers = cpp_include(headers)
try_compile(<<"SRC", libs, &b)
#{COMMON_HEADERS}
#{headers}
/*top*/
int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
SRC
end

def have_func_nolink(func, headers = nil, &b)
checking_for "#{func}()" do
if try_func_nolink(func, $libs, headers, &b)
$defs.push(format("-DHAVE_%s", func.upcase))
true
else
false
end
end
end

def headers(header)
if PLATFORM !~ /(mingw|cygwin)/ then
hdrs = header
else
hdrs = ["windows.h", header]
end
hdrs
end

def check_for_type(type)
begin
if defined? have_type
have_type(type, headers("sqltypes.h"))
else
throw
end
rescue
puts "WARNING: please check sqltypes.h for #{type} manually,"
puts "WARNING: if defined, modify CFLAGS in Makefile to contain"
puts "WARNING: the option -DHAVE_TYPE_#{type}"
end
end

dir_config("odbc")
have_header("sql.h") || begin
puts "ERROR: sql.h not found"
exit 1
end
have_header("sqlext.h") || begin
puts "ERROR: sqlext.h not found"
exit 1
end
testdlopen = enable_config("dlopen", true)

check_for_type("SQLTCHAR")
check_for_type("SQLLEN")
check_for_type("SQLULEN")

$have_odbcinst_h = have_header("odbcinst.h")

if PLATFORM =~ /mswin32/ then
if !have_library_ex("odbc32", "SQLAllocConnect", "sql.h") ||
!have_library_ex("odbccp32", "SQLConfigDataSource", "odbcinst.h") ||
!have_library_ex("odbccp32", "SQLInstallerError", "odbcinst.h") ||
!have_library("user32", "CharUpper") then
puts "Can not locate odbc libraries"
exit 1
end
have_func("SQLConfigDataSourceW", "odbcinst.h")
have_func("SQLWriteFileDSNW", "odbcinst.h")
have_func("SQLReadFileDSNW", "odbcinst.h")
have_func("SQLInstallerError", "odbcinst.h")
have_func("SQLInstallerErrorW", "odbcinst.h")
# mingw untested !!!
elsif PLATFORM =~ /(mingw|cygwin)/ then
have_library("odbc32", "")
have_library("odbccp32", "")
have_library("user32", "")
hdrs = headers("odbcinst.h")
have_func("SQLConfigDataSourceW", hdrs)
have_func("SQLWriteFileDSNW", hdrs)
have_func("SQLReadFileDSNW", hdrs)
have_func("SQLInstallerError", hdrs)
have_func("SQLInstallerErrorW", hdrs)
elsif (testdlopen && PLATFORM !~ /(macos|darwin)/ && CONFIG["CC"] =~ /gcc/ && have_func("dlopen", "dlfcn.h") && have_library("dl", "dlopen")) then
$LDFLAGS+=" -Wl,-init -Wl,ruby_odbc_init -Wl,-fini -Wl,ruby_odbc_fini"
$CPPFLAGS+=" -DHAVE_SQLCONFIGDATASOURCE"
$CPPFLAGS+=" -DHAVE_SQLINSTALLERERROR"
$CPPFLAGS+=" -DUSE_DLOPEN_FOR_ODBC_LIBS"
# but test the UNICODE installer functions w/o linking
# in case we need to provide fwd declarations
have_func_nolink("SQLConfigDataSourceW", "odbcinst.h")
have_func_nolink("SQLWriteFileDSNW", "odbcinst.h")
have_func_nolink("SQLReadFileDSNW", "odbcinst.h")
have_func_nolink("SQLInstallerErrorW", "odbcinst.h")
else
have_library("odbc", "SQLAllocConnect") ||
have_library("iodbc", "SQLAllocConnect")
($have_odbcinst_h &&
have_library("odbcinst", "SQLConfigDataSource")) ||
($have_odbcinst_h &&
have_library("iodbcinst", "SQLConfigDataSource"))
$have_odbcinst_h &&
have_func("SQLConfigDataSourceW", "odbcinst.h")
$have_odbcinst_h &&
have_func("SQLWriteFileDSNW", "odbcinst.h")
$have_odbcinst_h &&
have_func("SQLReadFileDSNW", "odbcinst.h")
$have_odbcinst_h &&
have_func("SQLInstallerError", "odbcinst.h")
$have_odbcinst_h &&
have_func("SQLInstallerErrorW", "odbcinst.h")
end

create_makefile("odbc_utf8")