test/helpers_test.rb in sinatra-1.2.9 vs test/helpers_test.rb in sinatra-1.3.0.a

- old
+ new

@@ -310,10 +310,23 @@ end get '/' assert_body 'ok' end + + it 'accepts an options hash' do + mock_app do + set :sessions, :foo => :bar + get '/' do + assert_equal env['rack.session.options'][:foo], :bar + 'ok' + end + end + + get '/' + assert_body 'ok' + end end describe 'mime_type' do include Sinatra::Helpers @@ -417,43 +430,20 @@ assert_equal content_type(:html), 'text/html;charset=utf-8' assert_equal content_type(:foo), 'text/foo;charset=utf-8' assert_equal content_type(:xml), 'application/xml;charset=utf-8' assert_equal content_type(:xhtml), 'application/xhtml+xml;charset=utf-8' assert_equal content_type(:js), 'application/javascript;charset=utf-8' - assert_equal content_type(:json), 'application/json;charset=utf-8' assert_equal content_type(:bar), 'application/bar' assert_equal content_type(:png), 'image/png' assert_equal content_type(:baz), 'application/baz;charset=utf-8' tests_ran = true "done" end end get '/' assert tests_ran end - - it 'handles already present params' do - mock_app do - get '/' do - content_type 'foo/bar;level=1', :charset => 'utf-8' - 'ok' - end - end - get '/' - assert_equal 'foo/bar;level=1, charset=utf-8', response['Content-Type'] - end - - it 'does not add charset if present' do - mock_app do - get '/' do - content_type 'text/plain;charset=utf-16' - 'ok' - end - end - get '/' - assert_equal 'text/plain;charset=utf-16', response['Content-Type'] - end end describe 'send_file' do setup do @file = File.dirname(__FILE__) + '/file.txt' @@ -624,18 +614,10 @@ end get '/baz' do expires Time.at(0) end - - get '/blah' do - obj = Object.new - def obj.method_missing(*a, &b) 60.send(*a, &b) end - def obj.is_a?(thing) 60.is_a?(thing) end - expires obj, :public, :no_cache - 'Hello World' - end end end it 'sets the Cache-Control header' do get '/foo' @@ -654,15 +636,10 @@ it 'allows passing time objects' do get '/baz' assert_equal 'Thu, 01 Jan 1970 00:00:00 GMT', response['Expires'] end - - it 'accepts values pretending to be a Numeric (like ActiveSupport::Duration)' do - get '/blah' - assert_equal ['public', 'no-cache', 'max-age=60'], response['Cache-Control'].split(', ') - end end describe 'last_modified' do it 'ignores nil' do mock_app do @@ -737,11 +714,11 @@ end get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2010 23:43:52 GMT' } assert_equal 200, status assert_equal 'foo', body - get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2012 23:43:52 GMT' } + get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2100 23:43:52 GMT' } assert_equal 304, status assert_equal '', body end end @@ -879,9 +856,39 @@ it 'is aliased to #to' do mock_app { get('/') { to }} get '/' assert_equal 'http://example.org/', body + end + end + + describe 'logger' do + it 'logging works when logging is enabled' do + mock_app do + enable :logging + get '/' do + logger.info "Program started" + logger.warn "Nothing to do!" + end + end + io = StringIO.new + get '/', {}, 'rack.errors' => io + assert io.string.include?("INFO -- : Program started") + assert io.string.include?("WARN -- : Nothing to do") + end + + it 'logging works when logging is disable, but no output is produced' do + mock_app do + disable :logging + get '/' do + logger.info "Program started" + logger.warn "Nothing to do!" + end + end + io = StringIO.new + get '/', {}, 'rack.errors' => io + assert !io.string.include?("INFO -- : Program started") + assert !io.string.include?("WARN -- : Nothing to do") end end module ::HelperOne; def one; '1'; end; end module ::HelperTwo; def two; '2'; end; end