【问题标题】:Unable to generate rspec in rails project, "uninitialized constant RSpec (NameError) is thrown"无法在 rails 项目中生成 rspec,“抛出未初始化的常量 RSpec (NameError)”
【发布时间】:2014-12-05 13:20:04
【问题描述】:
>: rails generate rspec:install
/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb:1:in `<top (required)>': uninitialized constant RSpec (NameError)
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec/formatter.rb:1:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec/formatter.rb:1:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec.rb:3:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec.rb:3:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /Users/prashanth_sams/Desktop/MAC/blog/config/application.rb:7:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.16/lib/rails/commands.rb:24:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.16/lib/rails/commands.rb:24:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我在终端中尝试了以下 cmd

bundle exec rails generate rspec:install

但没有运气:(

将以下内容放在我的 Gemfile 中

group :test, :development do
  gem 'rspec-rails', '~> 3.1.0'
end

【问题讨论】:

  • 常数是Rspec 我相信
  • 嗨! @Малъ Скрылевъ 这个问题有解决办法吗?
  • 您使用哪些导轨?

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


【解决方案1】:

可能是rspec的版本不兼容:降级rspec的版本或者直接写:

gem 'rspec-rails'

然后你可以更新它:

bundle update rspec-rails 

【讨论】:

    【解决方案2】:

    我可以创建 spec 文件夹和 spec_helper.rb 使用

    rspec --init

    【讨论】:

      猜你喜欢
      • 2013-11-10
      • 2023-04-02
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      相关资源
      最近更新 更多