16

明らかな何かが欠けているかもしれない初心者... 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 ファイルを認識できないのはなぜですか?

4

2 に答える 2

41

実行したことを確認してください

rails generate rspec:install

spec_helper.rb ファイルを作成します。

于 2012-02-21T21:55:42.647 に答える
24

spec_helper.rb が spec ディレクトリにあると思いますか? 試す:

require_relative '../spec_helper'
于 2011-02-18T19:53:10.913 に答える