天天看點

organize rspec2 tests into 'unit' (fast) and 'integration' (slow) categories

I wish I can use these under commands to run the tests.

rake spec                    # run all tests
rake spec:integration  # run all integration tests
rake spec:unit            # run all unit tests
           

So that's what I do in my Rakefile:

def run_test(scope)
  RSpec::Core::RakeTask.new(scope) do |t|
    t.rspec_opts = %w{--colour --format progress}
    t.pattern = "spec/#{scope.to_s}/**/*_spec.rb"
  end
end

namespace :spec do
  ENV['RACK_ENV'] = 'test'

  desc "run all unit tests"
  run_test(:unit)

  desc "run all integration tests"
  run_test(:integration)

end

desc "run all tests"
task :spec => ["spec:unit", "spec:integration"]