Sha256: ac1f0f17b081de25e33841b8092da67b5fe8c96763c758adca67601e84bb3257

Contents?: true

Size: 1.38 KB

Versions: 252

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/custom_format'

class StubObjectData
  def x_value
    'X1'
  end

  def y_value
    'Y1'
  end
end

RSpec.describe ::EacRubyUtils::CustomFormat do
  let(:instance) { described_class.new(x: :x_value, y: :y_value, z: :unexistent) }
  let(:ok_format) { instance.format('|%%|%y|%x|%y|') } # rubocop:disable Style/FormatStringToken
  let(:ok_string_expected) { '|%|Y1|X1|Y1|' }
  let(:fail_format) { instance.format('|%z|') }

  it do
    expect(ok_format.sequences).to include(:x, :y)
  end

  it do
    expect(fail_format.sequences).to include(:z)
  end

  context 'when object source is a hash' do
    let(:object_source) { { x_value: 'X1', y_value: 'Y1' } }

    context 'when hash has all keys' do
      it do
        expect(ok_format.with(object_source)).to eq(ok_string_expected)
      end
    end

    context 'when hash has not all keys' do
      it do
        expect(fail_format.with(object_source)).to eq('||')
      end
    end
  end

  context 'when object source is not a hash' do
    let(:object_source) { ::StubObjectData.new }

    context 'when object has all methods' do
      it do
        expect(ok_format.with(object_source)).to eq(ok_string_expected)
      end
    end

    context 'when object has not all methods' do
      it do
        expect { fail_format.with(object_source) }.to raise_error(::ArgumentError)
      end
    end
  end
end

Version data entries

252 entries across 252 versions & 3 rubygems

Version Path
eac_tools-0.76.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.76.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.75.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.75.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.75.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.74.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.74.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.73.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.72.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.70.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.70.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.69.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.69.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.68.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.67.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.67.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.66.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.65.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.65.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.64.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb