黄瓜找不到路线?这可能是一个新的大问题
使用 Rspec2 和 Cucumber 的 Rails3 应用程序
Cucumber
Given /^that a user is logged in$/ do
current_user = User.first
render new_user_post_path(current_user)
end
Routes.rb
map.resources :users do |users|
users.resources :posts, :collection => {:view => :get}
end
posts_controller_spec
describe PostsController do
describe "#new" do
it "should be successful" do
get :new
response.should be_success
end
end
end
我的第一个史诗般的失败
(::) failed steps (::)
No route matches {:controller=>"posts", :action=>"new"} (ActionController::RoutingError)
./features/step_definitions/tasklist_steps.rb:3:in `/^that a user is logged in$/'
features/tasklist.feature:7:in `Given that a user is logged in'
Failing Scenarios:
cucumber features/tasklist.feature:6 # Scenario: List SubmitLink
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.147s
rake aborted!
抱歉,我也是纽布。这是我第一次尝试黄瓜。 :(
Rails3 app with Rspec2 and Cucumber
Cucumber
Given /^that a user is logged in$/ do
current_user = User.first
render new_user_post_path(current_user)
end
Routes.rb
map.resources :users do |users|
users.resources :posts, :collection => {:view => :get}
end
posts_controller_spec
describe PostsController do
describe "#new" do
it "should be successful" do
get :new
response.should be_success
end
end
end
My first big epic Fail
(::) failed steps (::)
No route matches {:controller=>"posts", :action=>"new"} (ActionController::RoutingError)
./features/step_definitions/tasklist_steps.rb:3:in `/^that a user is logged in$/'
features/tasklist.feature:7:in `Given that a user is logged in'
Failing Scenarios:
cucumber features/tasklist.feature:6 # Scenario: List SubmitLink
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.147s
rake aborted!
Sorry, I'm too newb. This is my first ever attempt at cucumber. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,Rails 3 路线中不推荐使用地图,您可能应该有这样的东西。
按照我通常编写给定的方式,我遵循用户实际采用的路径,在测试数据库中创建用户,然后实际转到登录页面并登录,以便应用程序中的所有内容都得到正确设置。
我按以下方式使用它:
另外,通常我不会在黄瓜步骤中调用渲染。由于您正在使用模拟浏览器(假设是 webrat/capybara),您将
访问 path_to(page_name)
。Well first off map is deprecated in Rails 3 routes, you should probably have something like this.
The way I normally write my givens, I follow the path that the user would actually take, create the user in the test db, and then actually going to the login page and signing in, so everything gets set correctly in the app.
I use it the following way:
Also, normally I don't call render inside a cucumber step. Since you are working with a simulated browser (assuming webrat/capybara) you would
visit path_to(page_name)
.