【发布时间】:2013-11-21 15:02:28
【问题描述】:
我有许多规格,我希望在 Rails 视图中使用它们 (v3.2.15)。
我使用的是rspec-rails gem v2.14.0,我运行的代码如下。
这段代码曾经在 gem 的 v2.11.4 上工作,我可以看到 HtmlFormatter 现在已经将它的一些代码拆分为 HtmlPrinter,我想这与错误有关。你打算如何使用HtmlFormatter?除了源代码之外,我找不到任何文档...我在下面做错了什么?
class RSpecRunner
attr_accessor :summary, :html, :documentation
SpecPath = "system_checks/**/*_spec.rb"
DataChecks = "data_checks/**/*_spec.rb"
def initialize(path)
@html = RSpec::Core::Formatters::HtmlFormatter.new(nil)
@documentation = RSpec::Core::Formatters::DocumentationFormatter.new(nil)
end
def run!
RSpec::world.reset
Dir[@spec_path].each { |f| load f }
@html = RSpec::Core::Formatters::HtmlFormatter.new(nil)
reporter = RSpec::Core::Reporter.new(@html)
RSpec::world.example_groups.each do |example_group|
example_group.run(reporter)
end
end
end
控制器
@sys_check = RSpecRunner.new(RSpecRunner::SystemChecksPath)
@sys_check.run!
查看
@sys_check.html.output.string
错误
NoMethodError: private method `puts' called for nil:NilClass
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/formatters/html_printer.rb:23:in `print_example_group_start'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/formatters/html_formatter.rb:50:in `example_group_started'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:127:in `block in notify'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:126:in `each'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:126:in `notify'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:74:in `example_group_started'
from /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:367:in `run'
from (irb):11:in `block in irb_binding'
from (irb):10:in `each'
from (irb):10
谢谢
【问题讨论】:
标签: ruby-on-rails rspec rspec2 rspec-rails