0
建立一個基本的博客應用程序,以推動我學習TDD,所以我是相當新的。我有問題讓水豚識別鏈接。好像所有的元素都在的地方,所以我在我缺少什麼困惑..Rspec:水豚幫手找不到鏈接
這裏是失敗的:
1) PostsController#GET create with valid attributes creates a post by the current_user
Failure/Error: sign_in(build_stubbed(:user))
Capybara::ElementNotFound:
Unable to find link "Sign Up"
# ./spec/support/authentication_helpers.rb:7:in `sign_in'
# ./spec/controllers/posts_controller_spec.rb:44:in `block (4 levels) in <top (required)>'
規格/支持/ authentication_helper.rb
require 'rails_helper'
module AuthenticationHelpers
def sign_in(x)
visit root_path
click_link "Sign Up"
fill_in "First Name", with: x.first_name
fill_in "Last Name", with: x.last_name
fill_in "Email", with: x.email
fill_in "Password", with: x.password
fill_in "Password Confirmation", with: x.password
click_button "Sign Up"
end
end
規格/控制器/ posts_controller_spec.rb
describe '#GET create' do
context 'with valid attributes' do
before :each do
post :create, post: attributes_for(:post)
end
it { expect(Post.count).to eq(1) }
it { expect(flash[:success]).to eq('Your post has been saved!') }
it { expect(assigns(:post)).to be_a(Post) }
it { expect(assigns(:post)).to be_persisted }
it { expect(response).to redirect_to Post.first }
it "creates a post by the current_user" do
sign_in(build_stubbed(:user))
@post = Post.last
expect(@post.user).to eq(user)
end
end
條
_header.html.erb
<div class="cbp-af-header">
<div class="cbp-af-inner">
<nav>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#"><%= link_to "Sign Up", new_user_path %></a>
<a href="#"><%= link_to "Log In", new_user_session_path %></a>
</nav>
</div>
</div>
耙路線
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
user_sessions POST /user_sessions(.:format) user_sessions#create
new_user_session GET /user_sessions/new(.:format) user_sessions#new
root GET / posts#index
post_comments GET /posts/:post_id/comments(.:format) comments#index
POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit
post_comment GET /posts/:post_id/comments/:id(.:format) comments#show
PATCH /posts/:post_id/comments/:id(.:format) comments#update
PUT /posts/:post_id/comments/:id(.:format) comments#update
DELETE /posts/:post_id/comments/:id(.:format) comments#destroy
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
admin GET /admin(.:format) admin/dashboard#index
如果這個信息是相關的;身份驗證是從頭構建的,我還沒有實施授權。
我有點困惑。失敗在第7行(直接訪問root_path之後),這是它最初點擊鏈接「註冊」到註冊頁面然後填寫表格,用「click_button」結束註冊「註冊」。當我簡單地使用'click'時,我得到錯誤'未定義的方法'點擊''。 – shroy 2015-04-06 16:59:44