我正在通过 rspec rails 学习僵尸课程,但我无法运行测试,因为他们没有读取我的 App/models 文件夹中的 ruby 代码。我什至尝试将我称为zombie.rb的ruby文件放入spec文件夹本身和require_relative中,但测试仍然失败,有人可以帮助我吗?我是一个新手,我发现 TDD 是学习精通编码的最好和最快的方法。我的代码如下,分别在zombie_spec.rb 文件和zombie.rb 文件中都有:
require_relative 'spec_helper'
require_relative 'zombie'
describe Zombie do
it 'is invalid without a name' do
zombie = Zombie.new
zombie.should_not be_valid
end
it 'include tweets' do
tweet1 = Tweet.new(status: 'Uuuuunhhhhh')
tweet2 = Tweet.new(status: 'Arrrrggggg')
zombie = Zombie.new(name: 'Ash', tweets: [tweet1, tweet2])
zombie.tweets.should include(tweet1)
zombie.tweets.should include(tweet2)
end
end
和zombie.rb文件在这里
class Zombie < ActiveRecord::Base
attr_accessor :Tweet
validates :name, presence: true
end
这是我得到的测试结果
1) Zombie is invalid without a name
Failure/Error: zombie = Zombie.new
ActiveRecord::StatementInvalid:
Could not find table 'zombies'
# ./zombie_spec.rb:8:in `block (2 levels) in <top (required)>
2) Zombie include tweets
Failure/Error: tweet1 = Tweet.new(status: 'Uuuuunhhhhh')
NameError:
uninitialized constant Tweet
# ./zombie_spec.rb:15:in `block (2 levels) in <top (required)>'