1
    require 'spec_helper'

describe PagesController do
  render_views

  describe "GET 'home'" do
    it "should be successful" do
      get 'home'
      response.should be_success
    end
  end

  describe "GET 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success
    end
  end

  describe "GET 'contact'" do
    it "should be successful" do
      response.should be_success
    end
  end




end

上面是我在学习 Ruby on rails 测试基础知识时编写的一个非常简单的测试,问题是它应该没有通过“接触”测试,因为我的 app/controllers/pages_controller.rb 中没有这个.

它返回以下内容

   Finished in 0.04558 seconds
3 examples, 0 failures

因此,它会成功计算测试,但如果其中之一是错误的,它不会失败。

4

1 回答 1

2

如果您已经联系了视图文件,这可能是通过联系的原因。尝试删除这些文件或重命名文件并再次检查。

(或者)

如果您不在测试环境中关闭缓存,您可能会遇到同样的问题。转到config/environments/test.rb并更改config.cache_classes = trueconfig.cache_classes = false

如果不让知道,这可能是原因。

于 2013-01-28T17:01:06.650 回答