我在上一个问题中遇到了问题,我提供了帮助,但现在我接受了新问题。我正在使用 rspec 和 capybara 进行集成测试。
这是我的profiles_controllers.rb:
before_filter :authenticate_user!
def update
@profile = current_user.profile
if @profile.update_attributes(params[:profile])
flash[:success] = "Профиль обновлен!"
redirect_to user_path(current_user)
else
render 'edit'
end
end
这是我的测试文件:
describe "ProfilePages" do
subject { page }
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
let(:profile) { FactoryGirl.create(:profile, user: user) }
before do
login user
visit edit_profile_path(profile)
end
it { should have_selector('h2', text: 'Заполните информацию о себе') }
describe "change information" do
let(:new_city) { "Ulan-Bator" }
let(:new_phone) { 1232442 }
let(:new_gamelevel) { "M2" }
let(:new_aboutme) { "nfsfsdfds" }
let(:submit) { "Сохранить" }
before do
fill_in "Город", with: new_city
fill_in "Телефон", with: new_phone
select new_gamelevel, from: "Уровень игры"
fill_in "О себе", with: new_aboutme
click_button submit
end
specify { profile.reload.city.should == new_city }
specify { profile.reload.phone.should == new_phone }
specify { profile.reload.gamelevel.should == new_gamelevel }
specify { profile.reload.aboutme.should == new_aboutme }
end
describe "submitting to the update action" do
before { put profile_path(profile) }
specify { response.should redirect_to(user_path(user)) }
end
end
end
我有错误:
失败/错误:指定 { response.should redirect_to(user_path(user)) } 预期响应是重定向到http://www.example.com/users/1但重定向到http://www.example。 com/users/sign_in
我使用设计并在规范/支持中有登录助手:
def login(user)
page.driver.post user_session_path, 'user[email]' => user.email, 'user[password]' => user.password
end
config.include Devise::TestHelpers, :type => :controller
在spec_helper.rb
我尝试使用warden helper login_as ,但有同样的错误。我怎么理解它不开始会话,我是对的?