spec/bumblebee/template_spec.rb in bumblebee-3.0.1 vs spec/bumblebee/template_spec.rb in bumblebee-3.1.0.pre.alpha
- old
+ new
@@ -9,19 +9,19 @@
require 'spec_helper'
require 'examples/person_template'
require 'examples/simple_object'
-describe ::Bumblebee::Template do
+describe Bumblebee::Template do
describe 'array/string-based columns and symbol based object keys' do
let(:data_objects) { yaml_fixture('simple', 'data.yml').map(&:symbolize_keys) }
let(:csv_file) { fixture('simple', 'data.csv') }
let(:columns) { yaml_fixture('simple', 'columns.yml') }
- subject { ::Bumblebee::Template.new(columns: columns) }
+ subject { Bumblebee::Template.new(columns: columns) }
specify '#generate_csv properly builds a CSV-formatted string' do
actual = subject.generate(data_objects)
expect(actual).to eq(csv_file)
@@ -43,11 +43,11 @@
let(:csv_file) { fixture('simple', 'data.csv') }
let(:columns) { yaml_fixture('simple', 'columns.yml') }
- subject { ::Bumblebee::Template.new(columns: columns, object_class: OpenStruct) }
+ subject { Bumblebee::Template.new(columns: columns, object_class: OpenStruct) }
specify '#generate_csv properly builds a CSV-formatted string' do
actual = subject.generate(data_objects)
expect(actual).to eq(csv_file)
@@ -67,11 +67,11 @@
let(:csv_file) { fixture('simple', 'data.csv') }
let(:columns) { yaml_fixture('simple', 'columns.yml') }
- subject { ::Bumblebee::Template.new(columns: columns, object_class: SimpleObject) }
+ subject { Bumblebee::Template.new(columns: columns, object_class: SimpleObject) }
specify '#generate_csv properly builds a CSV-formatted string' do
actual = subject.generate(data_objects)
expect(actual).to eq(csv_file)
@@ -89,11 +89,11 @@
let(:csv_file) { fixture('registrations', 'data.csv') }
let(:columns) { yaml_fixture('registrations', 'columns.yml') }
- subject { ::Bumblebee::Template.new(columns: columns) }
+ subject { Bumblebee::Template.new(columns: columns) }
specify '#generate_csv properly builds a CSV-formatted string' do
actual = subject.generate(data_objects)
expect(actual).to eq(csv_file)
@@ -112,11 +112,11 @@
let(:csv_file) { fixture('registrations', 'data.csv') }
let(:columns) { yaml_fixture('registrations', 'columns.yml') }
subject do
- ::Bumblebee::Template.new do |t|
+ Bumblebee::Template.new do |t|
columns.each do |header, opts|
t.column(header, opts)
end
end
end
@@ -138,11 +138,11 @@
let(:data_objects) { yaml_fixture('registrations', 'data.yml') }
let(:csv_file) { fixture('registrations', 'data.csv') }
subject do
- ::Bumblebee::Template.new do
+ Bumblebee::Template.new do
columns = yaml_fixture('registrations', 'columns.yml')
columns.each do |header, opts|
column(header, opts)
end
end
@@ -178,9 +178,35 @@
specify '#parse_csv properly builds objects' do
template = PersonTemplate.new
actual = template.parse(csv_file)
+
+ expect(actual).to eq(data_objects)
+ end
+ end
+
+ describe 'UTF-8 Byte Order Mark (BOM) support' do
+ let(:data_objects) { yaml_fixture('simple', 'data.yml').map(&:symbolize_keys) }
+
+ let(:csv_file) { fixture('simple', 'data.csv') }
+
+ let(:columns) { yaml_fixture('simple', 'columns.yml') }
+
+ subject { Bumblebee::Template.new(columns: columns) }
+
+ specify '#generate_csv includes BOM' do
+ actual = subject.generate(data_objects, bom: true)
+
+ expect(actual).to start_with("\xEF\xBB\xBF")
+ end
+
+ specify '#parse excludes BOM' do
+ utf8_string_with_bom = "\xEF\xBB\xBF#{csv_file}"
+
+ expect(utf8_string_with_bom.encoding).to eq(Encoding::UTF_8)
+
+ actual = subject.parse(utf8_string_with_bom).map(&:symbolize_keys)
expect(actual).to eq(data_objects)
end
end
end