Sha256: 3d7deb566e241cb7a650c5379f1fb80037a7d956254841c45f9d34f97ef53aba

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

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

describe Response do
  before(:each) do
    @response = Response.new(:headers => {'A' => 'a'})
  end

  it "should report normalized headers" do
    Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
    @response = Response.new(:headers => {'A' => 'a'})
    @response.headers.should == {'B' => 'b'}
  end

  describe "status" do

    it "should be 200 by default" do
      @response.status.should == 200
    end

    it "should return assigned status" do
      @response = Response.new(:status => 500)
      @response.status.should == 500
    end

  end

  describe "raising error" do

    it "should raise error if any assigned" do
      @response = Response.new(:exception => ArgumentError)
      lambda {
        @response.raise_error_if_any
      }.should raise_error(ArgumentError, "Exception from WebMock")
    end

    it "should not raise error if no error assigned" do
      @response.raise_error_if_any
    end
    
  end

  describe "body" do
    
    it "should return empty body by default" do
      @response.body.should == ''
    end

    it "should report body if assigned" do
      @response = Response.new(:body => "abc")
      @response.body.should == "abc"
    end
    
    it "should report string even if existing file path was provided" do
      @response = Response.new(:body => __FILE__)
      @response.body.should == __FILE__
    end
    
    it "should report content of a IO object if provided" do
      @response = Response.new(:body => File.new(__FILE__))
      @response.body.should == File.new(__FILE__).read
    end
    
    it "should report many times content of a IO object if provided" do
      @response = Response.new(:body => File.new(__FILE__))
      @response.body.should == File.new(__FILE__).read
      @response.body.should == File.new(__FILE__).read
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webmock-0.8.2 spec/response_spec.rb
webmock-0.8.1 spec/response_spec.rb