【问题标题】:Using a rails engine in rspec在 rspec 中使用 rails 引擎
【发布时间】:2015-07-14 14:32:04
【问题描述】:

如何在规范测试中创建 Rails 引擎?我会用它来测试宝石。 这是我正在尝试的方法

module Zan
  class Engine < ::Rails::Engine
    isolate_namespace MyEngine
  end
end

我得到了

 Failure/Error: class Engine < ::Rails::Engine
 NameError:
   uninitialized constant Rails

我试过bundle exec rake spec,结果相同。

【问题讨论】:

    标签: ruby-on-rails ruby rspec rails-engines


    【解决方案1】:

    您需要添加 rails 作为 gem 的依赖项,并在 spec 帮助器中使用它:

    # your_gem.gemspec
    
    spec.add_development_dependency 'rails'
    
    
    # spec_helper.rb
    
    require 'rubygems'
    require 'bundler/setup'
    

    【讨论】:

      猜你喜欢
      • 2012-05-13
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      相关资源
      最近更新 更多