所以我试图在我的一个模型中添加一个子类,然后创建一个fixture并测试它,但我似乎遇到了错误。我真的不知道如何描述问题,但我通过以下步骤重新创建了它。如果您希望我在这个问题上添加一些内容,请询问。
控制台
$ hobo new lab --setup
$ cd lab
$ hobo g model foo num:integer
IDE
#inserted into app/models/foo.rb
def do_foo
num*5
end
#create app/models/bar.rb
class Bar < Foo
def doo_foo
num*10
end
end
控制台
$ hobo g migration
IDE
#create test/fixtures/bars.yml
bar_one:
num: 1
#create test/unit/bar_test.rb
require 'test_helper'
class BarTest < ActiveSupport::TestCase
def test_bar
puts Bar.first.do_foo
assert true
end
end
控制台
$ rake test
ERROR
1) Error:
test_bar(BarTest):
ActiveRecord::StatementInvalid: Could not find table 'bars'
答案 0 :(得分:0)
拿出你的夹具。 由于Bar是Foo的一个子类,它将使用Foos灯具。