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)


232
233
234
# File 'lib/buildr/java/bdd.rb', line 232

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

Instance Method Details

#runner_configObject



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

def runner_config
  runner = super
  runner.gems.update 'rspec' => '~> 2.1.0'
  runner.requires.unshift 'rspec'
  runner
end

#runner_content(binding) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/buildr/java/bdd.rb', line 250

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 = ::RSpec::Core::Parser.new
    argv = <%= runner.rspec.inspect %> || []
    argv.push *<%= tests.inspect %>

    Buildr::TestFramework::TestResult::Error.guard('<%= runner.result %>') do
      ::RSpec::Core::CommandLine.new(argv).run(output, output)
    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:



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

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