我有一些規格,我希望在Rails視圖(v3.2.15)中使用。如何使用HtmlFormatter運行RSpec?獲得「私人方法」放'所謂nil:NilClass「
我使用的是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
謝謝
謝謝,但我想存儲在一個attr_accessor的HTML,所以我可以打印它在一個視圖,發送它在電子郵件等等等等更新問題,以顯示完整的代碼。感謝您的回覆 – rwb
我會編輯我的答案,爲您的案例展示解決方案。 – DiegoSalazar
這看起來很棒。現在將有一個遊戲,並回到你身邊。非常感謝您的幫助 – rwb