0

在发现测试驱动开发之前,我对 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。稍后将发布解决方案。

4

1 回答 1

0

好的,我修好了(接近完美)。这是我所做的:

我将 git 恢复到工作状态并从头开始。这次我没有用线

gem 'devise', :git => 'git://github.com/plataformatec/devise.git'

在我的 Gemfile 中,我只放了

gem 'devise'

然后通过安装最新的设计gem

gem install devise
rails generate devise:install

该命令安装了 1.4.5 版本,而不是我之前安装的 1.4.7。然后我安装了所有其他的 gem,即 capybara、guard-rspec、factory_girl_rails 和 launchy。现在一切正常,除了我留下的这两个警告:

Running: spec/requests/sign_ups_spec.rb
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
.

Finished in 0.16255 seconds
1 example, 0 failures

好吧,只要一切正常,我就可以接受警告,但如果有人知道如何摆脱它们,请告诉我。

谢谢。

于 2011-09-12T06:57:16.953 回答