嘿,我在做rspec rails的click_link
然後檢查鏈接頁面的內容。內容絕對是在該頁面,但它仍然給我一個錯誤,它不是。Rails - 無法獲得Rspec點擊鏈接工作
錯誤
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"
的routes.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
代碼對於集成測試看起來很不錯。您使用的是什麼版本的rspec-rails和水豚? – fontno 2013-05-06 06:57:00
我試過了,我得到了。失敗/錯誤:訪問log_in_path NoMethodError: 未定義的方法'訪問'爲#
2013-05-06 22:10:31
rails 3.2.13和capybara 1.1.2 – 2013-05-06 22:14:21