Question

I am using Rails 4.1 and the Pundit gem. I created a UserPolicyTest class for my UserPolicy class. But when I run rake test, none of the tests in the class get run. I'm also trying to use mini-test. I cannot find any documentation on what the parent class should be. I also tried extending MiniTest::Unit:TestCase but that didn't work either. Below is the test class which is in the test/policies folder. The name is user_policy_test.rb. I removed some of the tests in the file to save space.

require 'test_helper'

class UserPolicyTest < ActiveSupport::TestCase

  def setup
    @user = users(:regularuser)
    @admin = users(:admin)
    @admin.role = :admin
  end

  def test_index
    policy = UserPolicy.new @admin, nil
    refute policy.index?
  end
end
Was it helpful?

Solution

I think I found my answer. It seems that with minitest, rake test doesn't run the tests in all of the test directories. I found some answers here:

Rails and MiniTest: add additional folder

I tried just running rake test:all and al of my tests were run. I'm not sure which solution I like better. I could continue to run this way or I could move the policies test directory under models or controllers.

I just installed guard and guard-minitest and that actually monitors all of my existing tests and runs all of them by default. So I think everything is good now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top