1

I am writing a gem and I want to check that it is performing an http request with the parameters , headers and content that its supposed to pass. How do I write a unit test.

I am using httparty to do the request, I am also using fakeweb to test actions after the response.

Pedro
  • 403
  • 5
  • 14
  • 1
    "How do I write a unit test" is a little vague. Do you need help with rspec syntax? Do you need to know how to set up rspec in a gem environment? Do you want guidance in the TDD or BDD process? Perhaps some code or initial attempts would be a good place to start the discussion. – Mark Thomas May 29 '11 at 12:58

1 Answers1

3

I recommend using webmock and include the stub request that should be created:

In your Gemfile:

group :test do
  gem 'webmock'
end

In your spec:

stub_request(:post, 
             "https://external.api.com")
             .with(:body => {:message => {:foo => 'bar'}}, 
                  :headers => {'Accept'=>'application/json'})
Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
juandebravo
  • 200
  • 1
  • 5