rspec“无法加载此类文件”

时间:2013-01-02 23:06:57

标签: rspec railstutorial.org

第一次使用Rails教程运行rspec,p。 95。 获得此输出:

    david@david-desktop:~/rails_projects/sample_app1$ bundle exec rspec /spec/requests/static_pages_spec.rb
/home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load': cannot load such file -- /spec/requests/static_pages_spec.rb (LoadError)
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
    from /home/david/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2nded/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'

这是Gemfile:

    source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.9.0'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby
end

gem 'jquery-rails'

group :test do
  gem 'capybara', '1.1.2'
end

已经完成了rails生成rspec:install和 rails生成integration_test static_pages命令。想法?

3 个答案:

答案 0 :(得分:11)

删除文件名中的前导斜杠:

bundle exec rspec spec/requests/static_pages_spec.rb

答案 1 :(得分:1)

仅供参考 - 当我的spec文件格式不正确时,我也遇到过这种情况。我错过了一个“DO”

答案 2 :(得分:0)

我有同样的问题 - 删除领先" /"修好了。