spec/lib/quandl/operation/qdformat_spec.rb in quandl_operation-0.1.18 vs spec/lib/quandl/operation/qdformat_spec.rb in quandl_operation-0.1.19

- old
+ new

@@ -2,64 +2,74 @@ require 'quandl/operation/qdformat' require 'spec_helper' describe Quandl::Operation::QDFormat do - let(:full_code){ "SOURCE_CODE/DATASET_CODE" } - let(:name){ 'name: Test dataset name' } - let(:description){ 'description: Dataset description' } - let(:headers){ 'headers: Date, value, high, low' } - let(:data){ "2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353\n2013-11-19,10.039388096885814,,14.09718770934256\n2013-11-18,10.03702588792184,11.040801329322205,14.148600982164867\n2013-11-16,10.019903902583621,10.99988541851354,14.186053161235304\n2013-11-15,9.98453953586862,10.922239168500502,\n2013-11-14,10.004508614940358,10.894612328250766,\n2013-11-13,,10.877309120435308,14.187437960548612\n2013-11-12,,10.838918617657301,14.22499294338536\n2013-11-11,9.965116185761039,10.827442115591547,14.178970907392053\n2013-11-09,9.881291973139637,10.924889094631869" } - - let(:output){ + let(:qdf_dataset){ %Q{ - --- - #{full_code} - #{name} - #{description} - #{headers} - #{data} - - - - I am a comment. - - - #{full_code} - #{name} - #{description} - #{headers} - #{data} - ----- + # YAML metadata + code: DATASET_CODE + source_code: SOURCE_CODE + name: Test Dataset Name 1 + description: Here is a description with multiple lines.\\n This is the second line. + # CSV data + Date, Value, High, Low + 2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353 + 2013-11-19,10.039388096885814,,14.09718770934256 + + # Second dataset + code: DATASET_CODE_2 + source_code: SOURCE_CODE_2 + name: Test Dataset Name 2 + description: Here is a description with multiple lines. + # CSV data + Date, Value, High, Low + 2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353 + 2013-11-19,10.039388096885814,,14.09718770934256 + 2013-11-18,11.039388096885814,,15.09718770934256 } } - let(:collection){ Quandl::Operation::QDFormat.parse(output) } - describe ".parse" do + let(:collection){ Quandl::Operation::QDFormat.load(qdf_dataset) } + + describe ".load" do subject{ collection } - + its(:count){ should eq 2 } describe "#first" do subject{ collection.first } - it{ should be_a Quandl::Operation::QDFormat } + it{ should be_a Quandl::Operation::QDFormat::Node } its(:source_code){ should eq 'SOURCE_CODE' } its(:code){ should eq 'DATASET_CODE' } - its(:name){ should eq 'Test dataset name' } - its(:description){ should eq 'Dataset description' } - its(:headers){ should eq ['Date', 'value', 'high', 'low'] } - its(:data){ should eq data } + its(:name){ should eq 'Test Dataset Name 1' } + its(:description){ should eq 'Here is a description with multiple lines.\n This is the second line.' } + its(:column_names){ should eq ['Date', 'Value', 'High', 'Low'] } + its(:data){ should eq [ + ["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"], + ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]] } end end describe "#to_qdf" do subject{ collection.first } - its(:to_qdf){ should eq [full_code, name, description, headers, data].join("\n")} + its(:to_qdf){ should eq %Q{source_code: SOURCE_CODE +code: DATASET_CODE +name: Test Dataset Name 1 +description: Here is a description with multiple lines.\\n This is the second line. +Date,Value,High,Low +2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353 +2013-11-19,10.039388096885814,,14.09718770934256 +}} + context "data Array" do let(:data){ [['2013-11-20',9.94,11.2],['2013-11-19',9.94,11.2],['2013-11-18',9.94,11.2]] } - subject{ Quandl::Operation::QDFormat.new( full_code: "TEST/OIL", data: data ) } + subject{ Quandl::Operation::QDFormat::Node.new( full_code: "TEST/OIL", data: data ) } - its(:to_qdf){ should eq ["TEST/OIL", data.collect(&:to_csv).join].join("\n") } + its(:to_qdf){ should eq "source_code: TEST\ncode: OIL\n2013-11-20,9.94,11.2\n2013-11-19,9.94,11.2\n2013-11-18,9.94,11.2\n" } end end end \ No newline at end of file