Flowdock
requests() public

Returns an array of all request objects that have been sent to the mock. You can use this to check if your model actually sent an HTTP request.

Example

def setup
  @matz  = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
  ActiveResource::HttpMock.respond_to do |mock|
    mock.get "/people/1.xml", {}, @matz
  end
end

def test_should_request_remote_service
  person = Person.find(1)  # Call the remote service

  # This request object has the same HTTP method and path as declared by the mock
  expected_request = ActiveResource::Request.new(:get, "/people/1.xml")

  # Assert that the mock received, and responded to, the expected request from the model
  assert ActiveResource::HttpMock.requests.include?(expected_request)
end
Show source
Register or log in to add new notes.