ntalbott의 답변에 따라 조치가 표시됩니다. 포스트 작업은 조금 까다 롭습니다. 새 객체를 XML 메시지로 보내고 컨트롤러의 params 해시에 XML 속성을 표시하려면 헤더를 올바르게 가져와야합니다. 다음은 레일스 2.3.x의 예제입니다.
class TruckTest < ActionController::IntegrationTest
def test_new_truck
paint_color = 'blue'
fuzzy_dice_count = 2
truck = Truck.new({:paint_color => paint_color, :fuzzy_dice_count => fuzzy_dice_count})
@headers ||= {}
@headers['HTTP_ACCEPT'] = @headers['CONTENT_TYPE'] = 'application/xml'
post '/trucks.xml', truck.to_xml, @headers
#puts @response.body
assert_select 'truck>paint_color', paint_color
assert_select 'truck>fuzzy_dice_count', fuzzy_dice_count.to_s
end
end
게시 할 두 번째 인수는 매개 변수 해시 일 필요는 없습니다. 헤더가 맞으면 문자열 (XML 포함) 이 될 수 있습니다. 세 번째 주장 인 @headers는 나에게 많은 연구를 요구하는 부분입니다.
(또한 주 그리고 to_s의 사용 assert_select의 정수 값을 비교.)
내가 아는 그 부분하는 A..Z 통합 테스트 –
그 assert_equal을 찾는 것은 매우 취약하다. 엘리먼트 또는 애트리뷰트 순서의 보장은 없습니다. 변경되면 테스트가 중단됩니다. 리터럴 문자열 비교는 XML 트리의 평등을 검사하는 올바른 방법이 아닙니다. – bjnord