2

我正在写一个 gem,我想为它写很多测试,这是常态。我遵循了一些指南并得出以下结论:

耙文件

require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new do |t|
  t.libs << 'test'
end

desc "Run tests"
task :default => :test

测试/settings_test.rb

require "test/unit"
require "cohabit"

class SettingsTest < Test::Unit::TestCase

  def test_thing
    assert(false)
  end

end

具有以下项目结构:

- cohabit
  - lib
    - cohabit
      - ...
    cohabit.rb
  - test
    settings_test.rb

我运行时得到以下信息rake test --trace

mbp4:cohabit mike.campbell$ rake test --trace
** Invoke test (first_time)
** Execute test
mbp4:cohabit mike.campbell$

rake -T

mbp4:cohabit mike.campbell$ rake -T
rake build    # Build cohabit-0.0.1.gem into the pkg directory.
rake default  # Run tests
rake install  # Build and install cohabit-0.0.1.gem into system gems.
rake release  # Create tag v0.0.1 and build and push cohabit-0.0.1.gem to R...
rake test     # Run tests

任何想法为什么我的测试似乎没有运行?我确定我可能错过了一些愚蠢的东西。

编辑 - 更改 Rakefile 和输出现在是:

mbp4:cohabit mike.campbell$ rake test --trace
** Invoke test (first_time)
** Execute test
/Users/mike.campbell/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -I"lib:test" -I"/Users/mike.campbell/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.4/lib" "/Users/mike.campbell/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" 
4

1 回答 1

3

试试这个: -

在您的测试 Rakefile 中将您的代码更新为此

require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['test/*_test.rb']
  t.verbose = true
end

desc "Run tests"
task :default => :test

我自己在自己的 gem 中实现并测试了它

https://github.com/sachin87/week-of-month/blob/master/Rakefile

要为 rake 任务添加更多参数,请阅读

http://rake.rubyforge.org/classes/Rake/TestTask.html

于 2013-07-29T15:47:03.273 回答