0

在我的 Rakefile 中,我有一个这样定义的任务:

namespace :test do
  desc "Run all specs."
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.pattern = 'spec/**/*_spec.rb'
    t.verbose = false
  end

  RSpec::Core::RakeTask.new(:coverage) do |t|
    t.rcov = true
    t.rcov_opts =  %q[--exclude "spec"]
    t.verbose = true
  end
end

运行 test:coverage 时,我得到以下信息:

./spec/foo_spec.rb:3: undefined method `describe' for main:Object (NoMethodError)
    from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516:in `load'
    from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516
    from /usr/bin/rcov:19:in `load'
    from /usr/bin/rcov:19
rake aborted!
ruby -S rcov -Ispec:lib --exclude "spec" "./spec/foo_spec.rb" failed

在我的宝石列表下方:

diff-lcs (1.1.2)
rake (0.8.7)
rcov (0.9.9)
rspec (2.3.0)
rspec-core (2.3.1)
rspec-expectations (2.3.0)
rspec-mocks (2.3.0)

任何的想法?提前致谢。

4

1 回答 1

0

解决方案,来自 David Chelimsky:
http: //rubyforge.org/pipermail/rspec-users/2010-December/019077.html

require "rspec"

干杯。

于 2011-01-01T14:04:14.820 回答