Let's say that I have a method that looks like this:
def raise_if_client_status_error(xml_resp) # xml_resp is Nokogiri::XML object
unless xml_resp.at('StatusCode').text == 'Success'
raise ClientError, xml_resp.at('StatusMessage').text
end
end
Is it possible to create an xml_resp_mock and stub the chained call -- .at('StatusCode').text
-- to return 'Success'? I'm unsure of the syntax to use, if it's at all possible.
It is not necessary to mock Nokogiri in your tests, because it doesn't exhibit any of the reasons to mock on c2 or reasons for use on wikipedia. It would be better to pass in a document with <StatusCode>Success</StatusCode>
instead. It would be best to mock the methods of the object that would normally read the xml response from the network.