ab1428x
ab1428x

Reputation: 804

ruby on rails: rspec not failing tests when it should

    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

Above is a very simple test I've written while learning the basics of testing in Ruby on rails, the problem is that it should be failing the "contact" test since I don't have this in my app/controllers/pages_controller.rb.

It return the following

   Finished in 0.04558 seconds
3 examples, 0 failures

So it counts the test successfully but doesn't fail if one of them is wrong.

Upvotes: 1

Views: 504

Answers (1)

Sri
Sri

Reputation: 2273

If you have already the view files in contact, that's might be the reason to pass contact. Try to remove those files or rename the files and check again.

(or)

You might run into the same issues if you don't turn off caching in the test environment. Go to config/environments/test.rb and change config.cache_classes = true to config.cache_classes = false

It's might be the reason, if not let know.

Upvotes: 2

Related Questions