WickedPdf和Rails 5.1.4:无法实例化

时间:2017-10-16 15:39:27

标签: ruby-on-rails ruby rspec wicked-pdf

我想在Rails 5.1.4应用程序使用的ruby服务中生成PDF。它很快失败了。

class PdfRenderer
  require 'wicked_pdf'

  def self.generate
    WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
  end
end

当我在我的rspec测试中调用PdfRenderer.generate时,我收到了错误:

NoMethodError Exception: undefined method `pdf_from_string' for nil:NilClass

我无法实例化WickedPdf类。当我在byebug中致电WickedPdf.new时,我会得到nil

stacktrace:

NoMethodError:
   undefined method `pdf_from_string' for nil:NilClass
 # ./app/services/pdf_renderer.rb:25:in `generate'
 # ./spec/services/pdf_renderer_spec.rb:40:in `block (2 levels) in <top (required)>'
 # /usr/local/bundle/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/command_wrapper.rb:38:in `call'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:201:in `block in serve'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
 # /usr/local/bundle/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
 # -e:1:in `<main>'

0 个答案:

没有答案