Sha256: 5c294f4d091f6895f6616cbd775a6d77cae446824f7146ea7a601262f34b5abe

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

class TestButterflyResponse < Test::Unit::TestCase
  context "response" do
    before do
      @env = {
        "REQUEST_URI" => "/.json",
        "REQUEST_METHOD" => "get"
      }
      @request = Butterfly::Request.new @env
      @response = Butterfly::Response.new  @request
    end
    it "should have headers, status and a body" do
      @response.headers.should == {}
      @response.status.should == 200
      @response.body.should == nil
    end
    it "should add the response header on a json request" do
      @response.prepare_headers.should == {"ContentType" => "application/json"}
    end
    it "should return an Array on to the response to return to Rack" do
      @response.return!("hi").class.should == Array
    end
    it "should return a rack request (json)" do
      req = Butterfly::Request.new(@env.merge("REQUEST_URI" => "/index.json"))
      resp = Butterfly::Response.new req
      resp.return!("hi").should == [200, {"ContentType" => "application/json"}, "\"hi\""]
    end
    it "should return a rack request (text)" do
      req = Butterfly::Request.new(@env.merge("REQUEST_URI" => "/"))
      resp = Butterfly::Response.new req
      resp.return!("hi").should == [200, {"ContentType" => "text/plain"}, "hi"]
    end
    it "should be able to add headers" do
      @response.add_header("foo", "bar")
      @response.headers.should === {"foo" => "bar"}
    end
    it "should return a 404 when there is a fail!" do
      @response.fail!
      @response.return!("hi").should == [404, {"ContentType" => "application/json"}, "\"hi\""]
    end
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
auser-butterfly-0.0.3 test/test_butterfly_response.rb
auser-butterfly-0.0.4 test/test_butterfly_response.rb
auser-butterfly-0.0.5 test/test_butterfly_response.rb
auser-poolparty-1.1.1 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.1.3 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.1.4 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.1.5 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.1.7 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.2.0 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.2.1 vendor/gems/butterfly/test/test_butterfly_response.rb
auser-poolparty-1.2.2 vendor/gems/butterfly/test/test_butterfly_response.rb
fairchild-poolparty-1.1.3 vendor/gems/butterfly/test/test_butterfly_response.rb
fairchild-poolparty-1.1.4 vendor/gems/butterfly/test/test_butterfly_response.rb
poolparty-1.2.2 vendor/gems/butterfly/test/test_butterfly_response.rb