buildr with rails application

64 Views Asked by At

I have a project with four modules. All the modules are java based except one that's a rails application.

In order to automate the build process I'm using buildr. I'd like to run rails tests using "buildr test" (same way I execute the java tests), but I can't figure out how to execute the rake task available in the rails project.

Any idea how to do this?

2

There are 2 best solutions below

0
On

In your project definition for the rails module, you could do something like:

test do
  exec "bin/rails test"
end
0
On

There is a few ways to do this and it depends on how "integrated" you want to get. Typically we have our rails applications also report test results out via ci_reporter so can be picked up by jenkins. One of our projects uses code itest.rb by a snippet like

workspace_dir = File.expand_path(File.dirname(__FILE__) + '/..')

require File.expand_path("#{workspace_dir}/lib/itest.rb")

ITest::Config.reports_dir = "#{workspace_dir}/target/reports"
ITest::Config.scripts_dir = "#{workspace_dir}/target"
ITest::TestTask.new('models', FileList["#{workspace_dir}/test/unit/**/*_test.rb"])
ITest::TestTask.new('controllers', FileList["#{workspace_dir}/test/functional/**/*_test.rb"])

def add_tests_task(project, task_name)
  project.test do
    begin
      task(task_name).invoke
    rescue
      raise unless Buildr.options.test == :all
    end
  end
end

And then in our buildfile we add something like

project 'myproject' do
  ...
  add_tests_task(project, 'test:models')
  add_tests_task(project, 'test:controllers')
end

Hope that helps!