【发布时间】:2011-01-19 21:04:25
【问题描述】:
我在使用 Devise 的 Rails 应用程序中添加了一个 username 字段。我完成了所有必要的步骤,例如将字段添加到视图、将其添加到 User 模型、迁移我的数据库等。现在,当我手动完成注册步骤时,一切正常。但是,当我尝试在 Cucumber 中编写一个功能时,我会收到一大堆错误。
这是我在运行黄瓜功能时遇到的错误的简短列表
Scenario: New user registration with valid info # features/user_access.feature:7
When I sign up as a new user with valid info # features/step_definitions/user_access_steps.rb:5
undefined method `username' for #<User:0x00000102f7dcf0> (ActionView::Template::Error)
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1019:in `value_before_type_cast'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1007:in `value_before_type_cast'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `block in to_input_field_tag'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `fetch'
我已将错误隔离到我的设计视图中。由于某种原因,黄瓜不喜欢以下几行
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! % >
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
由于某种原因,cucumber 不能很好地与 :username 标签和 text_field 搭配使用。我在黄瓜步骤中所做的只是进入注册页面并尝试用名称填写username。
知道是什么导致了这个错误以及如何解决它吗?
【问题讨论】: