2012-10-09 3 views
2

두 가지 테스트가 실패했습니다. 우분투에서만 (12), 내 (새) Mac에서는 테스트가 아닙니다.rspec - Ubuntu에서만이 속성 비교 usng assert_equal이 실패 할 때 왜 실패합니까?

실패한 두 가지는 Active Record 개체 속성 비교이지만이를 비교하기 위해 노력하고 있습니다. 명령 줄에서 해시를 만들고 특성을 붙여 넣으면 비교 결과가 동일하다고 말합니다.

우리는 수 백 가지의 테스트가 포함 된 광범위한 테스트 스위트를 보유하고 있기 때문에 진정한 난제입니다. 레일 3.2.8, RSpec에 2.11

Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes 
MiniTest::Assertion: 
    <{"id"=>414, 
    "duration"=>30, 
    "frequency"=>3, 
    "period"=>"week", 
    "group_size"=>"group", 
    "location"=>nil, 
    "service"=>nil, 
    "area_of_need"=>"speech", 
    "created_at"=>Tue, 09 Oct 2012 01:53:39 UTC +00:00, 
    "updated_at"=>Tue, 09 Oct 2012 01:53:39 UTC +00:00, 
    "therapist_id"=>nil, 
    "start_date"=>nil, 
    "end_date"=>nil, 
    "student_id"=>469, 
    "adhoc"=>false}> expected but was 
    <{"id"=>414, 
    "duration"=>30, 
    "frequency"=>3, 
    "period"=>"week", 
    "group_size"=>"group", 
    "location"=>nil, 
    "service"=>nil, 
    "area_of_need"=>"speech", 
    "created_at"=>Tue, 09 Oct 2012 01:53:39 UTC +00:00, 
    "updated_at"=>Tue, 09 Oct 2012 01:53:39 UTC +00:00, 
    "therapist_id"=>nil, 
    "start_date"=>nil, 
    "end_date"=>nil, 
    "student_id"=>469, 
    "adhoc"=>false}>. 
# (eval):2:in `assert_equal' 

시험 코드 : 나는 또한 시도

context "And a pre-existing Iep Service for one of those students" do 
    before(:each) { @iep_service = FactoryGirl.create(:iep_service, :student => @district.students.first) } 

    context "And an Iep Service CSV" do 
     before(:each) { @spreadsheet = IepServiceSpreadsheet.new(@district, open_spec_fixture_file('sample-ieps.csv')) } 

     specify "Prevent importing" do 
     # Leave database untouched 
     assert_equal 1, IepService.count 
     assert_equal @iep_service.attributes, IepService.first.attributes 

     # Provide error report 
     assert @spreadsheet.error_report.any? 
     end 
    end 
    end 

: @iep_service.attributes.should == IepService.first.attributes

만 가지고 : 큰 DIFF 포함와

Failure/Error: @iep_service.attributes.should == IepService.first.attributes 
    expected: {"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=>nil, "area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, "end_date"=>nil, "student_id"=>483, "adhoc"=>false} 
     got: {"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=>nil, "area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, "end_date"=>nil, "student_id"=>483, "adhoc"=>false} (using ==) 

" 구현 확인 ':

 Diff:{"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", 
"group_size"=>"group", "location"=>nil, "service"=>nil, "area_of_need"=>"speech", 
"created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "updated_at"=>Tue, 09 Oct 2012 02:13:51 
UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, "end_date"=>nil, "student_id"=>483, 
"adhoc"=>false}.==({"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", 
"group_size"=>"group", "location"=>nil, "service"=>nil, "area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, "end_date"=>nil, "student_id"=>483, "adhoc"=>false}) returned false even though the diff between {"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=>nil, 
"area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, 
"updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, 
"end_date"=>nil, "student_id"=>483, "adhoc"=>false} and {"id"=>421, "duration"=>30, 
"frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=>nil, 
"area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, 
"updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, "therapist_id"=>nil, "start_date"=>nil, 
"end_date"=>nil, "student_id"=>483, "adhoc"=>false} is empty. 
Check the implementation of 
{"id"=>421, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", 
"location"=>nil, "service"=>nil, "area_of_need"=>"speech", "created_at"=>Tue, 09 Oct 2012 
02:13:51 UTC +00:00, "updated_at"=>Tue, 09 Oct 2012 02:13:51 UTC +00:00, 
"therapist_id"=>nil, "start_date"=>nil, "end_date"=>nil, "student_id"=>483, 
"adhoc"=>false}.==. 
+0

매우 이상합니다! be_hash_matching 정규 표현식을 시도 했습니까? https://github.com/rspec/rspec-expectations/pull/79 –

답변

1

실제 답변이 제공되지 않았으므로 본인이 속명을 통해 반복 해 보았습니다.

i=0 
while i < @student.attributes.count 
    assert_equal @student.attributes[i], Student.first.attributes[i] 
    i+= 1 
end 

# Comparing field by field as ruby hash comparison isn't working right - 
# but only on Ubuntu!