我有一个rails应用程序并在VPS上运行,Ruby,Rails和RSpec的安装步骤在我的笔记本电脑和VPS上是相同的(后面是same instruction)。
但是当我想要的时候要在VPS上使用RSpec测试应用程序,它会出现uninitialized constant
错误(类似this)。项目的确切克隆运行完美,笔记本电脑没有任何错误!
虽然测试在我的笔记本电脑上执行没有任何问题,但我尝试在网上存在解决方案,但对我没有帮助 - 甚至我在服务器上重新安装了Ruby,Rails和RSpec!
我需要提一下,该应用程序通过网络(应用程序是一个网站)在服务器上运行完美,没有任何问题。这肯定是RSpec问题;不是Ruby或Rails。
确切的错误输出如下:
Traceback (most recent call last):
32: from /home/user/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
31: from /home/user/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
30: from /home/user/.rvm/gems/ruby-2.5.0/bin/rspec:23:in `<main>'
29: from /home/user/.rvm/gems/ruby-2.5.0/bin/rspec:23:in `load'
28: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
27: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
26: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
25: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:86:in `run'
24: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:99:in `setup'
23: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:21:in `configure'
22: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
21: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:111:in `each'
20: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
19: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `requires='
18: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `each'
17: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `block in requires='
16: from /home/user/.rvm/gems/ruby-2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `require'
15: from /var/www/www.site.com/spec/rails_helper.rb:17:in `<top (required)>'
14: from /var/www/www.site.com/spec/rails_helper.rb:17:in `each'
13: from /var/www/www.site.com/spec/rails_helper.rb:19:in `block in <top (required)>'
12: from /var/www/www.site.com/spec/rails_helper.rb:19:in `each'
11: from /var/www/www.site.com/spec/rails_helper.rb:19:in `block (2 levels) in <top (required)>'
10: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
9: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
8: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
7: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
6: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
5: from /var/www/www.site.com/spec/support/helpers/api.rb:1:in `<main>'
4: from /var/www/www.site.com/spec/support/helpers/api.rb:2:in `<module:APIHelper>'
3: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:42:in `load_missing_constant'
2: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `rescue in load_missing_constant'
1: from /home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
/home/user/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant': uninitialized constant APIHelper::AuthHelper (NameError)
要点:
`block in load_missing_constant': uninitialized constant APIHelper::AuthHelper (NameError)
答案 0 :(得分:2)
RSpec
有什么问题?
RSpec
没有任何问题。
我该如何解决这个问题?
您不应该在生产中运行测试套件。工具集中的不同工具有许多步骤可以阻止您这样做(如隐式环境变量设置。)如果您仍然肯定要远程运行测试(您不应该这样做),那么应该使用明确的环境设置可能有帮助:
RAILS_ENV=test bundle install
RAILS_ENV=test bundle exec rspec