【问题标题】:Problems running Rake rspec task with ci_reporter使用 ci_reporter 运行 Rake rspec 任务时出现问题
【发布时间】:2012-03-12 20:48:26
【问题描述】:

我正在尝试将 rake 配置为使用 ci_reporter for Hudson 从 rspec 生成报告。

使用下面的 rake 文件,使用 spec 命令运行时通过的相同测试无法使用新的 rake 文件运行。首先有很多警告(我省略了,因为它们太多而无法显示)。

似乎 ci_reporter 正在生成报告,但它们是空的。

任何帮助将不胜感激!

谢谢! -劳拉

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/packagetask'
require 'spec/version'
require 'spec/rake/spectask'
require 'rcov'
require 'tasks/rails'
gem 'ci_reporter'
require 'ci/reporter/rake/rspec'

def rspec_report_path
    "reports/rspec/"
end

namespace :ci do
    task :pre_ci do
        ENV["CI_REPORTS"] = rspec_report_path
        gem 'ci_reporter'
    require 'ci/reporter/rake/rspec'
end

  task :rspec => [:pre_ci, "ci:setup:rspec"]
  desc "do rspec tests and test coverage"

  @suite = Spec::Rake::SpecTask.new('rspec') do |t|
      # t.spec_files = FileList['spec/**/*_spec.rb']
      t.spec_files = FileList['spec/models/assignment_spec.rb']
      t.warning = true
      t.rcov = false
      t.rcov_dir = 'coverage'
      t.fail_on_error = false
      t.rcov_opts = ['--exclude', "kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,^spec/*,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}", '-I', 'lib/']
    end
end

错误:

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/whiny_nil.rb:52:in `method_missing': undefined method `metadata' for nil:NilClass (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:46:in `name'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:146
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:140:in `each'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:140
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:136:in `to_xml'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:86
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:85:in `each'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:85
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:84:in `to_xml'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:18:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:17:in `open'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:17:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:203:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:207:in `new_suite'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:114:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:19:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:18:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:18:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:115:in `notify'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:96:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:23:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:22:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:22:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/options.rb:153:in `run_examples'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner.rb:61:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner.rb:45
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/whiny_nil.rb:52:in `method_missing': undefined method `metadata' for nil:NilClass (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:46:in `name'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:146
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:140:in `each'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:140
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:136:in `to_xml'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:86
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:85:in `each'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:85
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `call'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:134:in `_nested_structures'
    from /usr/lib/ruby/gems/1.8/gems/builder-2.1.2/lib/builder/xmlbase.rb:58:in `method_missing'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/test_suite.rb:84:in `to_xml'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:18:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:17:in `open'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/report_manager.rb:17:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:203:in `write_report'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:207:in `new_suite'
    from /usr/lib/ruby/gems/1.8/gems/ci_reporter-1.7.0/lib/ci/reporter/rspec.rb:114:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:19:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:18:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/reporter.rb:18:in `example_group_started'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:115:in `notify'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:96:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:23:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:22:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/example_group_runner.rb:22:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/options.rb:153:in `run_examples'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/command_line.rb:9:in `run'
    from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/bin/spec:5
    from /usr/bin/rcov:508:in `load'
    from /usr/bin/rcov:508 
Recording test results 

【问题讨论】:

    标签: ruby-on-rails ruby rspec rake


    【解决方案1】:

    例外是 ci_reporter 中的一个错误,该错误已于 2012 年 2 月 21 日修复(请参阅 https://github.com/nicksieger/ci_reporter/commit/48d7389f19bace8e7765d889bcd4425e3aab699b),但该修复不属于 2012 年 4 月 26 日的任何已发布版本。在发布之前的解决方案是获取 gem来自 github。如果您使用的是捆绑程序,请将您的 Gemfile 条目更改为:

    gem 'ci_reporter', :git => 'git://github.com/nicksieger/ci_reporter.git'
    

    【讨论】:

    • 您能解释一下为什么这可以解决问题吗?我可以从错误中看到调用metadata 的对象为nil,但为什么呢?从该文件中的代码看来,对象@exception 应该在范围内,那么为什么不将其设置为非零值呢?
    • 哦,没关系,我现在看到了。我正在阅读 @example 作为 @exception - 我的阅读很糟糕。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 2018-06-21
    • 2010-11-02
    • 1970-01-01
    • 2015-11-29
    相关资源
    最近更新 更多