实例变量在单个测试中可用,但不在完整的测试套件中

时间:2017-08-04 17:41:52

标签: ruby-on-rails testing

我的测试:

def setup
    @seminar = seminars(:one)
end

test "Auto user_number" do
    debugger
    post students_path, params: { students: [{ first_name: "Noob",
                                last_name: "Sauce" }],
                                ss: { seminar_id: @seminar.id } }
    student = assigns(:student)
    assert_equal student.id, student.user_number
end

当我单独运行此测试文件时,一切都按预期传递。但是当我运行完整的测试套件时,它会在@ seminar.id上运行。

当我暂停调试器并调用@seminar时,结果为nil。

我已经检查了研讨会的研讨会(:一)。此外,这个相同的灯具在十几个其他测试文件中工作正常。

提前感谢任何见解。

1 个答案:

答案 0 :(得分:0)

事实证明,这个问题是由于另一个控制器具有与此控制器相同的类名引起的。

此测试包含在由

定义的类中
class StudentsControllerTest < ActionDispatch::IntegrationTest

由于一些鲁莽的剪切和粘贴,我有另一个Controller类,它具有完全相同的行定义它。这在某种程度上导致设置功能无法在其中一个类中运行。

干杯!