rspec - 为什么这个assert_equal比较测试在mac上而不在Ubuntu上工作?

时间:2012-10-24 19:11:29

标签: ruby-on-rails ruby rspec assert

  

可能重复:
  rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

Ruby: 1.9.3-p194  
Rails: 3.2.8  
Ubuntu: 12.04

测试有很多设置,然后最终确实:

assert_equal @iep_service.attributes, IepService.first.attributes

在Mac上运行但在ubuntu上失败:

  2) Iep Service Spreadsheet A typical district With pre-existing students And a pre-existing Iep Service for one of those students And an Iep S[52/427$
SV Prevent importing
     Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes
     MiniTest::Assertion:
       <{"id"=>212,
        "duration"=>30,
        "frequency"=>3,
        "period"=>"week",
        "group_size"=>"group",
        "location"=>nil,
        "service"=>nil,
        "area_of_need"=>"speech",
        "created_at"=>Wed, 24 Oct 2012 18:59:47 UTC +00:00,
        "updated_at"=>Wed, 24 Oct 2012 18:59:47 UTC +00:00,
        "therapist_id"=>nil,
        "start_date"=>nil,
        "end_date"=>nil,
        "student_id"=>233,
        "adhoc"=>false}> expected but was
       <{"id"=>212,
        "duration"=>30,
        "frequency"=>3,
        "period"=>"week",
        "group_size"=>"group",
        "location"=>nil,
        "service"=>nil,
        "area_of_need"=>"speech",
        "created_at"=>Wed, 24 Oct 2012 18:59:47 UTC +00:00,
        "updated_at"=>Wed, 24 Oct 2012 18:59:47 UTC +00:00,
        "therapist_id"=>nil,
        "start_date"=>nil,
        "end_date"=>nil,
        "student_id"=>233,
        "adhoc"=>false}>.
     # (eval):2:in `assert_equal'
     # ./spec/models/iep_service_spreadsheet_spec.rb:71:in `block (6 levels) in <top (required)>'

如果有帮助,完整的来源是:

context "A typical district" do
  before(:each) { set_up_district }

  context "With pre-existing students" do
    before(:each) { StudentSpreadsheet.new(@district, open_spec_fixture_file('sample-students.csv')) }

    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.c    sv')) }
        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
  end
end

1 个答案:

答案 0 :(得分:0)

assert_equal使用operator / method ==。

您可以在此处阅读assert_equal的文档:http://ruby-doc.org/core/classes/Test/Unit/Assertions.html#M006665。它直接来自Ruby,Rails不会覆盖定义。

因此,取决于对象类型== bahaves的不同,以及它来自Ruby,可能会有不同的实现或ruby代码略有不同。

无论如何,你最好比较一个值或者与==比较可能会带给你的。