Ruby Debug“没有这样的文件加载--spec_helper”

时间:2011-02-18 19:50:20

标签: ruby-on-rails rspec ruby-debug

Noob可能会遗漏一些明显的东西...... 我正在尝试调试Rspec文件。此时Rspec文件被删除:

  require 'spec_helper'

  describe PagesController do

    render_views

    describe "GET 'home'" do
        describe "when not signed in" do

        before(:each) do
          get :home
        end

        it "should be successful" do
          response.should be_success
        end

        it "should have a vendor section" do
          response.should have_selector("h1", :content => "Vendor")
        end

        it "should have a hospital section" do
          response.should have_selector("h1", :content => "Hospital")
        end
    end
  end

我从命令行进行以下调用:

rdebug spec/controllers/pages_controller_spec.rb

调试器运行,但抛出以下错误:

> require 'spec_helper'

    <internal:lib/rubygems/custom_require>:29:in `require'
    <internal:lib/rubygems/custom_require>:29:in `require'
    /home/kevin/.rvm/bin/rails_projects/evaluationrx/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
    /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_load'
    /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:125:in `debug_program'
    /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/ruby-debug19-0.11.6/bin/rdebug:412:in `<top (required)>'
    /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/bin/rdebug:19:in `load'
    /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/bin/rdebug:19:in `<main>'
Uncaught exception: no such file to load -- spec_helper

没有调试器的Rspec没有问题。我正在使用Rspec 2.3.0,ruby-debug19(0.11.6),Rails 3.0.3和ruby 1.9.2。为什么调试器不能看到spec_helper文件?

2 个答案:

答案 0 :(得分:41)

确保您已经

运行
rails generate rspec:install

创建spec_helper.rb文件。

答案 1 :(得分:24)

我假设您的spec_helper.rb位于spec目录中?尝试:

require_relative '../spec_helper'