1

$ bundle exec rspec spec/RSpecでユニットテストを開始すると...

admin@ADMINPC /d/ruby/rails/projects/CMS (static-pages)
$ bundle exec rspec spec/
d:/ruby/rails/projects/CMS/spec/controllers/pages_controller_spec.rb:1:in `requi
re': cannot load such file -- spec_helper (LoadError)
        from d:/ruby/rails/projects/CMS/spec/controllers/pages_controller_spec.r
b:1:in `<top (required)>'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:in `load'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:in `map'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/command_line.rb:22:in `run'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/runner.rb:69:in `run'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/runner.rb:8:in `block in autorun'

これをどのように修正しますか?

ファイルpages_controller_spec.rb:

require 'spec_helper'

describe PagesController do

  describe "GET 'home'" do
    it "returns http success" do
      get 'home'
      response.should be_success
    end
  end

  describe "GET 'contact'" do
    it "returns http success" do
      get 'contact'
      response.should be_success
    end
  end

end
4

1 に答える 1

3

初めに:

rails g rspec:install

ファイルが作成されますspec_helper

テスト用にデータベースを準備するよりも:

rake db:test:load
rake db:test:prepare
于 2012-07-23T19:19:29.447 に答える