这是通过的测试:
test "should create user" do
assert_difference('User.count') do
post :create, user: { name: "John Doe",
email: "example@example.com",
password: "foobar3",
password_confirmation: "foobar3" }
end
这是失败的测试:
def setup
@user = User.new(name: "John Doe",
email: "example@example.com",
password: "foobar3",
password_confirmation: "foobar3")
end
test "should create user" do
assert_difference('User.count') do
post :create, user: @user
end
为什么第二次测试失败?以及如何使它使用@user 变量?