【问题标题】:Problem adding a custom field to Devise while testing with cucumber使用黄瓜测试时向设计添加自定义字段时出现问题
【发布时间】: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

知道是什么导致了这个错误以及如何解决它吗?

【问题讨论】:

    标签: ruby-on-rails cucumber


    【解决方案1】:

    您是否更新了测试数据库? rake db:test:prepare

    【讨论】:

    • 顺便说一句,您是否仅通过查看错误就意识到这是数据库?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2019-01-17
    • 1970-01-01
    • 2017-11-26
    相关资源
    最近更新 更多