Class: Buildr::RSpec

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

Overview

<a href=“rspec.info”>RSpec</a> is the defacto BDD framework for ruby. To test your project with RSpec use:

test.using :rspec

Support the following options:

  • :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 suppress 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

TESTS_PATTERN =
[ /_spec.rb$/ ]
OPTIONS =
[:properties, :java_args]

Constants included from TestFramework::JRubyBased

TestFramework::JRubyBased::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TestFramework::JRubyBased

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

Class Method Details

.applies_to?(project) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


239
240
241
# File 'lib/buildr/java/bdd.rb', line 239

def self.applies_to?(project) #:nodoc:
  !Dir[project.path_to(:source, bdd_dir, lang, '**/*_spec.rb')].empty?
end

Instance Method Details

#runner_configObject



250
251
252
253
254
255
# File 'lib/buildr/java/bdd.rb', line 250

def runner_config
  runner = super
  runner.gems.update 'rspec' => '>0'
  runner.requires.unshift 'spec'
  runner
end

#runner_content(binding) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/buildr/java/bdd.rb', line 257

def runner_content(binding)
  runner_erb = %q{
    <%= jruby_gem %>
    <%= dependencies.inspect %>.each { |dep| $CLASSPATH << dep }
    <%= runner.gems.inspect %>.each { |ary| JRuby.gem(*ary.flatten) }
    <%= runner.requires.inspect %>.each { |rb| Kernel.require rb }
    <% if runner.output == false %>
      output = StringIO.new
    <% elsif runner.output.kind_of?(String) %>
      output = File.open(<%= result.output.inspect %>, 'w')
    <% else %>
      output = STDOUT
    <% end %>
    parser = ::Spec::Runner::OptionParser.new(output, output)
    argv = <%= runner.rspec.inspect %> || []
    argv.push *<%= tests.inspect %>
    parser.order!(argv)
    $rspec_options = parser.options

    Buildr::TestFramework::TestResult::Error.guard('<%= runner.result %>') do
      ::Spec::Runner::CommandLine.run($rspec_options)
    end
    exit 0 # let buildr figure the result from the yaml file
  }
  Filter::Mapper.new(:erb, binding).transform(runner_erb)
end

#tests(dependencies) ⇒ Object

:nodoc:



243
244
245
246
247
248
# File 'lib/buildr/java/bdd.rb', line 243

def tests(dependencies) #:nodoc:
  Dir[task.project.path_to(:source, bdd_dir, lang, '**/*_spec.rb')].select do |name|
    selector = ENV['SPEC']
    selector.nil? || Regexp.new(selector) === name
  end
end