Sha256: fb74dd36cd7d760d81a107318b757791fd68cd8344373c9b8d9327024242c6a0

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

# comma do
#   name 'Title'
#   description
#
#   isbn :number_10 => 'ISBN-10', :number_13 => 'ISBN-13'
# end

describe Comma::HeaderExtractor do # rubocop:disable Metrics/BlockLength
  before do
    @isbn = Isbn.new('123123123', '321321321')
    @book = Book.new('Smalltalk-80', 'Language and Implementation', @isbn)

    @headers = @book.to_comma_headers
  end

  describe 'when no parameters are provided' do
    it 'should use the method name as the header name, humanized' do
      expect(@headers).to include('Description')
    end
  end

  describe 'when given a string description as a parameter' do
    it 'should use the string value, unmodified' do
      expect(@headers).to include('Title')
    end
  end

  describe 'when an hash is passed as a parameter' do
    describe 'with a string value' do
      it 'should use the string value, unmodified' do
        expect(@headers).to include('ISBN-10')
      end
    end

    describe 'with a non-string value' do
      it 'should use the non string value converted to a string, humanized' do
        expect(@headers).to include('Issuer')
      end
    end
  end
end

describe Comma::HeaderExtractor, 'with static column method' do
  before do
    @headers = Class.new(Struct.new(:id, :name)) do
      comma do
        __static_column__
        __static_column__ 'STATIC'
        __static_column__ 'STATIC' do '' end
      end
    end.new(1, 'John Doe').to_comma_headers
  end

  it 'should extract headers' do
    expect(@headers).to eq(['', 'STATIC', 'STATIC'])
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
comma-4.8.0 spec/comma/header_extractor_spec.rb
comma-4.7.0 spec/comma/header_extractor_spec.rb
comma-4.6.0 spec/comma/header_extractor_spec.rb
comma-4.5.0 spec/comma/header_extractor_spec.rb
comma-4.4.0 spec/comma/header_extractor_spec.rb