# encoding: utf-8 require 'spec_helper' require 'fedux_org_stdlib/project/report' require 'fedux_org_stdlib/filesystem' RSpec.describe FeduxOrgStdlib::Project::Report do before :each do touch_file('plan.tjp') touch_file('reports/Overview.html') end let(:plan_file) { absolute_path('plan.tjp') } let(:report_file) { absolute_path('reports/Overview.html') } context '#generate' do it 'generates report' do plan = double('Plan') allow(plan).to receive(:to_s).and_return(plan_file) expect(plan).to receive(:needs_to_be_compiled?).with(report_file).and_return(true) generator = double('Generator') expect(generator).to receive(:generate_report) report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file) report.generate end it 'generates report only if plan file is newer than output file' do FileUtils.touch report_file, mtime: Time.now - 2.hours plan = double('Plan') allow(plan).to receive(:to_s).and_return(plan_file) expect(plan).to receive(:needs_to_be_compiled?).with(report_file).and_return(true) generator = double('Generator') expect(generator).to receive(:generate_report).once in_current_dir do report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file) report.generate end end it 'does not generate report if plan file is older or of eqal age than output file' do FileUtils.touch plan_file, mtime: Time.now - 2.hours plan = double('Plan') expect(plan).to receive(:needs_to_be_compiled?).with(report_file).and_return(false) generator = double('Generator') expect(generator).not_to receive(:generate_report) in_current_dir do report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file) silence(:stderr) do report.generate end end end end context '#open' do it 'can open a report in a browser' do plan = double('Plan') generator = double('Generator') report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file) expect(report).to respond_to :open end end end