Sha256: 44e0719ca8a2473d27e1f2cbe5c2936e51cb1a92e41d99d84c727b8f79c9e960

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Kitabu::Cli, "while running stats" do
  let(:root_dir) { SPECDIR.join("support/mybook") }
  before { Dir.chdir(root_dir) }

  it "recognizes command" do
    expect do
      capture(:stdout) { Kitabu::Cli.start(["stats"]) }
    end.to_not raise_error
  end

  it "initializes stats with root dir" do
    expect(Kitabu::Stats)
      .to receive(:new)
      .with(root_dir)
      .and_return(double.as_null_object)

    capture(:stdout) { Kitabu::Cli.start(["stats"]) }
  end

  context "outputting stats" do
    let(:stats) do
      double("stats", {
               chapters: 4,
               words: 50,
               images: 10,
               footnotes: 15,
               links: 20,
               code_blocks: 25
             })
    end

    before do
      allow(Kitabu::Stats).to receive_message_chain(:new).and_return(stats)
    end

    subject(:output) do
      capture(:stdout) { Kitabu::Cli.start(["stats"]) }
    end

    it { expect(output).to include("Chapters: 4") }
    it { expect(output).to include("Words: 50") }
    it { expect(output).to include("Images: 10") }
    it { expect(output).to include("Footnotes: 15") }
    it { expect(output).to include("Links: 20") }
    it { expect(output).to include("Code blocks: 25") }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kitabu-3.1.0 spec/kitabu/cli/stats_spec.rb
kitabu-3.0.3 spec/kitabu/cli/stats_spec.rb
kitabu-3.0.2 spec/kitabu/cli/stats_spec.rb
kitabu-3.0.1 spec/kitabu/cli/stats_spec.rb
kitabu-3.0.0 spec/kitabu/cli/stats_spec.rb