Sha256: ca9904483578b95b73be52000be1696c0db186a56d14974bb7067d572a6a0ceb

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

module GoogleDataSource
  # Some usefull helpers for testing datasources
  module TestHelper

    # Returns the parsed JSON argument of the datasource response
    def datasource_response
      first_cmd = @response.body.match(/([^;"]*|"(\\"|[^"])*;?(\\"|[^"])*")*;/)[0]
      response = OpenStruct.new(JSON.parse(first_cmd.match(/^[^(]*\((.*)\);$/)[1]))
      response.table = OpenStruct.new(response.table)
      response
    end

    # Returns the columns array of the JSON response
    def datasource_column(column)
      response = datasource_response
      column_no = response.table.cols.collect { |c| c['id'] }.index(column.to_s)
      response.table.rows.collect { |r| r['c'][column_no] }
    end

    # Returns the column ids of the JSON response
    def datasource_column_ids
      datasource_response.table.cols.collect { |c| c['id'] }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
google_data_source-0.7.6 lib/google_data_source/test_helper.rb