Sha256: b726c7771c9f6dc09685d24aacb83def110e88e54ac0d97117284bd2bc65dd97

Contents?: true

Size: 1.96 KB

Versions: 12

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'
require 'rack/test'

describe Softcover::App do
  include Rack::Test::Methods

  def app
    Softcover::App
  end

  context "ordinary book" do
    before(:all) do
      generate_book
      Softcover::Builders::Html.new.build!
    end
    after(:all)  { remove_book }

    before { chdir_to_book }

    let(:manifest) { Softcover::BookManifest.new }
    let(:chapter) { manifest.chapters[1] }

    it 'redirects / to first chapter' do
      get '/'
      expect(last_response).to be_redirect
      expect(last_response.location).to match chapter.slug
    end

    it 'GET chapter' do
      get "/#{chapter.slug}"
      expect(last_response).to be_ok
      expect(last_response.body).to match Regexp.new(chapter.title)
    end

    it 'GET chapter.js' do
      get "/#{chapter.slug}.js"
      expect(last_response).to be_ok
      expect(last_response.body).to match Regexp.new(chapter.title)
      expect(last_response.body).not_to match Regexp.new('<html>')
    end

    it 'GET nonexistent chapter' do
      get '/boom'
      expect(last_response.status).to eq 404
    end

    describe 'serving files' do
      it 'GET pygments.css' do
        get '/stylesheets/pygments.css'
        expect_server_response_of_type 'text/css'
      end

      it 'GET main.js' do
        get '/main.js'
        expect_server_response_of_type 'application/javascript'
      end

      it 'GET css asset' do
        get '/assets/main.css'
        expect_server_response_of_type 'text/css'
      end

      it 'GET image asset' do
        get '/assets/icons.png'
        expect_server_response_of_type 'image/png'
      end

      it 'GET image within book' do
        get '/images/2011_michael_hartl.png'
        expect_server_response_of_type 'image/png'
      end

      def expect_server_response_of_type(type)
        expect(last_response).to be_ok
        expect(last_response.content_type).to match type
        expect(last_response.content_length > 0).to be_true
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
softcover-0.7.11 spec/app_spec.rb
softcover-0.7.10 spec/app_spec.rb
softcover-0.7.9 spec/app_spec.rb
softcover-0.7.8 spec/app_spec.rb
softcover-0.7.7 spec/app_spec.rb
softcover-0.7.6 spec/app_spec.rb
softcover-0.7.5 spec/app_spec.rb
softcover-0.7.4 spec/app_spec.rb
softcover-0.7.3 spec/app_spec.rb
softcover-0.7.2 spec/app_spec.rb
softcover-0.7.1 spec/app_spec.rb
softcover-0.7.0 spec/app_spec.rb