【问题标题】:Why is my Pundit Policy minitest test case not running with rake test?为什么我的 Pundit Policy minitest 测试用例没有使用 rake 测试运行?
【发布时间】:2014-04-21 03:21:32
【问题描述】:

我正在使用 Rails 4.1 和 Pundit gem。我为我的 UserPolicy 类创建了一个 UserPolicyTest 类。但是当我运行 rake test 时,类中的所有测试都没有运行。我也在尝试使用迷你测试。我找不到任何关于父类应该是什么的文档。我也尝试过扩展 MiniTest::Unit:TestCase 但这也不起作用。下面是 test/policies 文件夹中的测试类。名称是 user_policy_test.rb。我删除了文件中的一些测试以节省空间。

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

【问题讨论】:

    标签: ruby-on-rails unit-testing rake minitest pundit


    【解决方案1】:

    我想我找到了答案。似乎使用 minitest,rake test 不会在所有测试目录中运行测试。我在这里找到了一些答案:

    Rails and MiniTest: add additional folder

    我尝试只运行 rake test:all 并且我的所有测试都运行了。我不确定我更喜欢哪种解决方案。我可以继续以这种方式运行,也可以将策略测试目录移动到模型或控制器下。

    我刚刚安装了 guard 和 guard-minitest,它实际上监控了我所有的现有测试并默认运行所有测试。所以我认为现在一切都很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 2017-01-16
      相关资源
      最近更新 更多