1
J'écris un test rspec pour ma classe Cars, et j'ai une question concernant la mise en place de mocks. Je voudrais remplacer le tableau de pièces dans Cars, comment puis-je faire cela?Stubbing Un attribut de modèle
je le code suivant:
class Cars
has_many :parts
def heavy_count
parts.inject(0) { |sum, v| v.weight > 10 ? sum + 1 : sum }
end
end
avec le test
context ("#heavy_count") do
let(:car) {mock_model(Car, :brand => "toyota")}
let(:vote_1) {mock_model(Part, :weight => 11)}
let(:vote_2) {mock_model(Part, :weight => 11)}
it "should return 2 if there are 2 parts heavier than 10" do
#how do I stub parts here?
end
end