0
Failure/Error: @group.attributes.keys.should include (Group.first.attributes.keys)     
   expected 

["id", "duration", "frequency", "period", "group_size", "location", "service", "area_of_need", "created_at", "updated_at", "therapist_id", "start_date", "end_date", "student_id", "adhoc"] 
to include  
["id", "duration", "frequency", "period", "group_size", "location", "service", "area_of_need", "created_at", "updated_at", "therapist_id", "start_date", "end_date", "student_id", "adhoc"]

测试:

@group.attributes.keys.should include (Group.first.attributes.keys) 
4

2 回答 2

2

因为a.should includes(b)断言这a.include? b是真的并include?检查一个数组的元素是否包含一个对象,而不是一个数组是否等于另一个

[1].include? [1]
=> false

[1].include? 1
=> true

[[1]].include? [1]
=> true
于 2012-10-10T01:46:31.080 回答
1

答案是哈希比较在 Ubuntu 上失败,但在 Mac 上有效。

我的解决方法是:

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

# Comparing field by field as ruby hash comparison isn't working right - 
# but only on Ubuntu!
于 2012-10-26T01:29:47.447 回答