1
嘗試在登錄用戶嘗試訪問新建並創建操作後,在頁面重定向後測試通知。使用Rspec在頁面重定向後測試通知
規格故障:
失敗:
1) Authentication authorization as signed in master submitting a GET request to the Masters#new action
Failure/Error: it { should have_content("You cannot complete this request when signed in.") }
Capybara::ElementNotFound:
Unable to find xpath "/html"
# ./spec/requests/authentication_pages_spec.rb:126:in `block (5 levels) in <top (required)>'
2) Authentication authorization as signed in master submitting a POST request to the Masters#create action
Failure/Error: it { should have_content("You cannot complete this request when signed in.") }
Capybara::ElementNotFound:
Unable to find xpath "/html"
# ./spec/requests/authentication_pages_spec.rb:132:in `block (5 levels) in <top (required)>'
過濾器之前:
before_action :already_signed_in, only: [:new, :create]
def already_signed_in
redirect_to root_url, notice: "You cannot complete this request when signed in." if signed_in?
end
授權規格:
context "as signed in master" do
let(:master) { FactoryGirl.create(:master) }
before { sign_in master, no_capybara: true }
subject { page }
context "submitting a GET request to the Masters#new action" do
before { get new_master_path }
specify { expect(response).to redirect_to(root_url) }
it { should have_content("You cannot complete this request when signed in.") }
end
context "submitting a POST request to the Masters#create action" do
before { post masters_path }
specify { expect(response).to redirect_to(root_url) }
it { should have_content("You cannot complete this request when signed in.") }
end
end
好吧謝謝!我做了flash [:notice]這個主題,然後寫了它{should =〜/當你登錄/ i時你不能完成這個請求} –