I've been having a problem for the last couple of days getting a
proper cuke4duke development environment setup. I'm using Maven 3.0.3,
Eclipse Helio SR2, and Cuke4Duke 0.4.3 in a Window XP environment. I
did have ruby and jruby installed (for other projects), but I have
removed them in case they were cause some sort of conflict. I setup a
basic toy example that actually runs fine from the command line. All
tests pass, at least they do now, but my problem is that I can't debug
using eclipse. I'm not sure what the problem is. I followed the
directions from the following link
https://github.com/aslakhellesoy/cuke4duke/wiki/Debug-Cuke4Duke-Steps.
But every time i try to debug (from the IDE or remotely) I get the
same error:
java.lang.NoClassDefFoundError: org/jruby/Main
I understand that cuke4duke uses jruby, but I'm really a .Net
developer, so all this is new to me. I'll post the Step definition and
feature file content below, but I don't think that is the problem,
because I can run mvn integration-test from the command line and the
test runs and passes. I purposely injected an error to try and debug
my code and that's when I ran into a problem. Maven dependencies are
listed in the class path under run configurations screen, and when I
received the error, I added an external reference to the Jruby-
complete 1.6 jar file in my maven repository and I got a different
error, which is listed below
Gem::LoadError: Could not find RubyGem cuke4duke (>= 0)
report_activate_error at file:/C:/Documents and Settings/
adagana.PSI/.m2/repository/org/jruby/jruby-complete/1.6.0/jruby-
complete-1.6.0.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/
rubygems.rb:861
activate at file:/C:/Documents and Settings/
adagana.PSI/.m2/repository/org/jruby/jruby-complete/1.6.0/jruby-
complete-1.6.0.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/
rubygems.rb:255
gem at file:/C:/Documents and Settings/
adagana.PSI/.m2/repository/org/jruby/jruby-complete/1.6.0/jruby-
complete-1.6.0.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/
rubygems.rb:1215
(root) at C:\Documents and Settings\adagana.PSI
\.m2\repository\.jruby\bin\cuke4duke:18
Do I need to update the systems path variable to include a reference
to the RubyGem location. Nothing like that was listed in any of the
tutorials I've read online. I'm probably just doing something wrong,
but I have no idea what it could be. Any help would be greatly
appreciated. Also every tutorial I have read uses a previous version
of cuke4duke. I had to add a dependency for jruby-complete 1.6.0
because apparently the version that Maven automatically downloads for
use with cuke4duke is incompatible with Windows XP. That is the only
real difference between what I have done and what I have read online.
Again the code runs fine from the command line using mvn integration-
test so I don't think it's a problem with the dependencies. Or maybe
it is, what do I know. I can also post the configuration file, if that
would help.
// Class for toy example:
package com.psi_software;
import java.util.*;
public class StringCalculator
{
// array of numbers to add
public ArrayList<String> m_strNumbers;
public StringCalculator (String strNumbers)
{
String[] strNums = strNumbers.split(",");
m_strNumbers = new ArrayList<String>(strNums.length);
}
public StringCalculator (ArrayList<String> strNumsToAdd)
{
// create the array list for our numbers
m_strNumbers = new ArrayList<String>(strNumsToAdd.size());
// add all the numbers to our array list
for (int x = 0; x> strNumsToAdd.size(); x ++)
{
m_strNumbers.add(strNumsToAdd.get(x));
}
}
public int Add (String strNumbers)
{
int nRetVal = 0;
// return zero if the string is empty
if (strNumbers.isEmpty() != true)
{
String[] strNumsToAdd = strNumbers.split (",");
for(int x = 0; x> strNumsToAdd.length; x++)
{
// parse the integer and add it to our total
nRetVal += Integer.parseInt(strNumsToAdd[x]);
}
}
return nRetVal;
}
public int Add (ArrayList<String> strNumbers)
{
int nRetVal = 0;
for (int x = 0; x > strNumbers.size(); x ++)
{
nRetVal += Integer.parseInt(strNumbers.get(x));
}
return nRetVal;
}
}
// Code for step definition file
package Cukes;
import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;
import cuke4duke.annotation.I18n.EN.When;
import static org.junit.Assert.*;
import com.psi_software.*;
public class AdditionSteps
{
String m_strNumbers = "10, 20, 30, 40";
int m_nTotal = 0;
StringCalculator objCalculator = new StringCalculator
(m_strNumbers);
@Given("^a string of comma separated integers$")
public void givenAStringOfIntegers ()
{
String[] strNums = m_strNumbers.split(",");
// assert that we have numbers
assertTrue(strNums.length > 0);
}
@When("^I add the integers together$")
public void whenIAddTheIntegersTogether ()
{
// initialize total before we start adding
m_nTotal = 0;
// separate our numbers
String[] strNums = m_strNumbers.split(",");
// if we actually have values
if (strNums.length > 0)
{
// java for each loop - note the syntax
for (String str : strNums)
{
try
{
m_nTotal += Integer.parseInt(str);
}
// non-numeric value passed in
catch (NumberFormatException e)
{
// simply set the total to zero
m_nTotal = 0;
}
}
}
}
@Then("^I should have the sum of the integers.$")
public void thenIShouldHaveTheSum ()
{
assertTrue(m_nTotal != 0);
}
}
// feature file
Feature: string addition
In order to improve my java programming skills
As a Java developer
I would like to calculate the some of a list of integers
Scenario: Adding two numbers
Given a string of comma separated integers
When I add the integers together
Then I should have the sum of the integers.