Potrzebuję uzyskać odpowiedź z metody current_user
w specyfikacji żądania Rspec/capybara. Metoda jest zdefiniowana w ApplicationController
i używa metody helper_method. Metoda powinna po prostu zwrócić identyfikator użytkownika. W ramach testu chciałbym, aby ta metoda zawsze zwracała ten sam identyfikator użytkownika.Jak uruchomić procedurę ApplicationController w żądaniu spec
Alternatywnie, mógłbym naprawić mój problem, ustawiając session[:user_id]
w specyfikacji (co zwraca current_user
) ... ale to też nie działa.
Czy jedno z nich jest możliwe?
Edit:
Oto co mam (. Nie działa on tylko prowadzi normalną metodę current_user).
require 'spec_helper'
describe "Login" do
before(:each) do
ApplicationController.stub(:current_user).and_return(User.first)
end
it "logs in" do
visit '/'
page.should have_content("Hey there user!")
end
end
także nie działa:
require 'spec_helper'
describe "Login" do
before(:each) do
@mock_controller = mock("ApplicationController")
@mock_controller.stub(:current_user).and_return(User.first)
end
it "logs in" do
visit '/'
page.should have_content("Hey there user!")
end
end
jest 'current_user' metody klasy? Wydaje mi się że nie. Więc zamiast 'ApplicationController.stub (: current_user)' możesz potrzebować 'ApplicationController.any_instance.stub (: current_user)'. – skalee