class Kicker::Recipes::Ruby
Attributes
Assigns the ruby command to run the tests with. Eg: `ruby19' or `specrb'.
This can be set from the command line with the `-b' or `–ruby' options.
Assigns the root directory of where test cases will be looked up.
Assigns the type of tests to run. Eg: `test' or `spec'.
The list of collected tests.
Public Class Methods
# File lib/kicker/recipes/ruby.rb, line 45 def reset! @test_type = nil @runner_bin = nil @test_cases_root = nil @test_options = nil end
Runs the given tests, if there are any, with the method defined by test_type. If test_type
is `test' the run_with_test_runner
method is used. The same applies when test_type
is `spec'.
# File lib/kicker/recipes/ruby.rb, line 66 def run_tests(tests) send("run_with_#{test_type}_runner", tests) unless tests.empty? end
Runs the given tests with `spec' as RSpec tests.
# File lib/kicker/recipes/ruby.rb, line 85 def run_with_spec_runner(tests) execute(spec_runner_command(tests)) end
Runs the given tests with `ruby' as unit-test tests.
# File lib/kicker/recipes/ruby.rb, line 76 def run_with_test_runner(tests) execute(test_runner_command(tests)) end
# File lib/kicker/recipes/ruby.rb, line 52 def runner_command(*parts) parts.map do |part| case part when Array part.empty? ? nil : part.join(' ') else part.to_s end end.compact.join(' ') end
# File lib/kicker/recipes/ruby.rb, line 80 def spec_runner_command(tests) runner_command(runner_bin, test_options, tests) end
Returns the root directory of where test cases will be looked up.
Defaults to the value of test_type. Eg: `test' or `spec'.
# File lib/kicker/recipes/ruby.rb, line 32 def test_cases_root @test_cases_root ||= test_type end
Assigns extra options that are to be passed on to the runner_bin.
Ruby.test_options << '-I ./lib/foo'
# File lib/kicker/recipes/ruby.rb, line 41 def test_options @test_options ||= [] end
# File lib/kicker/recipes/ruby.rb, line 70 def test_runner_command(tests) tests_without_ext = tests.map { |f| f[0,f.size-3] } runner_command(runner_bin, %w{ -I. } + test_options, '-r', tests_without_ext.join(' -r '), "-e ''") end
Returns the type of tests to run. Eg: `test' or `spec'.
Defaults to `test' if no `spec' directory exists.
# File lib/kicker/recipes/ruby.rb, line 9 def test_type @test_type ||= File.exist?('spec') ? 'spec' : 'test' end
Public Instance Methods
This method is called to collect tests. Override this if you're subclassing and make sure to call super
.
# File lib/kicker/recipes/ruby.rb, line 131 def handle! @tests.concat(@files.take_and_map do |file| case file # Match any ruby test file when /^#{test_cases_root}\/.+_#{test_type}\.rb$/ file # A file such as ./lib/namespace/foo.rb is mapped to: # * ./test/namespace/foo_test.rb # * ./test/foo_test.rb when /^lib\/(.+)\.rb$/ if namespaced = test_file($1) namespaced elsif in_test_root = test_file(File.basename(file, '.rb')) in_test_root end end end) end
A shortcut to Ruby.runner_bin
.
# File lib/kicker/recipes/ruby.rb, line 110 def runner_bin self.class.runner_bin end
A shortcut to Ruby.test_cases_root
.
# File lib/kicker/recipes/ruby.rb, line 115 def test_cases_root self.class.test_cases_root end
Returns the file for name
if it exists.
test_file('foo') # => "test/foo_test.rb" test_file('foo/bar') # => "test/foo/bar_test.rb" test_file('does/not/exist') # => nil
# File lib/kicker/recipes/ruby.rb, line 124 def test_file(name) file = File.join(test_cases_root, "#{name}_#{test_type}.rb") file if File.exist?(file) end
A shortcut to Ruby.test_type
.
# File lib/kicker/recipes/ruby.rb, line 105 def test_type self.class.test_type end