Sha256: 355bb9c7d97e1360272b895a91ab9484349bf94545578ae2ed4d287a11d69fd4

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe HTTParty::Response do
  describe "initialization" do
    before do
      @response_object = {'foo' => 'bar'}
      @body = "{foo:'bar'}"
      @code = 200
      @response = HTTParty::Response.new(@response_object, @body, @code)
    end
    
    it "should set delegate" do
      @response.delegate.should == @response_object
    end
    
    it "should set body" do
      @response.body.should == @body
    end
    
    it "should set code" do
      @response.code.should == @code
    end
  end
  
  it "should be able to set headers during initialization" do
    response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, {'foo' => 'bar'})
    response.headers.should == {'foo' => 'bar'}
  end
  
  it "should send missing methods to delegate" do
    response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
    response['foo'].should == 'bar'
  end
  
  it "should be able to iterate delegate if it is array" do
    response = HTTParty::Response.new([{'foo' => 'bar'}, {'foo' => 'baz'}], "[{foo:'bar'}, {foo:'baz'}]", 200)
    response.size.should == 2
    lambda {
      response.each { |item| }
    }.should_not raise_error
  end
  
  xit "should allow hashes to be accessed with dot notation" do
    response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
    response.foo.should == 'bar'
  end
  
  xit "should allow nested hashes to be accessed with dot notation" do
    response = HTTParty::Response.new({'foo' => {'bar' => 'baz'}}, "{foo: {bar:'baz'}}", 200)
    response.foo.should == {'bar' => 'baz'}
    response.foo.bar.should == 'baz'
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spreedly-1.3.5 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.3.4 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.3.3 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.3.2 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.3.1 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.0.0 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.0.1 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.2.2 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.3.0 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.1.0 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.2.1 vendor/httparty/spec/httparty/response_spec.rb
spreedly-1.2.0 vendor/httparty/spec/httparty/response_spec.rb