简体   繁体   English

在RSpec中使用Rails引擎

[英]Using a rails engine in rspec

How can I create a rails engine inside of a spec test? 如何在规格测试中创建Rails引擎? I would be using it to test a gem. 我会用它来测试宝石。 Here is what I am trying 这是我正在尝试的

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

and I am getting 而我得到

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

I've tried bundle exec rake spec with the same result. 我试过bundle exec rake spec具有相同的结果。

You need to add rails as a dependency of the gem, and require it in the spec helper: 您需要添加rails作为gem的依赖项,并在spec帮助器中要求它:

# your_gem.gemspec

spec.add_development_dependency 'rails'


# spec_helper.rb

require 'rubygems'
require 'bundler/setup'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM