Big_Bird
Big_Bird

Reputation: 427

Testing for View Exceptions in Rails with Rspec

How do I write a test that would iterate through all the instances of User#Show (for each User) to see if a exception is thrown?

I understand how to write a test to check if the object has certain data in it. But don`t know how to iterate for each while making sure that it wouldn't throw a 500 error etc.

I might just have temp. brain freeze, but please help me out.

Any helps or guidelines are appreciated.

Upvotes: 0

Views: 186

Answers (1)

MrDanA
MrDanA

Reputation: 11647

You can do this. This assumes you have already created and saved users to your database.

describe UsersController do
  User.each do |user|
    it "doesn't return a 500 error for user #{user.name}" do
      get :show, :id => user.id
      assert_response(:success)
    end
  end
end

Your Ruby code doesn't just have to be inside of an it so you can use that to loop and then perform its later on.

Upvotes: 1

Related Questions