Sha256: bece2281318383aed740232b0d36223f516d09fa4f904a4913a9816cdb654a85

Contents?: true

Size: 1.95 KB

Versions: 15

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodDefinition::ParameterBuilder do
  describe '.from' do
    let(:parameters)       { nil }
    let(:named_parameters) { nil }

    context 'when parameters and named_parameters are nil' do
      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('')
      end
    end

    context 'when parameters is empty' do
      let(:parameters) { [] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('')
      end
    end

    context 'when named_parameters is empty' do
      let(:named_parameters) { [] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('')
      end
    end

    context 'when parameters has no default values' do
      let(:parameters) { %i[x y] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('(x, y)')
      end
    end

    context 'when named_parameters has no default values' do
      let(:named_parameters) { %i[x y] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('(x:, y:)')
      end
    end

    context 'when parameters has only default values' do
      let(:parameters) { [{ x: 1, y: 3 }] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('(x = 1, y = 3)')
      end
    end

    context 'when named parameters has only default values' do
      let(:named_parameters) { [{ x: 1, y: 3 }] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('(x: 1, y: 3)')
      end
    end

    context 'when all options are present' do
      let(:parameters) { [:x, { y: 2 }] }
      let(:named_parameters) { [:a, { b: 3 }] }

      it do
        expect(described_class.from(parameters, named_parameters))
          .to eq('(x, y = 2, a:, b: 3)')
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-2.1.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-2.0.1 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-2.0.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.16.3 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.16.2 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.16.1 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.16.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.15.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.14.2 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.14.1 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.14.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.13.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.12.1 spec/lib/sinclair/method_definition/parameter_builder_spec.rb
sinclair-1.12.0 spec/lib/sinclair/method_definition/parameter_builder_spec.rb