2016-04-09 22 views
1

tutun değişkenleri karşılaştırma Ben Bir hata tutarsa ​​Travis CI RSpec testleri. Aynı zaman

it 'could not update question' do 
    old_title = question.title 
    old_body = question.body 
    old_updated_at = question.updated_at 

    patch :update, id: question, question: attributes_for(:question, title: 'new valid title', body: 'new valid body'), format: :js 
    question.reload 

    expect(question.title).to eq old_title 
    expect(question.body).to eq old_body 
    expect(question.updated_at).to eq old_updated_at 
    end 

böyle bir test var:

1) QuestionsController PATCH #update question by someone else could not update question Failure/Error: expect(question.updated_at).to eq old_updated_at

expected: 2016-04-09 18:05:03.650576201 +0000 
     got: 2016-04-09 18:05:03.650576000 +0000 

Nasıl farklı olabilir ?? Yerel makinemde

+3

Başlıca kural: * Asla kayan nokta sayılarına güvenme * –

cevap

1

Testinizin yapısını iyileştirebilirsiniz. mocks kullanarak & koçanları ziyade devlet mutasyonu test düşünün (veya bunların eksikliği): testlerinizde sonra

RSpec.configure do |config| 
include ActiveSupport::Testing::TimeHelpers 
... 

Ve:

it 'could not update question' do 
    expect(Question).to_not receive(:update) # Depending on how your model gets updated 
    patch :update, id: question, question: attributes_for(:question, title: 'new valid title', body: 'new valid body'), format: :js 
end 
İlgili konular