运行rspec时失败/错误,没有将字符串隐式转换为哈希值

时间:2019-01-12 22:24:05

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

我刚刚安装了一个新的Rails应用,该应用本身运行正常,但是在运行时 rspec返回以下错误。我无法弄清楚这里出了什么问题。有人可以帮忙吗?所有测试都是从composer基本应用程序加载的,尚未更改。

$ rspec

An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

TypeError:
  no implicit conversion of String into Hash
# ./config/application.rb:10:in `<module:Smarthost>'
# ./config/application.rb:9:in `<top (required)>'
# ./config/environment.rb:2:in `require_relative'
# ./config/environment.rb:2:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `<top (required)>'

Application.rb :(第10行如下:“类Application

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Smarthost
  class Application < Rails::Application

    config.generators do |g|
      g.test_framework :rspec,
        fixtures: true,
        view_specs: false,
        helper_specs: false,
        routing_specs: false,
        controller_specs: false,
        request_specs: false
      g.fixture_replacement :factory_bot, dir: "spec/factories"
    end

    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
  end
end

使用rake --trace运行完整跟踪将返回以下内容,这表明figaro中存在错误。我还没有碰过那些文件。对可能是什么问题有任何想法吗?

rake aborted!
TypeError: no implicit conversion of String into Hash
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro/application.rb:32:in `merge'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro/application.rb:32:in `configuration'/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro/application.rb:42:in `each'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro/application.rb:36:in `load'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro.rb:23:in `load'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/figaro-1.1.1/lib/figaro/rails/railtie.rb:5:in `block in <class:Railtie>'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:95:in `inherited'
/mnt/c/Users/chave/Documents/apps/smarthost/config/application.rb:10:in `<module:Smarthost>'
/mnt/c/Users/chave/Documents/apps/smarthost/config/application.rb:9:in `<top (required)>'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/mnt/c/Users/chave/Documents/apps/smarthost/Rakefile:5:in `<top (required)>'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/rake_module.rb:29:in `load'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/rake_module.rb:29:in `load_rakefile'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:703:in `raw_load_rakefile'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:104:in `block in load_rakefile'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:103:in `load_rakefile'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:82:in `block in run'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
/home/achaves/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/home/achaves/.rbenv/versions/2.5.3/bin/rake:23:in `load'
/home/achaves/.rbenv/versions/2.5.3/bin/rake:23:in `<main>'

1 个答案:

答案 0 :(得分:0)

我最终通过重新安装figaro并在运行后将application.yml的旧内容复制到新创建的文件中来解决此问题:

bundle exec figaro install