rspec - 为什么这个属性比较使用assert_equal时,只有在ubuntu上它们是相同的呢? [英] rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

查看:145
本文介绍了rspec - 为什么这个属性比较使用assert_equal时,只有在ubuntu上它们是相同的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个测试失败 - 但只在Ubuntu(12),但不在我的(新)Mac。



失败二是活动记录对象属性比较,但在我所有的努力来比较它们,例如在命令行中粘贴哈希值并粘贴属性,比较结果表明它们是相同的。



一个真正的益智游戏,因为我们有一个包含数百个测试的广泛测试套件。
Rails 3.2.8,rspec 2.11

 失败/错误: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=>无,
start_date=>无,
end_date=> nil,
student_id=> 469,
adhoc=> false}>预期但是是
<{id=> 414,
duration=> 30,
frequency=> 3,
period=
group_size=>group,
location=> nil,
service=> nil,
area_of_need =>speech,
created_at=> 2012年10月9日星期二01:53:39 UTC +00:00,
updated_at=& :53:39 UTC +00:00,
therapist_id=>无,
start_date=>无,
end_date=>无,
student_id=> 469,
adhoc=> false}> ;.
#(eval):2:在`assert_equal'中

测试代码:

  context对于其中一名学生而言,预先存在的Iep服务之前($ each){$ iep_service = FactoryGirl.create(:iep_service,:student => @ district.students.first)} 

contextIep Service CSV之前做过
(:each){@spreadsheet = IepServiceSpreadsheet.new(@district,open_spec_fixture_file('sample-ieps.csv'))}

指定防止导入do
#保持数据库不变
assert_equal 1,IepService。 count
assert_equal @ iep_service.attributes,IepService.first.attributes

#提供错误报告
assert @ spreadsheet.error_report.any?
end
end
end

我也试过: @ iep_service.attributes.should == IepService.first.attributes



但是:

 失败/错误:@ iep_service.attributes.should == IepService.first.attributes 
expected:{id=> 421,duration => 30,频率=> 3,周期=>周,组尺寸=>组,位置=> area_of_need=>speech,created_at=> Tue,09 Oct 2012 02:13:51 UTC +00:00,updated_at=& 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年10月09日02:13:51 UTC +00:00, rapist_id=> nil,start_date=> nil,end_date=> nil,student_id=> 483,adhoc=> false}(使用==)

包含一个大的差异,包括检查'的实现:

  Diff:{id=> 421,duration=> 30,frequency=> 3,period=>week,
group_size=>group,location=> nil,service=> nil,area_of_need=>speech,
created_at=& 2012 02:13:51 UTC +00:00,updated_at=>星期二,09十月2012 02:13:51
UTC +00:00,therapist_id=>无,start_date= > nil,end_date=> nil,student_id=> 483,
adhoc=> false}。 ; 30,频率=> 3,周期=>周,
group_size=>组,位置=>无,服务=& ,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=>无,start_date=>无,end_date=即使在{id=> 421,duration=> 30,frequency=>>之间的差异,也返回假,即student_id=> 483,adhoc=> ; 3period=>week,group_size=>group,location=> nil,service=> nil,
area_of_need=> speech,created_at=>星期二,09十月2012 02:13:51 UTC +00:00,
updated_at=>星期二,09十月2012 02:13:51 UTC +00:00 ,therapist_id=> nil,start_date=> nil,
end_date=> nil,student_id=> 483,adhoc=> false}和{id => 421,持续时间=> 30,
频率=> 3,周期=>周,组尺寸=>组,位置=> ;无,服务=>无,
area_of_need=>语音,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=>无,start_date=>无,
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=> $ b 02:13:51 UTC +00:00,updated_at=>星期二,09十月2012 02:13:51 UTC +00:00,
therapist_id=>无,start_date => nil,end_date=>无,student_id=> 483,
adhoc=> false}。


解决方案

没有真正的答案,所以我走了迭代遍历atrributes,例如

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

#比较字段按字段作为红宝石哈希比较是不正确的工作 -
#但只在Ubuntu上!


Two tests are failing - but only on Ubuntu(12) but not on my (new) Mac.

The failure two are Active Record object attribute comparisons but in all my effort to compare them, e.g. making hash's at the command line and pasting the attributes in, the comparison says they are the same.

A real puzzler as we have an extensive test suite with many hundreds of tests. Rails 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'

Test Code:

  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 

I also tried: @iep_service.attributes.should == IepService.first.attributes

but got:

 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 ==)

with a big diff including "check the implementation of':

      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}.==.

解决方案

No real answer has been given so I've gone with iterating through the atrributes, e.g.

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!

这篇关于rspec - 为什么这个属性比较使用assert_equal时,只有在ubuntu上它们是相同的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆