【问题标题】:no implicit conversion of nil into String in spec在规范中没有将 nil 隐式转换为 String
【发布时间】:2018-01-18 12:27:08
【问题描述】:

当我运行这个 Ruby 代码时出现错误:

require "rails"
let(:xml_file) { File.join(Rails.root, 'spec', 'fixtures', 'xml', 'sale.xml') }

结果:

失败/错误:let(:xml_file) { File.join(Rails.root, 'spec', 'fixtures', 'xml', 'sale.xml') }

 TypeError:
   no implicit conversion of nil into String

您知道这是导致此问题的原因吗?我该如何解决? xml文件存在于指定位置。

【问题讨论】:

  • 你确定 RailsRails.root 是在那个时候定义的吗?
  • 你在 Rails 应用程序中运行这个吗?

标签: ruby


【解决方案1】:

Rails.root 在没有项目时返回nil。确保在当前工作区中初始化项目。

http://edgeapi.rubyonrails.org/classes/Rails.html#method-c-root

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-14
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多