Sha256: c0bd1a1c0c537340494c3e3a548c861eace5134cbc8a4df36fab609a4546eb3a

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'
require 'acceptance/webmock_shared'

unless RUBY_PLATFORM =~ /java/
  require 'acceptance/typhoeus/typhoeus_hydra_spec_helper'

  describe "Typhoeus::Hydra" do
    include TyphoeusHydraSpecHelper

    include_context "with WebMock"

    describe "Typhoeus::Hydra features" do
      before(:each) do
        WebMock.disable_net_connect!
        WebMock.reset!
      end

      describe "callbacks" do
        before(:each) do
          @hydra = Typhoeus::Hydra.new
          @request = Typhoeus::Request.new("http://example.com")
        end

        it "should call on_complete with 2xx response" do
          body = "on_success fired"
          stub_request(:any, "example.com").to_return(:body => body)

          test = nil
          @hydra.on_complete do |c|
            test = c.body
          end
          @hydra.queue @request
          @hydra.run
          test.should == body
        end

        it "should call on_complete with 5xx response" do
          response_code = 599
          stub_request(:any, "example.com").to_return(:status => [response_code, "Server On Fire"])

          test = nil
          @hydra.on_complete do |c|
            test = c.code
          end
          @hydra.queue @request
          @hydra.run
          test.should == response_code
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webmock-1.7.8 spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
webmock-1.7.7 spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
webmock-1.7.6 spec/acceptance/typhoeus/typhoeus_hydra_spec.rb