【发布时间】:2019-01-12 22:24:05
【问题描述】:
我刚刚设置了一个新的 Rails 应用程序,该应用程序本身运行良好,但是在运行时 rspec 返回以下错误。我无法弄清楚这里出了什么问题。任何人都可以帮忙吗?所有测试都是从作曲家基础应用加载的,并且没有更改。
$ 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 行如下:“class 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>'
【问题讨论】:
-
发布您的
application.rb文件会很有帮助,如果您查看日志,application.rb的第 10 行似乎有错误 -
application.rb 以上编辑)。过去一个小时我一直在寻找它,但无法弄清楚那里出了什么问题。我的其他 Rails 应用程序看起来完全一样并且可以工作
标签: ruby-on-rails rspec devise rspec-rails