设备退出功能的功能测试用例

时间:2015-01-21 13:06:50

标签: ruby-on-rails rspec devise

我正在使用Rspec和capibara在我的项目中编写测试用例,该测试用例是在Rails 4中编写的。问题是虽然我已经编写了我的测试用例注销功能但它给了我一个错误。以下是我的测试用例

# Feature: Sign out
# As a user
# I want to sign out
# So I can protect my account from unauthorized access
feature 'Sign out', :devise do
# Scenario: User signs out successfully
# Given I am signed in
# When I sign out
# Then I see a signed out message
  scenario 'applicant signs out successfully' do
    applicant = FactoryGirl.create(:applicant)
    signin(applicant.email, applicant.password)
    expect(page).to have_content I18n.t 'devise.sessions.signed_in'
    click_link 'Sign out'
    expect(page).to have_content I18n.t 'devise.sessions.signed_out'
  end
end

我的观看代码

<h2>Log in</h2>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
    <%= devise_error_messages! %>
    <div class="field">
        <%= f.label :email %><br />
        <%= f.email_field :email, autofocus: 'true' %>
    </div>

    <div class="field">
        <%= f.label :password %><br />
        <%= f.password_field :password, autocomplete: "off" %>
    </div>

    <% if devise_mapping.rememberable? -%>
        <div class="field">
          <%= f.check_box :remember_me %>
          <%= f.label :remember_me %>
        </div>
    <% end -%>

    <div class="actions">
        <%= f.submit "Log in" %>
    </div>
<% end %>

这就是我得到的错误

1) Sign out applicant signs out successfully
     Failure/Error: expect(page).to have_content I18n.t 'devise.sessions.signed_in'
       expected to find text "Signed in successfully." in "Sign up or Sign in You have to confirm your email address before continuing. Log in Email Password Remember me Sign up Forgot your password? Didn't receive confirmation instructions? Didn't receive unlock instructions?"
     # ./spec/features/applicants/sign_out_spec.rb:13:in `block (2 levels) in <top (required)>'

请帮助我,因为我是Rspec的新手。在此先感谢

编辑

这是我的登录方法

module Features
  module SessionHelpers
    def sign_up_with(email, password, confirmation)
      visit new_applicant_registration_path
      fill_in 'Email', with: email
      fill_in 'Password', with: password
      fill_in 'Password confirmation', :with => confirmation
      click_button 'Sign up'
    end
    def signin(email, password)
      visit new_applicant_session_path
      fill_in 'Email', with: email
      fill_in 'Password', with: password
      click_button 'Log in'
    end
  end
end

0 个答案:

没有答案