Sha256: 47a167d2b9680b5440b05dccb0fb9a263668d7cacace5ca8d03c9766ed97c033

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

describe Knapsack::Report do
  let(:report) { described_class.send(:new) }
  let(:report_path) { 'tmp/fake_report.json' }
  let(:report_json) do
    %Q[{"a_spec.rb": #{rand(Math::E..Math::PI)}}]
  end

  describe '#config' do
    context 'when passed options' do
      let(:opts) do
        {
          report_path: 'new_knapsack_report.json',
          fake: true
        }
      end

      it do
        expect(report.config(opts)).to eql({
          report_path: 'new_knapsack_report.json',
          fake: true
        })
      end
    end

    context "when didn't pass options" do
      it do
        expect(report.config).to eql({
          report_path: 'knapsack_report.json'
        })
      end
    end
  end

  describe '#save', :clear_tmp do
    before do
      expect(report).to receive(:report_json).and_return(report_json)
      report.config({
        report_path: report_path
      })
      report.save
    end

    it { expect(File.read(report_path)).to eql report_json }
  end

  describe '.open' do
    let(:subject) { report.open }

    before do
      report.config({
        report_path: report_path
      })
    end

    context 'when report file exists' do
      before do
        expect(File).to receive(:read).with(report_path).and_return(report_json)
      end

      it { should eql(JSON.parse(report_json)) }
    end

    context "when report file doesn't exist" do
      let(:report_path) { 'tmp/non_existing_report.json' }

      it do
        expect {
          subject
        }.to raise_error("Knapsack report file doesn't exist. Please generate report first!")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
knapsack-0.5.0 spec/knapsack/report_spec.rb
knapsack-0.4.0 spec/knapsack/report_spec.rb
knapsack-0.3.0 spec/knapsack/report_spec.rb
knapsack-0.2.0 spec/knapsack/report_spec.rb
knapsack-0.1.4 spec/knapsack/report_spec.rb
knapsack-0.1.3 spec/knapsack/report_spec.rb
knapsack-0.1.2 spec/knapsack/report_spec.rb
knapsack-0.1.1 spec/knapsack/report_spec.rb
knapsack-0.1.0 spec/knapsack/report_spec.rb