【问题标题】:Rails Activesupport error in rpectrpect 中的 Rails Activesupport 错误
【发布时间】:2015-10-28 00:50:59
【问题描述】:

我是 Ruby on Rails 的初学者。我正在关注 railstutorial.org 尝试进行测试,但我收到了与 activesupport 相关的错误。 我在优胜美地。我运行命令'rails generate integration_test static_pages'来生成static_pages,然后尝试运行TDD。我运行 'exec rspec spec/requests/static_pages_spec.rb' 并出现错误

/Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require': No such file to load -- test/unit/assertions (LoadError)
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/rspec-rails-2.13.1/lib/rspec/rails/adapters.rb:3:in `<top (required)>'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/rspec-rails-2.13.1/lib/rspec/rails.rb:11:in `<top (required)>'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:360:in `require_or_load'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:317:in `depend_on'
from /Users/pradeepkotwal1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:233:in `require_dependency'
from /Users/pradeepkotwal1/rails_projects/sample_app/spec/spec_helper.rb:4:in `<top (required)>'

你能帮帮我吗

【问题讨论】:

  • 您实际遵循的是什么教程?另外,你能告诉我/Users/pradeepkotwal1/rails_projects/sample_app/spec/spec_helper.rb的内容
  • 你的 spec_helper.rb 是什么样的?
  • 我删除了 cmets,现在它显示 ENV["RAILS_ENV"] ||= 'test' 需要 File.expand_path("../../config/environment", FILE) 需要 'rspec/rails' Dir[Rails.root.join("spec/support/**/*.rb")].each { |f|需要 f } ActiveRecord::Migration.check_pending!如果定义了?(ActiveRecord::Migration) RSpec.configure 做 |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = false config.order = "random" end

标签: ruby-on-rails ruby rspec


【解决方案1】:

你的 spec_helper.rb 应该是这样的,我不确定你是否粘贴错了:

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
  RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
    config.order = "random"
  end 

检查并重试。如果这不起作用,请尝试备份您的 Gemfile 并将其替换为:

https://github.com/railstutorial/sample_app_rails_4/blob/master/Gemfile

然后运行

bundle install

然后再试一次:

bundle exec rspec spec/requests/static_pages_spec.rb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    相关资源
    最近更新 更多