Hi Patrick,

I'd spec out the possible consequences of the different response codes as
well what should happen in the event of a HTTP timeout. The requests
themselves I would mock out because, as you pointed out, you're calling a
3rd party and you don't want live HTTP calls in your unit tests.

Best,
Sidu.
http://sidu.in#code
http://goldberg.c42.in


On 22 July 2011 01:19, Patrick J. Collins <patr...@collinatorstudios.com>wrote:

> So I have a class that does this:
>
>  def perform
>    @response = Net::HTTP.new(url.host, url.port).start {|http|
> http.request(do_post) }
>
>    unless @response.is_a?(Net::HTTPSuccess) ||
> @response.is_a?(Net::HTTPRedirection)
>      @response.error!
>    end
>  end
>
>  def do_post
>    Net::HTTP::Post.new(url.request_uri).tap do |req|
>      req.set_form_data({:foo => "Bar")
>    end
>  end
>
>  def url
>    "http://myurl.com/something";
>  end
> ...
>
> My question is--  Is there anything worth testing here?  Since this is
> involving a 3rd party API, I shouldn't perform an actual post (for many
> reasons)...  On the other hand, this is pretty much all Net::HTTP
> functionality
> so I should be able to rely on it just working as is.
>
> The only thing I can see in this that MIGHT be worth testing is that
> @response
> raises an error if it's not a HTTPSuccess or HTTPRedirection, but---  is
> that
> really worth doing?
>
> Thank you in advance for your input.
>
>
> Patrick J. Collins
> http://collinatorstudios.com
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to