我自学RSpec(v3.1.7)。我已将rspec与rails g rspec:install
安装到现有的Rails应用程序中 - 新创建。RSpec模型测试:失败
我创建了一个模型:rails g rspec:model zombie
。冉移民,一切顺利。
在:应用/模型/ zombie.rb:
class Zombie < ActiveRecord::Base
validates :name, presence: true
end
在:应用程序/规格/模型/ zombie_spec.rb:
require 'rails_helper'
RSpec.describe Zombie, :type => :model do
it 'is invalid without a name' do
zombie = Zombie.new
zombie.should_not be_valid
end
end
在终端当我跑(在应用程序目录):rspec spec/models
我得到:下面的视频教程
F
Failures:
1) Zombie is invalid without a name
Failure/Error: zombie.should_not be_valid
NoMethodError:
undefined method `name' for #<Zombie id: nil, created_at: nil, updated_at: nil>
# ./spec/models/zombie_spec.rb:6:in `block (2 levels) in <top (required)>'
Im和我跟着视频(测试使用RSpec)下降到LATT呃。我很喜欢第二章的减肥。我错过了什么吗?视频是否使用旧版rspec作为视频教程?
在我的移民文件:
class CreateZombies < ActiveRecord::Migration
def change
create_table :zombies do |t|
t.timestamps
end
end
end
我已经创建了一个'attr_accessor:name'和它的工作原理是。但视频没有attr_accessor!我很失落! – Sylar 2014-11-05 09:33:02
查看这两个链接:http://guides.rubyonrails.org/migrations.html#using-the-change-method adn http://guides.rubyonrails.org/migrations.html#running-migrations-in-different-环境 – jyrkim 2014-11-06 08:48:27