내가 테스트 할 방법입니까? 서식 지정과 관련이 있습니까?RSpec에 매처 (Matchers) 액티브 작업을 할 때 : 그래서 여기에 관계
context 'method "by_letter"' do
it 'returns and ordered list by letter' do
theon = Contact.create!(
firstname: "Theon",
lastname: "Greyjoy",
email: "[email protected]"
)
rob = Contact.create!(
firstname: "Rob",
lastname: "Stark",
email: "[email protected]"
)
tyrion = Contact.create!(
firstname: "Tyrion",
lastname: "Lannister",
email: "[email protected]"
)
result = Contact.by_letter("S")
expect(result).to include("Snow")
end
end
그리고 여기 실행 테스트 (오, 마음에 베어는, 이전의 사양에 나는 "존 상기 생성 한 후 출력을 위해 내가 할 로그를이다 :
여기에 그 방법을 테스트하는 사양의 일부 스노우 (Snow) "가 나오고 알파벳순으로"스탁 (Stark) "앞에 팝업되어야합니다) :
Failures:
1) Contact method "by_letter" returns and ordered list by letter
Failure/Error: expect(result).to include("Snow")
expected #<ActiveRecord::Relation [#<Contact id: 1, firstname: "Jon", lastname: "Snow", email: "[email protected]", created_at: "2014-11-14 17:17:55", updated_at: "2014-11-14 17:17:55">, #<Contact id: 3, firstname: "Rob", lastname: "Stark", email: "[email protected]", created_at: "2014-11-14 17:17:56", updated_at: "2014-11-14 17:17:56">]> to include "Snow"
Diff:
@@ -1,2 +1,3 @@
-["Snow"]
+[#<Contact id: 1, firstname: "Jon", lastname: "Snow", email: "[email protected]", created_at: "2014-11-14 17:17:55", updated_at: "2014-11-14 17:17:55">,
+ #<Contact id: 3, firstname: "Rob", lastname: "Stark", email: "[email protected]", created_at: "2014-11-14 17:17:56", updated_at: "2014-11-14 17:17:56">]
무엇이 누락 되었습니까? 지정한 문자열이 포함 된 컬렉션을 반환하기 때문에 테스트를 통과해서는 안됩니까? 정규 배열이 아니고 프록시 배열의 일종이기 때문에 약간의 합병증이 있습니까? 시험을 통과하려면 무엇을해야합니까?
http://pivotallabs.com/testing-active-record-scopes/ 이것은 매우 유사합니다. AR :: Relation은 "Snow"#include?를 찾는 방법을 모르므로 오류가 발생합니다. 당신은 비록 개체에 일치 수 있습니다. – jfornoff