rspec testing throws Uninitialized constant Rails (NameError)

后端 未结 2 1137
天命终不由人
天命终不由人 2021-01-13 11:20

Please forgive any shortcomings in this (my first-ever) post on StackOverflow. I\'m brand new to Ruby on Rails. I\'m following the Rails Tutorial. I have spent many unsucces

相关标签:
2条回答
  • 2021-01-13 11:59

    Remove redundant require 'spec_helper' line from your spec_helper.rb file.

    0 讨论(0)
  • In your spec_helper.rb, you have the following line twice:

    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
    

    Delete the first instance (the one on line 2). This is what is causing the error. Having this line before require 'rspec/rails' will cause problems because we don't know what Rails is, and so we cannot call the root method. The second instance (on line 13) is fine because this is after require 'rspec/rails'.

    0 讨论(0)
提交回复
热议问题