1
我有幾個集成測試,其中一些斷言是相同的。爲了維護性方面的考慮,我想在一個獨特的功能下重新組合每個測試的共同聲明。在函數中封裝重複的斷言
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, params: { session: { email: "", password: "" } }
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end
test "login with valid information followed by logout" do
get login_path
assert_template 'sessions/new'
post login_path, params: { session: { email: @user.email, password: "password" } }
.
end
例如,
get login_path
assert_template 'sessions/new'
位重複兩次測試中。我怎樣才能使這更可維護?