Sha256: 63443430a26e0195e14cf2c938d6e22aa9311479a3093be64048c2b4686b2b3b

Contents?: true

Size: 1.63 KB

Versions: 65

Compression:

Stored size: 1.63 KB

Contents

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

begin
require 'nokogiri'

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

  it 'renders inline Nokogiri strings' do
    nokogiri_app { nokogiri 'xml' }
    assert ok?
    assert_body %(<?xml version="1.0"?>\n)
  end

  it 'renders inline blocks' do
    nokogiri_app do
      @name = "Frank & Mary"
      nokogiri { |xml| xml.couple @name }
    end
    assert ok?
    assert_body %(<?xml version="1.0"?>\n<couple>Frank &amp; Mary</couple>\n)
  end

  it 'renders .nokogiri files in views path' do
    nokogiri_app do
      @name = "Blue"
      nokogiri :hello
    end
    assert ok?
    assert_body "<?xml version=\"1.0\"?>\n<exclaim>You're my boy, Blue!</exclaim>\n"
  end

  it "renders with inline layouts" do
    next if Tilt::VERSION <= "1.1"
    mock_app do
      layout { %(xml.layout { xml << yield }) }
      get('/') { nokogiri %(xml.em 'Hello World') }
    end
    get '/'
    assert ok?
    assert_body %(<?xml version="1.0"?>\n<layout>\n  <em>Hello World</em>\n</layout>\n)
  end

  it "renders with file layouts" do
    next if Tilt::VERSION <= "1.1"
    nokogiri_app {
      nokogiri %(xml.em 'Hello World'), :layout => :layout2
    }
    assert ok?
    assert_body %(<?xml version="1.0"?>\n<layout>\n  <em>Hello World</em>\n</layout>\n)
  end

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

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

Version data entries

65 entries across 62 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/nokogiri_test.rb