Sha256: 7339d18b400cdfa22b034530143b639aed2064e63defcebd64b1a41aedc66470

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require_relative 'helper'

require 'hobby/pages'
require 'securerandom'
require 'nokogiri'

describe Hobby::Pages do
  before :all do
    @socket = "app.#{SecureRandom.uuid}.socket"
    @pid = fork do
      server = Puma::Server.new described_class.new 'spec/dirs/main'
      server.add_unix_listener @socket
      server.run
      sleep
    end
    sleep 0.01 until File.exist? @socket
    @conn = Excon.new 'unix:///', socket: @socket
  end

  after(:all) { `kill -9 #{@pid}` }

  it 'creates pages for existing templates' do
    doc = Nokogiri.HTML @conn.get(path: '/exist').body

    text = doc.at_css('p').text
    expect(text).to eq 'some'

    text = doc.at_css('title').text
    expect(text).to eq 'Default layout'
  end

  it 'returns 404 for non-existing templates' do
    response = @conn.get(path: '/nonexist')

    expect(response.status).to eq 404
    expect(response.body).to eq "404. The page named 'nonexist' was not found."
  end

  it 'supports layouts with multiple content sections' do
    response = @conn.get(path: '/with-head')
    doc = Nokogiri.HTML response.body

    text = doc.at_css('title').text
    expect(text).to eq 'Head from with-head'

    text = doc.at_css('p').text
    expect(text).to eq 'main content'
  end

  it 'creates pages with CSS when CSS was supplied' do
    response = @conn.get path: '/with-css'
    doc = Nokogiri.HTML response.body

    text = doc.at_css('style#for_page_with-css').text
    expect(text).to eq "input {\n  width: 100%; }\n"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hobby-pages-0.0.0 spec/main_spec.rb