我有一个将从Ruby继承的类。有没有在Rspec中测试这个类的好方法?你会在考试中创建孩子类,让他们继承父母,看看孩子是否有适当的方法?例如:有没有一种好的方法来测试Ruby中的父类?
说这是我们的父类:
class Animal
def breathe
"it's breathing"
end
def self.color(some_color)
@color = some_color
end
attr_reader :color
end
,并在我们的测试
let(:dummy_animal) do
class DummyAnimal < described_class
color :brown
end
DummyAnimal
end
然而,上述不起作用。返回的DummyAnimal
没有任何实例变量集,这是我所期望的。有没有一种好的方法来测试这个?我是否以这种错误的方式去做?
你想要测试什么?我不认为你会从其他类继承 - 这是其他类的问题,所以其他类的规格。 –