Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 希望使用RAILS_ENV=production进行种子设定,但获取名称错误:未初始化常量RSpec::Core_Ruby On Rails_Ruby_Rspec_Seeding - Fatal编程技术网

Ruby on rails 希望使用RAILS_ENV=production进行种子设定,但获取名称错误:未初始化常量RSpec::Core

Ruby on rails 希望使用RAILS_ENV=production进行种子设定,但获取名称错误:未初始化常量RSpec::Core,ruby-on-rails,ruby,rspec,seeding,Ruby On Rails,Ruby,Rspec,Seeding,我有以下Rakefile: require File.expand_path('../config/application', __FILE__) A4aa2::Application.load_tasks if defined? RSpec task(:default).clear task default: :'spec:fuubar' namespace :spec do desc 'Run all specs in spec directory (with Fuu

我有以下Rakefile:

require File.expand_path('../config/application', __FILE__)
A4aa2::Application.load_tasks

if defined? RSpec
  task(:default).clear
  task default: :'spec:fuubar'

  namespace :spec do
    desc 'Run all specs in spec directory (with Fuubar formatter)'
    RSpec::Core::RakeTask.new(:fuubar) do |task|
      task.rspec_opts = [task.rspec_opts.to_s, '--color --format Fuubar'].compact.join ' '
    end
  end
end
我正在显式检查
是否已定义?RSpec
,但这并不能防止以下错误:

rake db:seed RAILS_ENV=production --trace
rake aborted!
NameError: uninitialized constant RSpec::Core
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/Rakefile:13:in `block in <top (required)>'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/task_manager.rb:209:in `in_namespace'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/dsl_definition.rb:147:in `namespace'
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/Rakefile:11:in `<top (required)>'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:689:in `raw_load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:77:in `block in run'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/bin/rake:4:in `<main>'

我不想将RSpec放入
:production
组,这就是我检查
RSpec
是否在
Rakefile
中定义的原因,但它似乎是
RSpec
:production
中定义的(尽管我只是在
:development
:test
组中加载它),而
RSpec::Core
不是。

确保
gem RSpec
Gemfile
中的
:test
组中

rspec在
之外时:测试
组:

> puts "RSpec defined" if defined? RSpec
RSpec defined
 => nil 
> puts "RSpec defined" if defined? RSpec
 => nil 
内部带有rspec
:测试组:

> puts "RSpec defined" if defined? RSpec
RSpec defined
 => nil 
> puts "RSpec defined" if defined? RSpec
 => nil 

您可以通过检查适当的环境来完全避免此问题,例如,
除非Rails.env.production?

您可以使用--trace添加/共享错误日志吗?您是否使用“gem'spork”,github'sporkrb/spork'进行了检查在您的gem文件中?这与spork有什么关系?rspec gem是否在您的gem文件中的测试组中?