Sha256: 393f5c9ceeb45e4f61b42bd5074fc545604995d017ef89eb8ab3d53c3787f38d

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

describe "HTTP" do

  before do
    @localhost_url = 'http://localhost'
    @fake_url = 'http://fake.url'
  end

  describe "Core HTTP method calls" do

    def test_http_method(method)
      called = false
      delegator = Proc.new { |r, q| @the_response = r; @the_query = q; called = true }
      query = BubbleWrap::HTTP.send(method, @localhost_url, { name: 'bubble-wrap', action: delegator })
      query.should.not.equal nil
      query.method.should.equal method.to_s.upcase
      query.options[:name].should.equal 'bubble-wrap'
      query.instance_variable_get(:@delegator).should.equal delegator

      query.connectionDidFinishLoading(query.connection)
      query.should.be.same_as @the_query
      query.response.should.be.same_as @the_response
      called.should.equal true
    end

    it ".get .post .put .delete .head .patch should properly generate the HTTP::Query" do
      [:get, :post, :put, :delete, :head, :patch].each do |method|
        test_http_method method
      end
    end

    it "uses the block instead of :action if both were given" do
      [:get, :post, :put, :delete, :head, :patch].each do |method|
        called = false
        expected_delegator = Proc.new {|response| called = true }

        query = BubbleWrap::HTTP.send(method, @localhost_url, { action: 'not_valid' }, &expected_delegator)
        query.connectionDidFinishLoading(query.connection)

        query.instance_variable_get(:@delegator).should.equal expected_delegator
        called.should.equal true
      end
    end

    it "works with classic blocks as well" do
      [:get, :post, :put, :delete, :head, :patch].each do |method|
        called = false
        query = BubbleWrap::HTTP.send(method, @localhost_url, { action: 'not_valid' } ) do
          called = true
        end
        query.connectionDidFinishLoading(query.connection)
        called.should.equal true
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bubble-wrap-1.5.0 spec/motion/http_spec.rb
bubble-wrap-1.5.0.rc1 spec/motion/http_spec.rb