SORU
21 Mart 2012, ÇARŞAMBA


&; Any_instance "demek" nasıl; &; should_receive" quot; RSpec kez herhangi bir sayı

Benim veritabanına birden çok kayıt ile birkaç csv dosyaları ithalat raylar alma kumanda var. Eğer kayıtları aslında RSpec kullanarak kaydedilmişse RSpec test etmek istiyorum:

<Model>.any_instance.should_receive(:save).at_least(:once)

Ancak hata diyorum

The message 'save' was received by <model instance> but has already been received by <another model instance>

Kontrol yapmacık bir örnek:

rows = CSV.parse(uploaded_file.tempfile, col_sep: "|")

  ActiveRecord::Base.transaction do
    rows.each do |row| 
    mutation = Mutation.new
    row.each_with_index do |value, index| 
      Mutation.send("#{attribute_order[index]}=", value)
    end
  mutation.save          
end

Test etmek mümkün bu RSpec kullanarak ya da herhangi bir geçici çözüm var mı?

CEVAP
3 NİSAN 2012, Salı


İşte geçersiz kılmak zorunda kalmazsınız daha iyi bir cevap :yeni yöntem:

save_count = 0
<Model>.any_instance.stub(:save) do |arg|
    # The evaluation context is the rspec group instance,
    # arg are the arguments to the function. I can't see a
    # way to get the actual <Model> instance :(
    save_count =1
end
.... run the test here ...
save_count.should > 0

Saplama yöntemi w/kısıtlaması * herhangi bir örneği bağlı olabilir gibi görünüyor, ve blok kontrol edebileceğiniz bir Kont kez doğru numarayı aramış olduğunu iddia yapabilirsiniz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • HTC

    HTC

    12 Ocak 2006
  • TastyTuts | Creative video tutorials by Gareth David

    TastyTuts |

    6 Temmuz 2011
  • TechShowsYou

    TechShowsYou

    3 Mart 2011