【发布时间】:2013-05-16 06:43:50
【问题描述】:
看来我在request specs 中多次使用current_path。但是,Capybara 现在要求规格在 features directory 中才能使用 Capybara DSL (page & visit)
# creating_posts_spec.rb
require "spec_helper"
feature "creating posts" do
scenario "creating posts with valid info is successful" do
visit new_post_path
fill_in 'Title', with: "This is a title test"
fill_in 'Content', with: "This is a content test"
click_button 'Create Post'
page.should have_content 'Post was successfully created.'
page.current_path.should == post_path(post)
end
end
它是一个简单的帖子控制器,并且在帖子在浏览器中呈现后页面就会显示出来。
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
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
root / posts#index
为什么我收到错误消息:undefined local variable or method 'post'?
我只是不记得曾经遇到过这种麻烦。 有人有建议或理由吗?还是我错过了一些明显的东西?来晚了
【问题讨论】:
-
感谢您的建议,但我已经完成了所有这些,
page工作正常。它只有current_path行。这很奇怪,除非我遗漏了一些明显的东西。
标签: ruby-on-rails tdd capybara acceptance-testing