使用Capybara和Devise?

时间:2011-08-30 18:20:43

标签: ruby-on-rails ruby-on-rails-3 rspec devise capybara

我正在尝试使用Capybara为我的app + devise编写登录集成测试。

这是我到目前为止所做的:

require 'spec_helper'

describe "the signup process", :type => :request do
  before :each do
    @user_1 = Factory.create(:user, :email => 'bob@golden.com', :password => 'iPassword')
  end

  it "signs me in" do

    visit new_user_session_path

    fill_in 'user[email]', :with => 'bob@golden.com'
    fill_in 'user[password]', :with => 'iPassword'

    click_link_or_button 'Sign In'

  end


end

这是过去了。这里的问题是它没有检查用户是否已登录(cookie?)并且网址是否正确重定向?

如何将这些细节添加到此测试中?此外,对于无效登录,我如何测试以确保正确设置了闪光警报?

谢谢

1 个答案:

答案 0 :(得分:3)

click_link_or_button'登录'后添加:

current_path.should == 'your path'
page.should have_content("Signed in successfully.")

/support/devise.rb

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end