Sha256: 91570a95bf627583469a5a8a7ca8c3cae901e2e8e111f62c25dc25f98a6ceba7

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodBuilder::StringMethodBuilder 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
      Sinclair::MethodDefinition.from(method_name, value.to_s)
    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 code 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 code when called' do
          expect(klass.the_method).to eq(value)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sinclair-1.11.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.10.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.9.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.8.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.7.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.7 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.6 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.5 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.4 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.3 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.2 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.1 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.6.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.5.2 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.5.1 spec/lib/sinclair/method_builder/string_method_builder_spec.rb
sinclair-1.5.0 spec/lib/sinclair/method_builder/string_method_builder_spec.rb