Sha256: 75eef3fa0e2b6136bcf64adb3029f429f92be715b7387a91761ee9f977585a73

Contents?: true

Size: 1.32 KB

Versions: 31

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodBuilder::BlockMethodBuilder do
  describe '#build' do
    subject(:builder) do
      described_class.new(klass, definition, type: type)
    end

    let(:klass)       { Class.new }
    let(:instance)    { klass.new }
    let(:value)       { Random.rand }
    let(:method_name) { :the_method }

    let(:definition) do
      result = value
      Sinclair::MethodDefinition.from(method_name) { result }
    end

    context 'when type is instance' do
      let(:type) { Sinclair::MethodBuilder::INSTANCE_METHOD }

      it do
        expect { builder.build }
          .to add_method(method_name).to(instance)
      end

      context 'when the method is built' do
        before { builder.build }

        it 'returns the result of the block when called' do
          expect(instance.the_method).to eq(value)
        end
      end
    end

    context 'when type is class' do
      let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }

      it do
        expect { builder.build }
          .to add_class_method(method_name).to(klass)
      end

      context 'when the method is built' do
        before { builder.build }

        it 'returns the result of the block when called' do
          expect(klass.the_method).to eq(value)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-2.1.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-2.0.1 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-2.0.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.16.3 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.16.2 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.16.1 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.16.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.15.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.14.2 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.14.1 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.14.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.13.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.12.1 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.12.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.11.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.10.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.9.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.8.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb
sinclair-1.7.0 spec/lib/sinclair/method_builder/block_method_builder_spec.rb