Sha256: 79f1961acf07fcf13cdd6ebffd9c77872332721fa45d091223e5bfb5a41aed77

Contents?: true

Size: 1.84 KB

Versions: 51

Compression:

Stored size: 1.84 KB

Contents

require File.dirname(__FILE__) + '/helper'

class ResultTest < Test::Unit::TestCase
  it "sets response.body when result is a String" do
    mock_app {
      get '/' do
        'Hello World'
      end
    }

    get '/'
    assert ok?
    assert_equal 'Hello World', body
  end

  it "sets response.body when result is an Array of Strings" do
    mock_app {
      get '/' do
        ['Hello', 'World']
      end
    }

    get '/'
    assert ok?
    assert_equal 'HelloWorld', body
  end

  it "sets response.body when result responds to #each" do
    mock_app {
      get '/' do
        res = lambda { 'Hello World' }
        def res.each ; yield call ; end
        res
      end
    }

    get '/'
    assert ok?
    assert_equal 'Hello World', body
  end

  it "sets response.body to [] when result is nil" do
    mock_app {
      get '/' do
        nil
      end
    }

    get '/'
    assert ok?
    assert_equal '', body
  end

  it "sets status, headers, and body when result is a Rack response tuple" do
    mock_app {
      get '/' do
        [205, {'Content-Type' => 'foo/bar'}, 'Hello World']
      end
    }

    get '/'
    assert_equal 205, status
    assert_equal 'foo/bar', response['Content-Type']
    assert_equal 'Hello World', body
  end

  it "sets status and body when result is a two-tuple" do
    mock_app {
      get '/' do
        [409, 'formula of']
      end
    }

    get '/'
    assert_equal 409, status
    assert_equal 'formula of', body
  end

  it "raises a TypeError when result is a non two or three tuple Array" do
    mock_app {
      get '/' do
        [409, 'formula of', 'something else', 'even more']
      end
    }

    assert_raise(TypeError) { get '/' }
  end

  it "sets status when result is a Fixnum status code" do
    mock_app {
      get('/') { 205 }
    }

    get '/'
    assert_equal 205, status
    assert_equal '', body
  end
end

Version data entries

51 entries across 50 versions & 9 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sinatra-1.0/test/result_test.rb
adamwiggins-sinatra-0.10.1 test/result_test.rb
sinatra-sinatra-0.10.0 test/result_test.rb
sinatra-sinatra-0.10.1 test/result_test.rb
sinatra-sinatra-0.9.1.3 test/result_test.rb
sinatra-sinatra-0.9.2 test/result_test.rb
sinatra-base-1.0 test/result_test.rb
sinatra-1.2.6 test/result_test.rb
sinatra-1.3.0.d test/result_test.rb
sinatra-1.3.0.c test/result_test.rb
sinatra-1.2.3 test/result_test.rb
sinatra-1.1.4 test/result_test.rb
sinatra-1.2.2 test/result_test.rb
sinatra-1.3.0.b test/result_test.rb
sinatra-1.3.0.a test/result_test.rb
sinatra-1.2.1 test/result_test.rb
sinatra-1.2.0 test/result_test.rb
sinatra-1.2.0.d test/result_test.rb
sinatra-1.1.3 test/result_test.rb
sinatra-1.2.0.c test/result_test.rb