Permalink
Browse files

Config specs

  • Loading branch information...
1 parent 277c25c commit cd9c44ec08018b086e51d7b4953cec781f70c80d @paulspringett committed Aug 18, 2012
Showing with 31 additions and 5 deletions.
  1. +24 −5 spec/config_spec.rb
  2. +7 −0 spec/encoder_spec.rb
View
@@ -1,11 +1,30 @@
require 'spec_helper'
describe CsvShaper::Config do
- it "should assign options to config" do
- config = CsvShaper::Config.new do |c|
+ let(:config) {
+ CsvShaper::Config.new do |c|
c.write_headers = false
- c.col_sep = '\t'
+ c.col_sep = "\t"
+ end
+ }
+
+ it "should assign options to config" do
+ config.options.should eq({ write_headers: false, col_sep: "\t" })
+ end
+
+ it "should exclude the headers if specified" do
+ CsvShaper::Shaper.config = config
+
+ shaper = CsvShaper::Shaper.new do |csv|
+ csv.headers :name, :age, :gender
+
+ csv.row do |csv|
+ csv.cell :name, 'Paul'
+ csv.cell :age, '27'
+ csv.cell :gender, 'Male'
+ end
end
- config.options.should eq({ write_headers: false, col_sep: '\t' })
- end
+
+ shaper.to_csv.should eq "Paul\t27\tMale\n"
+ end
end
View
@@ -4,6 +4,12 @@
describe CsvShaper::Encoder do
let(:user) { User.new(name: 'Paul', age: 27, gender: 'Male') }
+ let(:config) {
+ CsvShaper::Config.new do |c|
+ c.write_headers = true
+ end
+ }
+
it "should raise an exception if the headers are missing" do
expect {
CsvShaper::Encoder.new(nil)
@@ -30,6 +36,7 @@
}
it "should encode a Shaper instance to a CSV string" do
+ CsvShaper::Shaper.config = config
encoder = CsvShaper::Encoder.new(csv.header, csv.rows)
encoder.to_csv.should eq("Full name,Sex,Age\nPaul,Male,27\nBob,Male,31\nJane,Female,23\n,,81\n")
end

0 comments on commit cd9c44e

Please sign in to comment.