Sha256: cd05ce790b3f7e173d65d56de1640f89581654973719627a44c30f08239f8fbe

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodDefinition::ParameterHelper do
  describe '.parameters_from' do
    context 'when parameters are not named' do
      context 'when there are no defaults' do
        it 'returns a list of parameters' do
          expect(described_class.parameters_from(%i[a b]))
            .to eq(%w[a b])
        end
      end

      context 'when there are defaults' do
        let(:parameters) do
          [{ a: 10, b: 'word', c: true, d: false, e: nil, f: :symbol }]
        end

        it 'returns a list of parameters' do
          expect(described_class.parameters_from(parameters))
            .to eq(['a = 10', 'b = "word"', 'c = true', 'd = false', 'e = nil', 'f = :symbol'])
        end
      end
    end

    context 'when parameters are named' do
      context 'when there are no defaults' do
        it 'returns a list of parameters' do
          expect(described_class.parameters_from(%i[a b], named: true))
            .to eq(%w[a: b:])
        end
      end

      context 'when there are defaults' do
        let(:parameters) do
          [{ a: 10, b: 'word', c: true, d: false, e: nil, f: :symbol }]
        end

        it 'returns a list of parameters' do
          expect(described_class.parameters_from(parameters, named: true))
            .to eq(['a: 10', 'b: "word"', 'c: true', 'd: false', 'e: nil', 'f: :symbol'])
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinclair-1.14.0 spec/lib/sinclair/method_definition/parameter_helper_spec.rb
sinclair-1.13.0 spec/lib/sinclair/method_definition/parameter_helper_spec.rb