#spec/features/user_spec.rbrequire'rails_helper'describe'home page'dobeforedo@user=create(:user,:admin)# mock CSRF allow_any_instance_of(ActionController::Base).toreceive(:protect_against_forgery?).and_return(true)endit'User is admin can login and see data',:js=>truedovisit'/backend'#後台首頁fill_in'email',:with=>'admin@gmail.com'#輸入emailfill_in'password',:with=>'password'#輸入密碼click_button'submit'#點擊登入expect(page).tohave_content('後台')#到後台看到後台的字endit'logout',:js=>truedologin_as(@user)#登入visit'/backend/posts'#在內頁find("#logout").click#點擊登出,記得要下 idexpect(current_path).toeq('/')#回到首頁expect(page).tohave_content('首頁')#頁面上也首頁的字endend