Sha256: c5b42263f2c9d785a842367175a1a5cbe06a903b25f98bd83f5e5c364dde22be

Contents?: true

Size: 1.81 KB

Versions: 65

Compression:

Stored size: 1.81 KB

Contents

require File.expand_path('../helper', __FILE__)

begin
require 'yajl'

class YajlTest < Minitest::Test
  def yajl_app(&block)
    mock_app do
      set :views, File.dirname(__FILE__) + '/views'
      get('/', &block)
    end
    get '/'
  end

  it 'renders inline Yajl strings' do
    yajl_app { yajl('json = { :foo => "bar" }') }
    assert ok?
    assert_body '{"foo":"bar"}'
  end

  it 'renders .yajl files in views path' do
    yajl_app { yajl(:hello) }
    assert ok?
    assert_body '{"yajl":"hello"}'
  end

  it 'raises error if template not found' do
    mock_app { get('/') { yajl(:no_such_template) } }
    assert_raises(Errno::ENOENT) { get('/') }
  end

  it 'accepts a :locals option' do
    yajl_app do
      locals = { :object => { :foo => 'bar' } }
      yajl 'json = object', :locals => locals
    end
    assert ok?
    assert_body '{"foo":"bar"}'
  end

  it 'accepts a :scope option' do
    yajl_app do
      scope = { :object => { :foo => 'bar' } }
      yajl 'json = self[:object]', :scope => scope
    end
    assert ok?
    assert_body '{"foo":"bar"}'
  end

  it 'decorates the json with a callback' do
    yajl_app do
      yajl(
        'json = { :foo => "bar" }',
        { :callback => 'baz' }
      )
    end
    assert ok?
    assert_body 'baz({"foo":"bar"});'
  end

  it 'decorates the json with a variable' do
    yajl_app do
      yajl(
        'json = { :foo => "bar" }',
        { :variable => 'qux' }
      )
    end
    assert ok?
    assert_body 'var qux = {"foo":"bar"};'
  end

  it 'decorates the json with a callback and a variable' do
    yajl_app do
      yajl(
        'json = { :foo => "bar" }',
        { :callback => 'baz', :variable => 'qux' }
      )
    end
    assert ok?
    assert_body 'var qux = {"foo":"bar"}; baz(qux);'
  end
end

rescue LoadError
  warn "#{$!.to_s}: skipping yajl tests"
end

Version data entries

65 entries across 62 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/sinatra-1.4.8/test/yajl_test.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/sinatra-1.4.8/test/yajl_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/sinatra-1.4.8/test/yajl_test.rb