require 'xing/specdoc/document' require 'xing/specdoc/winnower' describe Xing::SpecDoc::Winnower do subject :winnower do Xing::SpecDoc::Winnower.new(new_docs, old_docs) end let :first_content do { "a" => "a" }.to_json end let :second_content do { "something" => "else" }.to_json end let :third_content do { "something_completely" => "else" }.to_json end let :new_docs do new_contents.each_with_index.map do |content, index| Xing::SpecDoc::Document.new("new_path_#{index}", content) end end let :old_docs do old_contents.each_with_index.map do |content, index| Xing::SpecDoc::Document.new("old_path_#{index}", content) end end let :old_paths do old_docs.map(&:path) end let :new_contents do [] end let :old_contents do [] end context "should reduce extraneous new docs" do let :new_contents do [ first_content, first_content, first_content ] end it "should strip the extras" do expect(winnower.kept_new.length).to eq(1) end it "should not invent obsoletes" do expect(winnower.obsolete_paths.length).to eq(0) end end context "should prefer existing docs" do let :new_contents do [ first_content ] end let :old_contents do [ first_content ] end it "should strip the duplicate new docs" do expect(winnower.kept_new.length).to eq(0) end it "should not consider incumbents obsolete" do expect(winnower.obsolete_paths.length).to eq(0) end end context "should consider old docs without support obsolete" do let :new_contents do [ first_content ] end let :old_contents do [ second_content ] end it "should strip the duplicate new docs" do expect(winnower.kept_new.length).to eq(1) end it "should not consider incumbents obsolete" do expect(winnower.obsolete_paths.length).to eq(1) end end context "whole set up" do let :new_contents do [ first_content, second_content ] end let :old_contents do [ second_content, third_content ] end it "should strip the duplicate new docs" do expect(winnower.kept_new.length).to eq(1) end it "should not consider incumbents obsolete" do expect(winnower.obsolete_paths.length).to eq(1) end end end