首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rspec单元测试

rspec单元测试
EN

Stack Overflow用户
提问于 2012-07-24 03:14:55
回答 1查看 829关注 0票数 1

当我用RSpec启动单元测试$ bundle exec rspec spec/时...

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2012-07-24 03:19:29

首先:

代码语言:javascript
复制
rails g rspec:install

它将创建文件spec_helper

然后您就可以为测试准备数据库了:

代码语言:javascript
复制
rake db:test:load
rake db:test:prepare
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11618971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档