【发布时间】:2014-09-30 01:29:12
【问题描述】:
我是 ruby on rails 的新手。我正在做测试驱动开发。当我运行测试时,我收到以下错误:
1) User Signs Up for Blocitoff Successfully
Failure/Error: fill_in 'user_name', with: 'Joe User'
Capybara::ElementNotFound:
Unable to find field "user_name"
# ./spec/features/user_signs_up_spec.rb:6:in `block (2 levels) in <top (required)>'
这是我的规格:
require 'rails_helper'
feature 'User Signs Up for Blocitoff' do
scenario 'Successfully' do
visit new_user_path
fill_in 'User name', with: 'Joe User'
fill_in 'User email', with: 'joeuser@example.com'
fill_in 'User password', with: 'joepassword'
click_button 'Save'
end
end
这是我的 app/views/users/new.html.erb 文件:
<%= form_for User.new do |form| %>
<%= form.text_field :user_name, placeholder: 'User Name' %>
<%= form.text_field :user_email, placeholder: 'User Email' %>
<%= form.text_field :user_password, placeholder: 'User Password' %>
<%= form.submit 'Save' %>
<% end %>
这是 users_controller.rb:
class UsersController < ApplicationController
def new
end
end
这是我的迁移文件:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :user_name
t.string :user_email
t.string :user_password
t.timestamps
end
end
end
我认为这是规范、app/views/new.html.erb 和迁移之间的某种命名冲突。任何帮助将不胜感激...
【问题讨论】:
标签: ruby-on-rails rspec capybara