在发现测试驱动开发之前,我对 RoR 很陌生,并且编写了一些东西。所以我尝试用guard-rspec和capybara写一些测试。一切都很好,但我收到了一些关于设计的弃用警告(版本 1.1.rc02),所以我更新了它(现在有最新版本 1.4.5)。
这些是警告:
运行所有规格
DEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
FDEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
.DEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead. (called from _app_views_devise_registrations_new_html_erb__1735759005_2291086140_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/registrations/new.html.erb:3)
所以我改变了
<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
到
<%= form_for(resource, :url => registration_path(resource_name)) do |f| %>
并摆脱了警告。到目前为止一切顺利,我继续进行测试,并没有尝试自己在浏览器中打开应用程序。
我不确定当时发生了什么,但突然之间,当我尝试在浏览器中打开应用程序时,我收到以下错误消息:
NoMethodError in Slides#index
Showing /Users/xonic/Documents/work/ror.ror.at/app/views/layouts/application.html.erb where line #27 raised:
private method `split' called for #<Class:0x10c023278>
Extracted source (around line #27):
24:
25: <div class="gopro">
26:
27: <% if user_signed_in? %>
28: Signed in as <%= link_to current_user.username, user_path(current_user) %>. Not you? <%#, user_slides_path(current_user.username) %>
29: <%= link_to "Sign out", destroy_user_session_path %>
30: <% else %>
很明显,Devise 遇到了麻烦……不知道为什么。有趣的是,在save_and_open_page
测试应用程序时调用时,会打开一个浏览器窗口,应用程序显示正确且完全没有错误。
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.95467 seconds
3 examples, 0 failures
更新: 我已经看到了这个非常相似的问题Devise: NoMethod Error & user_signed_in并正确设置了用户模型,所以这不是问题。
这让我很困惑,希望有人能理解发生了什么crossFingers
谢谢,xon1c
更新 我修复了它,但由于缺乏声誉,stackoverflow 不会让我在接下来的 6 小时内回答我自己的问题sigh。稍后将发布解决方案。