HEre是我的集成测试代码:
要求' test_helper'
class UserSignupTest < ActionDispatch::IntegrationTest
test "a user can signup and return back to root url" do
visit new_user_path
fill_in "user[username]", with: "flyers1"
fill_in "user[first_name]", with: "user"
fill_in "user[last_name]", with: "name"
fill_in "user[email]", with: "username@gmail.com"
fill_in "user[street]", with: "street"
fill_in "user[city]", with: "city"
fill_in "user[state]", with: "state"
fill_in "user[country]", with: "country"
fill_in "user[password]", with: "password"
fill_in "user[password_confirmation]", with: "password"
click_button "Finish Signup"
refute flash.empty?
end
这是我的创建控制器方法:
def create
user = User.new(user_params)
if user.valid?
valid_user_signup(user)
else
invalid_user_signup(user)
end
end
和
def valid_user_signup(user)
user.save
session[:user_id] = user.id
flash[:success] = "Signup Successful"
redirect_to root_path
end
这里发生了什么?为什么我会收到一条错误消息,提示&#34;未定义方法flash&#34;为nil:nilclass?
答案 0 :(得分:1)
你在使用Capybara吗?我自己还没有使用它,但是如果我记得的话,正常的Test :: Unit断言语法并不总是能用它。尝试测试是否可以看到这样的flash消息:
page.should_not have_css('.flash')