Sha256: 8fed98b378bbfa5a6920d8657d64345fa6d2fcbe1314b54856cb60f78e91b060

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

# typed: false
# frozen_string_literal: true

require './spec/spec_setup'
require 'frontman/context'
require 'frontman/resource'

describe Frontman::Context do
  subject { Frontman::Context.new }
  let(:resource) { Frontman::Resource.from_path('spec/frontman/mocks/html_file.html') }

  it 'should correctly handle attached methods' do
    subject.singleton_class.send(:define_method, 'testing') { 'value' }
    expect(subject.testing).to eq 'value'
  end

  it 'should correctly respond to attached methods' do
    subject.singleton_class.send(:define_method, 'testing') { 'value' }
    expect(subject.respond_to?('testing')).to eq true
  end

  context 'content' do
    it 'should return nil for unknown content' do
      expect(subject.yield_content('unknown content')).to eq nil
    end

    it 'should return not react to unknown content' do
      expect(subject.content_for?('unknown content')).to eq false
    end

    it 'should return content when it\'s set' do
      Frontman::App.instance.current_page = resource
      subject.content_for('my-key', 'myvalue')
      expect(subject.yield_content('my-key')).to eq 'myvalue'
    end

    it 'should react to known content' do
      Frontman::App.instance.current_page = resource
      subject.content_for('my-key', 'myvalue')
      expect(subject.content_for?('my-key')).to eq true
    end

    it 'should wrap the layout properly' do
      Frontman::Config.set(:layout_dir, 'spec/frontman/mocks/layouts')
      expect(Frontman::Resource.from_path('spec/frontman/mocks/wrap.haml').render).to eq "<h1>This is a test!</h1>\n\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
frontman-ssg-0.0.4 spec/frontman/context_spec.rb
frontman-ssg-0.0.3 spec/frontman/context_spec.rb
frontman-ssg-0.0.2 spec/frontman/context_spec.rb