有人可以向我解释一下吗?怎么了?
1) NetworkController GET #index for staff user locates all network latencies to display
Failure/Error: assigns(:latencies).should eq([@lat1, @lat2, @lat3])
expected: [#<NetworkLatency from_network_id: "BSC", to_network_id: "FZJ", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "ABC", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "DEF", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">]
got: [#<NetworkLatency from_network_id: "BSC", to_network_id: "FZJ", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "ABC", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "DEF", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">]
(compared using ==)
Diff:
@@ -1,4 +1,2 @@
-[#<NetworkLatency from_network_id: "BSC", to_network_id: "FZJ", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">,
- #<NetworkLatency from_network_id: "CSC", to_network_id: "ABC", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">,
- #<NetworkLatency from_network_id: "CSC", to_network_id: "DEF", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">]
+[#<NetworkLatency from_network_id: "BSC", to_network_id: "FZJ", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "ABC", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">, #<NetworkLatency from_network_id: "CSC", to_network_id: "DEF", error_status: nil, percent_packet_lost: 0, min_ping: 54.8, avg_ping: 54.8, max_ping: 54.8, created_at: "2013-07-30 19:09:14", updated_at: "2013-07-30 19:09:14">]
Expected
和got
我一样。那么为什么Rspec会报错呢?
编辑
- 我用
eq
created_at
并由语句udated_at
创建schema.rb
_t.datetime
NetworkLatency 对象由 FactoryGirl 创建,如下所示
@lat1 = FactoryGirl.create(:network_latency, from_network: @bsc_net, to_network: @fzj_net)
@lat2 = FactoryGirl.create(:network_latency, from_network: @csc_net, to_network: @abc_net)
@lat3 = FactoryGirl.create(:network_latency, from_network: @csc_net, to_network: @def_net)
然后由控制器使用以下方法从数据库中获取:
NetworkLatency.where(:from_network_id => site_ids).order('from_network_id ASC, to_network_id ASC')