Sha256: b2a6ad56a58090a1a81ef2c5ec6baf57f472f90de37fa31ab7b91b682e7e1687

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require_relative '../spec_helper'

describe ResultSet do

  let(:crate_result) { "{\"cols\":[\"my_column\",\"my_integer_col\"],\"rows\":[[\"Foo\",5],[\"Bar\",5]],\"rowcount\":1,\"duration\":4}" }

  let(:result_set) { ResultSet.new(crate_result) }

  let(:json_result) { JSON.parse crate_result }

  describe '#initialize' do


    it 'should set rowcount' do
      result_set.rowcount.should eq 1
    end

    it 'should set duration' do
      result_set.duration.should eq 4
    end

     it 'should set cols' do
      result_set.cols.should eq json_result['cols']
    end

  end

  describe '#each' do
    it 'should loop over the result rows' do
      result_set.each_with_index do |r, i|
        r.should eq json_result['rows'][i]
      end
    end
  end

  describe '#[]' do
    it 'should return the row at index' do
      result_set[1][0].should eq('Bar')
    end
  end

  describe '#values_at' do
    it 'should only return the columns specified' do
      a = []
      result_set.select_columns(['my_column']) do |res|
        a << res
      end
      a.should eq [["Foo"], ["Bar"]]

    end
    it 'should not raise error on invalid column name' do
      expect do
        result_set.select_columns(['my_column', 'invalid']) do |row|
        end
      end.to_not raise_error
    end
  end

end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crate_ruby-0.0.2 spec/crate_ruby/result_set_spec.rb
crate_ruby-0.0.1 spec/crate_ruby/result_set_spec.rb