ruby - rspec 比较两个数组的时候要小心。rpsec不会显示出数组的所有细节

访问量: 218

例如
     Failure/Error: OrderProcessor.bid_order_book.should == [bid_order_100x2]
     
       expected: [#<OrderBid id: 368, bid: 0, ask: 0, market_id: "ethusdt", price: 0.1e3, volume: 0.2e1, origin_volume...ocked: nil, origin_locked: nil, funds_received: 0.0, trades_count: 0, ask_code: nil, bid_code: nil>]
            got: [#<OrderBid id: 367, bid: 0, ask: 0, market_id: "ethusdt", price: 0.2e3, volume: 0.1e1, origin_volume...ocked: nil, origin_locked: nil, funds_received: 0.0, trades_count: 0, ask_code: nil, bid_code: nil>] (using ==)
       Diff:
       @@ -1,2 +1,3 @@
       -[#<OrderBid id: 368, bid: 0, ask: 0, market_id: "ethusdt", price: 0.1e3, volume: 0.2e1, origin_volume: 0.2e1, state: nil, done_at: nil, type: "OrderBid", member_id: 587, created_at: "2019-03-25 23:17:49", updated_at: "2019-03-25 23:17:49", sn: nil, source: "web", ord_type: nil, locked: nil, origin_locked: nil, funds_received: 0.0, trades_count: 0, ask_code: nil, bid_code: nil>]
       +[#<OrderBid id: 367, bid: 0, ask: 0, market_id: "ethusdt", price: 0.2e3, volume: 0.1e1, origin_volume: 0.1e1, state: nil, done_at: nil, type: "OrderBid", member_id: 587, created_at: "2019-03-25 23:17:49", updated_at: "2019-03-25 23:17:49", sn: nil, source: "web", ord_type: nil, locked: nil, origin_locked: nil, funds_received: 0.0, trades_count: 0, ask_code: nil, bid_code: nil>,
       + #<OrderBid id: 368, bid: 0, ask: 0, market_id: "ethusdt", price: 0.1e3, volume: 0.2e1, origin_volume: 0.2e1, state: nil, done_at: nil, type: "OrderBid", member_id: 587, created_at: "2019-03-25 23:17:49", updated_at: "2019-03-25 23:17:49", sn: nil, source: "web", ord_type: nil, locked: nil, origin_locked: nil, funds_received: 0.0, trades_count: 0, ask_code: nil, bid_code: nil>]

一开始看到 expected 和 got ,  以为是完全相同的。 

后面看到diff的时候, 才知道数组元素一个是1, 一个是2. rspec把数组的中间部分省略了,看起来仿佛是一个元素一样。

订阅/RSS Feed

Subscribe

分类/category