Sha256: 29a88be520d444ef5394101c9a984a953f8504904bc0edd0a394fb93fe862587
Contents?: true
Size: 1.96 KB
Versions: 5
Compression:
Stored size: 1.96 KB
Contents
# require 'spec_helper' class DummyClass end describe "#identify_delimiter" do before(:each) do @dummy_class = DummyClass.new @dummy_class.extend(CsvImportAnalyzer::DelimiterIdentifier) end context "unable to determine the delimiter" do it "return invalid input when the input is neither string nor array" do expect(@dummy_class.identify_delimiter(3)).to be_instance_of(InvalidInput) end it "returns file not found when the input string is not a valid file" do expect(@dummy_class.identify_delimiter("test")).to be_instance_of(FileNotFound) end end context "finds the delimiter when the input is a file" do it "returns a comma as the delimiter for sample_csv file" do expect(@dummy_class.identify_delimiter($sample_csv_path)).to eq(",") end it "returns a semicolon as the the delimiter for sample_ssv file" do expect(@dummy_class.identify_delimiter($sample_ssv_path)).to eq(";") end end context "finds the delimiter when the input is an array" do let(:sample) {['1999;Chevy;"Venture ""Extended Edition""";"";4900.00','1999;\'Chevy\';"Venture ""Extended Edition; Very Large""";;5000.00']} it "returns a semicolon as the delimiter for sample array input" do expect(@dummy_class.identify_delimiter(sample)).to eq(";") end end end # Testing private method, although we don't really have to describe "#return_plausible_delimiter" do before(:each) do @dummy_class = DummyClass.new @dummy_class.extend(CsvImportAnalyzer::DelimiterIdentifier) end context "identifies delimiter" do it "returns comma as the delimiter by default" do expect(@dummy_class.send(:return_plausible_delimiter)).to eq(",") end it "returns semicolon as the delimiter for sample delimiter_count" do @dummy_class.stub(:delimiter_count).and_return(Hash[","=>15, ";"=>16, "\t"=>0, "|"=>0]) expect(@dummy_class.send(:return_plausible_delimiter)).to eq(";") end end end
Version data entries
5 entries across 5 versions & 1 rubygems