# encoding: utf-8 require 'spec_helper' describe "./bin/quandl upload" do let(:prefix){ "upload" } let(:command){ self.class.superclass.description } subject{ quandl( [prefix, command].flatten.join(" ") ) } context data_path("datasets.qdf") do its(:stdout){ should match /Updated|Created/ } its(:stderr){ should be_blank } end context data_path("metadata.qdf") do its(:stdout){ should match /Updated|Created/ } its(:stderr){ should be_blank } end context data_path("QUGC-42.qdf") do its(:stdout){ should match /Updated|Created/ } its(:stderr){ should be_blank } end context error_path("invalid_code.qdf") do its(:stdout){ should match /Unprocessable Entity/ } end context error_path("column_count_mismatch.qdf") do its(:stdout){ should match /Found 4 but expected 3 based on/ } end context error_path("date_parse_error.qdf") do its(:stdout){ should match /Invalid date segments/ } end context error_path("invalid_date.qdf") do its(:stdout){ should match /Invalid date/ } end context error_path("invalid_dash.qdf") do its(:stdout){ should match /Unprocessable Entity | Error | Psych::SyntaxError | Error parsing metadata. Could not find expected ':' on line 3./ } end context error_path("psych.qdf") do its(:stdout){ should match /Could not find expected ':'/ } end context error_path("unknown_attribute.qdf") do its(:stdout){ should match /UnknownAttribute/ } end context "json" do let(:prefix){ "upload" } let(:command){ self.class.superclass.description } subject{ result = quandl( [prefix, command, "-F json"].flatten.join(" ") ) OpenStruct.new( stdout: result.stdout, stderr: result.stderr, stdout_json: result.stdout.split("\n").collect{|l| JSON.parse(l) }, ) } context data_path("metadata.qdf") do its(:stderr){ should be_blank } its(:stdout_json){ should be_a Array } its('stdout_json.first'){ should have_key 'status' } its('stdout_json.first'){ should have_key 'id' } its('stdout_json.first'){ should have_key 'detail' } its('stdout_json.first'){ should have_key 'message' } its('stdout_json.first'){ should have_key 'attributes' } end context error_path("unknown_attribute.qdf") do its('stdout_json.first'){ should have_key 'status' } its('stdout_json.first'){ should have_key 'id' } its('stdout_json.first'){ should have_key 'detail' } its('stdout_json.first'){ should have_key 'message' } its(:stdout_json){ should eq([{"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_2 error around line 13\nUnknown Field 'this_attribute_does_not_exist' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}, {"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_3 error around line 25\nUnknown Field 'horse' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}, {"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_4 error around line 37\nUnknown Field 'mouse' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}]) } end end end