Sha256: b989a8cf510c6a4a76df7182e885911619ba114fec395cffa69ab43c1946905e

Contents?: true

Size: 1.71 KB

Versions: 21

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'

RSpec.describe YARD::Server::StaticCaching do
  include StaticCaching

  describe "#check_static_cache" do
    def adapter; @adapter ||= mock_adapter end
    def request; @request ||= MockRequest.new end

    it "returns nil if document root is not set" do
      adapter.document_root = nil
      expect(check_static_cache).to be nil
    end

    it "reads a file from document root if path matches file on system" do
      request.path_info = '/hello/world.html'
      expect(File).to receive(:file?).with('/public/hello/world.html').and_return(true)
      expect(File).to receive(:open).with('/public/hello/world.html', anything).and_return('body')
      s, _, b = *check_static_cache
      expect(s).to eq 200
      expect(b).to eq ["body"]
    end

    it "reads a file if path matches file on system + .html" do
      request.path_info = '/hello/world'
      expect(File).to receive(:file?).with('/public/hello/world.html').and_return(true)
      expect(File).to receive(:open).with('/public/hello/world.html', anything).and_return('body')
      s, _, b = *check_static_cache
      expect(s).to eq 200
      expect(b).to eq ["body"]
    end

    it "returns nil if no matching file is found" do
      request.path_info = '/hello/foo'
      expect(File).to receive(:file?).with('/public/hello/foo.html').and_return(false)
      expect(check_static_cache).to eq nil
    end

    it "adds mount point to cache location" do
      request.path_info = '/hello/world.html'
      request.script_name = '/mount/point'
      expect(File).to receive(:file?).with('/public/mount/point/hello/world.html').and_return(false)
      expect(check_static_cache).to eq nil
    end
  end
end

Version data entries

21 entries across 20 versions & 4 rubygems

Version Path
yard-0.9.24 spec/server/static_caching_spec.rb
yard-0.9.23 spec/server/static_caching_spec.rb
yard-0.9.22 spec/server/static_caching_spec.rb
yard-0.9.21 spec/server/static_caching_spec.rb
yard-0.9.20 spec/server/static_caching_spec.rb
yard-0.9.19 spec/server/static_caching_spec.rb
yard-0.9.16 spec/server/static_caching_spec.rb
yard-0.9.15 spec/server/static_caching_spec.rb
yard-0.9.14 spec/server/static_caching_spec.rb
yard-0.9.13 spec/server/static_caching_spec.rb
yard-0.9.12 spec/server/static_caching_spec.rb
yard-0.9.11 spec/server/static_caching_spec.rb
yard-0.9.10 spec/server/static_caching_spec.rb
yard-0.9.9 spec/server/static_caching_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/spec/server/static_caching_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/spec/server/static_caching_spec.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/spec/server/static_caching_spec.rb
yard-0.9.8 spec/server/static_caching_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/spec/server/static_caching_spec.rb
yard-0.9.7 spec/server/static_caching_spec.rb