Capybara使用Devise发出请求规范

时间:2013-09-04 18:46:29

标签: ruby-on-rails rspec tdd capybara rspec-rails

这是我的要求规范:

require 'spec_helper'

describe "user signs in", focus: true do

  before(:each) do
    create(:account_type)
  end

  it "allows users to sign in with their email address and password" do
    test_user = build_stubbed(:user)
    visit root_path
    click_link "Sign-In"
    fill_in "user_email", with: test_user.email
    fill_in "user_password", with: test_user.password
    click_button "Sign In"
    page.should have_content "Vitals"
  end
end

问题是我可以看到请求发生在用户登录,但是当用户登录时,请求被重定向回主页而没有错误消息。

这是我的用户工厂:

FactoryGirl.define do
  factory :user do
    email Faker::Internet.email
    password "password"
    password_confirmation "password"
    agreed_to_age_requirements true

    subscriptions {[create(:subscription)]}
  end 
end

订阅工厂:

FactoryGirl.define do
  factory :subscription do
    account_type_id 1
    trial_expiry 30.days.from_now
    active true
  end
end

我不确定为什么请求失败并且没有登录用户。

0 个答案:

没有答案