spec/fbo/parser_spec.rb in fbo-0.0.3 vs spec/fbo/parser_spec.rb in fbo-0.1.0

- old
+ new

@@ -1,54 +1,52 @@ require 'spec_helper' describe FBO::Parser do - subject { FBO::Parser.new(file) } - let(:file) { File.new(filename) } - let!(:notices) { subject.notices } + context 'a single data String' do + let(:contents) { "<PRESOL>\n</PRESOL>\n<COMBINE>\n</COMBINE>\n<AMDCSS>\n</AMDCSS>\n" } + let(:file) { stub('FBO::File', contents: contents) } + subject { FBO::Parser.new(file) } - - tag_to_name_map = { - amdcss: "Amendment", archive: "Archive", award: "Award", - combine: "Combined Solicitation", fairopp: "Fair Opportunity", - fstd: "Foreign Standard", itb: "Intent to Bundle", - ja: "Justification Approval", mod: "Modification", - presol: "Presolicitation", ssale: "Sale of Surplus", - srcsgt: "Sources Sought", snote: "Special Notice", - unarchive: "Unarchive" } - - tag_to_name_map.each do |tag, name| - notice_class_name = name.split.map { |w| w.capitalize }.join - notice_class = Kernel.const_get("FBO::Notices::#{ notice_class_name }") - - context "a file containing a #{ name } notice" do - let(:filename) { File.join(File.dirname(__FILE__), "..", "fixtures", "notices", tag.to_s) } - - it "should return an array with a single #{ notice_class_name }" do - notices.count.should eq 1 - notices[0].should be_an_instance_of(notice_class) - end + it 'parses the data all at once' do + subject.expects(:parse_string).with(file.contents) + subject.parse end - end - context "a file containing any other type of notice" do - let(:filename) { File.join(File.dirname(__FILE__), "..", "fixtures", "notices", "notanotice") } + it 'returns a tree representing all notices' do + tree = subject.parse + tree.must_be_instance_of FBO::Dump::DumpNode - it "should return an array with a single Unknown notice" do - notices.count.should eq 1 - notices[0].should be_an_instance_of(FBO::Notices::Unknown) + notice_types = tree.elements.map { |e| e.class.name }.sort + notice_types.must_equal [ 'FBO::Dump::AmendmentNode', + 'FBO::Dump::CombinedSolicitationNode', + 'FBO::Dump::PresolicitationNode' ] end end - context "a file containing a bunch of notices" do - let(:filename) { File.join(File.dirname(__FILE__), "..", "fixtures", "FBOFeed20130406") } + context 'a collection of data Strings' do + let(:contents) { [ '<PRESOL></PRESOL>', '<COMBINE></COMBINE>', '<AMDCSS></AMDCSS>' ] } + let(:file) { stub('FBO::ChunkedFile', contents: contents) } + subject { FBO::Parser.new(file) } - it "should return an array containing notice objects" do - notices.each { |notice| notice.should be_a_kind_of(FBO::Notice) } + it 'parses the collection' do + subject.expects(:parse_collection).with(contents) + subject.parse end - it "should return 679 Notices (which really is a lot)" do - notices.count.should eq 679 + it 'parses each data chunk individually' do + contents.each do |string| + subject.expects(:parse_string).with(string) + end + subject.parse end - end + it 'returns a unified tree representing all notices' do + tree = subject.parse + tree.must_be_instance_of FBO::Dump::DumpNode + notice_types = tree.elements.map { |e| e.class.name }.sort + notice_types.must_equal [ 'FBO::Dump::AmendmentNode', + 'FBO::Dump::CombinedSolicitationNode', + 'FBO::Dump::PresolicitationNode' ] + end + end end