Class: Buildr::JtestR

Inherits:
TestFramework::JavaBDD
  • Object
show all
Includes:
TestFramework::JRubyBased
Defined in:
lib/buildr/java/bdd.rb

Overview

<a href=“jtestr.codehaus.org/”>JtestR</a> is a framework for BDD and TDD using JRuby and ruby tools. To test your project with JtestR use:

test.using :jtestr

Support the following options:

  • :config – path to JtestR config file. defaults to @spec/ruby/jtestr_config.rb@

  • :gems – A hash of gems to install before running the tests.

    The keys of this hash are the gem name, the value must be the required version.
    
  • :requires – A list of ruby files to require before running the specs

    Mainly used if an rspec format needs to require some file.
    
  • :format – A list of valid Rspec –format option values. (defaults to ‘progress’)

  • :output – File path to output dump. @false@ to supress output

  • :fork – Create a new JavaVM to run the tests on

  • :properties – Hash of properties passed to the test suite.

  • :java_args – Arguments passed to the JVM.

Constant Summary collapse

VERSION =
'0.3.1'
STORY_PATTERN =

pattern for rspec stories

/_(steps|story)\.rb$/
TESTUNIT_PATTERN =

pattern for test_unit files

/(_test|Test)\.rb$|(tc|ts)[^\\\/]+\.rb$/
EXPECT_PATTERN =

pattern for test files using expectations.rubyforge.org/

/_expect\.rb$/
TESTS_PATTERN =
[STORY_PATTERN, TESTUNIT_PATTERN, EXPECT_PATTERN] + RSpec::TESTS_PATTERN

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TestFramework::JRubyBased

included, jruby_artifact, #jruby_home, #jruby_installed?, #run

Constructor Details

#initialize(task, options) ⇒ JtestR

:nodoc:



340
341
342
343
344
345
346
347
348
# File 'lib/buildr/java/bdd.rb', line 340

def initialize(task, options) #:nodoc:
  super
  [:test, :spec].each do |usage|
    java_tests = task.project.path_to(:source, usage, :java)
    task.compile.from java_tests if File.directory?(java_tests)
    resources = task.project.path_to(:source, usage, :resources)
    task.resources.from resources if File.directory?(resources)
  end
end

Class Method Details

.applies_to?(project) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


325
326
327
328
329
# File 'lib/buildr/java/bdd.rb', line 325

def applies_to?(project) #:nodoc:
  File.exist?(project.path_to(:source, bdd_dir, lang, 'jtestr_config.rb')) ||
    Dir[project.path_to(:source, bdd_dir, lang, '**/*.rb')].any? { |f| TESTS_PATTERN.any? { |r| r === f } } ||
    JUnit.applies_to?(project) || TestNG.applies_to?(project)
end

.dependenciesObject



320
321
322
323
# File 'lib/buildr/java/bdd.rb', line 320

def dependencies
  @dependencies ||= Array(super) + ["org.jtestr:jtestr:jar:#{version}"] +
    JUnit.dependencies + TestNG.dependencies
end

.versionObject



316
317
318
# File 'lib/buildr/java/bdd.rb', line 316

def version
  Buildr.settings.build['jtestr'] || VERSION
end

Instance Method Details

#runner_configObject



369
370
371
372
373
374
375
# File 'lib/buildr/java/bdd.rb', line 369

def runner_config
  runner = super
  # JtestR 0.3.1 comes with rspec 1.1.4 (and any other jtestr dependency) included, 
  # so the rspec version used depends on the jtestr jar.
  runner.requires.unshift 'jtestr'
  runner
end

#runner_content(binding) ⇒ Object



377
378
379
380
# File 'lib/buildr/java/bdd.rb', line 377

def runner_content(binding)
  runner_erb = File.join(File.dirname(__FILE__), 'jtestr_runner.rb.erb')
  Filter::Mapper.new(:erb, binding).transform(File.read(runner_erb), runner_erb)
end

#tests(dependencies) ⇒ Object

:nodoc:



354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/buildr/java/bdd.rb', line 354

def tests(dependencies) #:nodoc:
  dependencies |= [task.compile.target.to_s]
  types = { :story => STORY_PATTERN, :rspec => RSpec::TESTS_PATTERN,
            :testunit => TESTUNIT_PATTERN, :expect => EXPECT_PATTERN }
  tests = types.keys.inject({}) { |h, k| h[k] = []; h }
  tests[:junit] = JUnit.new(task, {}).tests(dependencies)
  tests[:testng] = TestNG.new(task, {}).tests(dependencies)
  Dir[task.project.path_to(:source, bdd_dir, lang, '**/*.rb')].each do |rb|
    type = types.find { |k, v| Array(v).any? { |r| r === rb } }
    tests[type.first] << rb if type
  end
  @jtestr_tests = tests
  tests.values.flatten
end

#user_configObject



350
351
352
# File 'lib/buildr/java/bdd.rb', line 350

def user_config
  options[:config] || task.project.path_to(:source, bdd_dir, lang, 'jtestr_config.rb')
end