Rails:如何忽略单个测试的夹具

时间:2017-11-17 23:33:47

标签: ruby-on-rails testing

我有两个测试。每个结果取决于用户数。

目前,我没有用户设备。第二个测试在其设置方法中引入了用户。如果数据库中有用户,则第一次测试将失败。

但我想在users.yml中介绍用户。因此,第一次测试将因现有用户而失败。有没有办法可以指示此测试忽略fixtures/users.yml

require 'test_helper'

class UsersSignupTestWithoutExistingUsers < ActionDispatch::IntegrationTest
  test "Signup page is accessible" do
    get new_user_registration_path
    assert_response :success
  end
end

class UsersSignupTestWithExistingUsers < ActionDispatch::IntegrationTest
  def setup
    post user_registration_path, params: {user: {
      email:                 "user@test.com",
      password:              "password",
      password_confirmation: "password"
    }}
  end

  test "Signup page will redirect" do
    get new_user_registration_path
    assert_response :redirect
  end
end

1 个答案:

答案 0 :(得分:1)

在DB中不需要用户的测试中,您可以存储在DB中查找用户的方法,以便为该测试返回一个空集。