嘿,我click_link
在 rspec rails 中做,然后检查链接页面的内容。内容肯定在那个页面上,但它仍然给我一个错误,它不是。
错误
Failure/Error: page.should have_selector('h1', :text => "Reset Password")
这就是我的规范正在做的事情
- 访问 log_in_path
- 点击忘记密码
- 实际上访问 new_password_reset_path
- 寻找
<h1>
重置密码</h1>
password_resets_controller_spec.rb(规范)
require 'spec_helper'
describe PasswordResetsController do
it "emails user when requesting password reset" do
user = FactoryGirl.build(:user)
visit log_in_path
click_link "forgotten password?"
current_path.should eq(new_password_reset_path)
page.should have_selector('h1', :text => "Reset Password")
end
end
new.html.haml (log_in_path)
%h1 Log in
= form_tag sessions_path do
%p
= label_tag :email
= text_field_tag :email, params[:email]
%p
= label_tag :password
= password_field_tag :password
%p.button
%input{name: "commit", type: "submit", value: "Log in"}
.field
= label_tag :remember_me
= check_box_tag :remember_me, 1, params[:remember_me]
%p
= link_to "forgotten password?", new_password_reset_path
new.html.haml(点击链接后应该去的页面)
%h1 Reset Password
= form_tag password_resets_path, :method => :post do
.field
= label_tag :email
= text_field_tag :email, params[:email]
.actions
= submit_tag "Reset Password"
路线.rb
SomeApp::Application.routes.draw do
get "password_resets/new"
get "sessions/new"
resources :sessions
resources :password_resets
resources :email_activations
resources :users do
collection do
get :accept_invitation
end
end
get "static_pages/home"
get "static_pages/help"
root to: 'static_pages#home'
match "sign_up", to: "users#new"
match '/help', to: 'static_pages#help'
match '/log_in', to: 'sessions#new'
match '/log_out', to: 'sessions#destroy'
end