Sha256: 724bb3d8191d81ae2b16c23ae87bcfa12099659329c638bde943bfbbdd087d0c

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

describe Nanoc::CLI::Commands::Shell, site: true, stdio: true do
  describe '#run' do
    before do
      # Prevent double-loading
      expect(Nanoc::CLI).to receive(:setup)
    end

    it 'can be invoked' do
      rules_collection = Nanoc::RuleDSL::RulesCollection.new
      config = Nanoc::Int::Configuration.new.with_defaults

      dsl = Nanoc::RuleDSL::CompilerDSL.new(rules_collection, config)
      allow(Nanoc::RuleDSL::CompilerDSL).to receive(:new).and_return(dsl)

      context = Object.new
      allow(Nanoc::Int::Context).to receive(:new).with(anything).and_return(context)
      expect(context).to receive(:pry)

      Nanoc::CLI.run(['shell'])
    end
  end

  describe '#env_for_site' do
    subject { described_class.env_for_site(site) }

    before do
      File.write('content/hello.md', 'Hello!')
      File.write('layouts/default.erb', '<title>MY SITE!</title><%= yield %>')
    end

    let(:site) do
      Nanoc::Int::SiteLoader.new.new_from_cwd
    end

    it 'returns views' do
      expect(subject[:items]).to be_a(Nanoc::ItemCollectionWithRepsView)
      expect(subject[:layouts]).to be_a(Nanoc::LayoutCollectionView)
      expect(subject[:config]).to be_a(Nanoc::ConfigView)
    end

    it 'returns correct items' do
      expect(subject[:items].size).to eq(1)
      expect(subject[:items].first.identifier.to_s).to eq('/hello.md')
    end

    it 'returns correct layouts' do
      expect(subject[:layouts].size).to eq(1)
      expect(subject[:layouts].first.identifier.to_s).to eq('/default.erb')
    end

    it 'returns items with reps' do
      expect(subject[:items].first.reps).not_to be_nil
      expect(subject[:items].first.reps.first.name).to eq(:default)
    end

    it 'returns items with rep paths' do
      expect(subject[:items].first.reps.first.path).to eq('/hello.md')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-4.7.10 spec/nanoc/cli/commands/shell_spec.rb