Sha256: 8ffd30fd0fe46b117c5b3c0a4b7453073449f550df294e5bba1f1efd6b5dfcb0
Contents?: true
Size: 1.72 KB
Versions: 7
Compression:
Stored size: 1.72 KB
Contents
require 'spec_helper' require 'collection' require 'rexml/document' Dir["#{File.dirname(__FILE__)}/tables/**/*.rb"].each {|file| require file } describe 'CSVTableSpec' do before do @cars = CarWithHumanAttributeName.collection @presenter = DiningTable::Presenters::CSVPresenter.new end it "correctly renders a basic table" do csv = CarTable.new(@cars, nil, :presenter => @presenter).render data = CSV.parse(csv) check_data( data ) end it "respects csv options" do @presenter = DiningTable::Presenters::CSVPresenter.new( :csv => { :col_sep => ';' } ) csv = CarTable.new(@cars, nil, :presenter => @presenter).render data = CSV.parse(csv) data.first.length.must_equal 1 # wrongly parsed due to using comma as a separator data = CSV.parse(csv, :col_sep => ';') check_data( data ) end it "respects global csv options" do DiningTable.configure do |config| config.csv_presenter.default_options = { :csv => { :col_sep => ';' } } end @presenter = DiningTable::Presenters::CSVPresenter.new csv = CarTable.new(@cars, nil, :presenter => @presenter).render data = CSV.parse(csv) data.first.length.must_equal 1 # wrongly parsed due to using comma as a separator data = CSV.parse(csv, :col_sep => ';') check_data( data ) # reset configuration for other specs DiningTable.configure do |config| config.csv_presenter.default_options = { } end end def check_data( data ) data.first.must_equal ["Brand", "Type", "Number of doors", "Stock"] @cars.each_with_index do |car, index| line = [ :brand, :type, :number_of_doors, :stock ].map do |item| car.send(item).to_s end data[index + 1].must_equal line end end end
Version data entries
7 entries across 7 versions & 1 rubygems