1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
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(:args) do
{
report_path: 'knapsack_new_report.json',
fake: true
}
end
it do
expect(report.config(args)).to eql({
report_path: 'knapsack_new_report.json',
fake: true
})
end
end
context "when didn't pass options" do
it { expect(report.config).to eql({}) }
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 #{report_path} doesn't exist. Please generate report first!")
end
end
end
end
|