0
因此,我目前正在關注這個tutorial,並且在第五集中我遵循了指示並更新了我正在使用的新Gems的Rails 4.1.6的語法。我的代碼是GithubRuby on Rails在驗證測試時出錯
我的Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.1.6'
gem 'pg'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'spring', group: :development
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
gem 'simple_form'
gem 'devise'
group :development, :test do
gem 'guard'
gem 'guard-livereload'
gem 'guard-rspec'
gem 'rspec-rails'
gem 'rspec-collection_matchers'
gem 'capybara'
gem 'factory_girl_rails'
gem 'launchy'
gem 'database_cleaner'
gem 'shoulda-matchers'
gem 'warden'
end
我的規格/型號/ user_spec.rb有以下幾點:
require 'rails_helper'
describe Account do
describe 'validations' do
it { should validate_presence_of (:name)}
it { should validate_presence_of (:email)}
it { should validate_presence_of (:password)}
end
describe 'associations' do
end
end
我的應用程序/模型/ user.rb有:
class User < ActiveRecord::Base
devise :database_authenticatable, :recoverable, :rememberable, :validatable
validates :name, presence: true
end
而當運行RSpec時,我得到以下錯誤:
Account
validations
should require name to be set (FAILED - 1)
should require email to be set (FAILED - 2)
should require password to be set (FAILED - 3)
Failures:
1) Account validations should require name to be set
Failure/Error: it { should validate_presence_of (:name)}
NoMethodError:
undefined method `name=' for #<Account:0x00000108092050>
# ./spec/models/user_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Account validations should require email to be set
Failure/Error: it { should validate_presence_of (:email)}
NoMethodError:
undefined method `email=' for #<Account:0x00000108088640>
# ./spec/models/user_spec.rb:7:in `block (3 levels) in <top (required)>'
3) Account validations should require password to be set
Failure/Error: it { should validate_presence_of (:password)}
NoMethodError:
undefined method `password=' for #<Account:0x00000108079af0>
# ./spec/models/user_spec.rb:8:in `block (3 levels) in <top (required)>'
一直呆在這一段時間了,無法弄清楚我還需要檢查什麼。任何想法都會很有幫助。
謝謝!