未初始化的恒定设计RSPEC

时间:2014-06-13 03:29:17

标签: ruby-on-rails ruby unit-testing rspec devise

我在RSpec和Capybara上使用Rails 4应用程序。

我的gemfile看起来像:

source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'pg'
gem 'devise'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'turbolinks'
gem "rspec-rails", :group => [:test, :development]
group :test do 
  gem "factory_girl_rails", "~> 4.0"
  gem "capybara"
  gem "guard-rspec"
end

我的spec_helper.rb文件如下:

require "capybara/rspec"
include Capybara::DSL

RSpec.configure do |config|
   config.include Devise::TestHelpers, :type => :controller
   config.extend ControllerMacros, :type => :controller
end

但由于某种原因,我收到错误:uninitialized constant Devise (NameError) 。在我的应用程序中,Devise正常工作,我在spec / support中有ControllerMacros文件。

1 个答案:

答案 0 :(得分:8)

试试这个:

你的spec_helper应该像

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment",__FILE__)
require 'rspec/rails'
require "capybara/rspec"
include Capybara::DSL

RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
end