私は RSpec (v3.1.7) を独学しています。rspec をrails g rspec:install
既存の Rails アプリにインストールしました - 新しく作成しました。
モデルを作成しました: rails g rspec:model zombie
. 移行を実行すると、すべてうまくいきました。
: app/models/zombie.rb:
class Zombie < ActiveRecord::Base
validates :name, presence: true
end
中: app/spec/models/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)>'
私はビデオチュートリアルに従っており、ビデオ(RSpecを使用したテスト)を後者までフォローしました。2章で痩せたみたい。何か不足していますか?ビデオ チュートリアル用に古いバージョンの rspec を使用しているビデオはありますか?
私の移行ファイルでは:
class CreateZombies < ActiveRecord::Migration
def change
create_table :zombies do |t|
t.timestamps
end
end
end