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.63.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.62.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.62.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.61.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.61.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.60.3 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.60.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.60.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.60.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.59.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.58.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.57.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.56.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.56.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.7 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.6 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.5 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.4 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.3 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
eac_tools-0.55.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb