用rspec + Capybara登录测试不重定向到主页

时间:2015-02-12 22:36:32

标签: ruby-on-rails rspec devise capybara factory-bot

我正在尝试与Capybara进行请求测试,但它似乎无法正常工作。这是我的测试文件:

describe "Sessions", :type => :request do

  let(:company) { FactoryGirl.create(:company) }
  let(:user) { FactoryGirl.create(:admin, company_id: company.id ) }

  describe "login page" do
    it "signs me in" do
      visit '/users/sign_in'
      within("#new_user") do
        fill_in 'Email', :with => user.email
        fill_in 'Password', :with => user.password
      end
      click_button 'Sign in'
      expect(page).to have_content 'Agenda'
    end
  end
end

引发以下错误:

Failure/Error: expect(page).to have_content 'Agenda'
   expected #has_content?("Agenda") to return true, got false

我不确定问题是在登录还是重定向时。但是,如果我在测试中更改了最后一行:

expect(page).to have_content 'Invalid email'

我得到了相同的错误。

提前致谢。

更新:

我使用devise登录

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用screenshot_and_save_page在失败的测试之前截取页面的屏幕截图,也许您可​​以确定问题所在。