Even if your organization won't accept writing an application in Ruby, it would probably be easier to get the testing done in Ruby. And writing tests in an effective language means that you will either write more production code, or more tests. Either of those are a quite good outcome.
A quick example of this in action. To run this example, you need JRuby 1.0 or later, and the rspec gem:
require 'java'In this code the examples are not that realistic, but you can see that the RSpec code looks the same for Java code, as it does for Ruby code. Even the raise_error exception matcher works. You can run this:
describe java.util.ArrayList, " when first created" do
before(:each) do
@list = java.util.ArrayList.new
end
it "should be empty" do
@list.should be_empty
end
it "should be able to add an element" do
@list.add "content"
end
it "should raise exception when getting anything" do
lambda{ @list.get 0 }.should raise_error(java.lang.IndexOutOfBoundsException)
end
end
jruby -S spec -fs arraylist_spec.rb
The RBehave test suite also runs, which means you can stop using JBehave now... =)
This is a perfect example of the intersection where JRuby's approach can be very powerful, utilizing the existing Ruby libraries to benefit your Java programming.
Inga kommentarer:
Skicka en kommentar