Sha256: fe1f97405a674b5b4bd00f24d5e1e15439316eeea5427bfd6dc6fedec760104a

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodDefinition do
  let(:klass)    { Class.new }
  let(:instance) { klass.new }

  describe '#build' do
    let(:method_name) { :the_method }

    context 'when instantiating the class itself' do
      subject(:method_definition) do
        described_class.new(method_name)
      end

      it do
        expect { method_definition.build(klass) }.to raise_error(
          RuntimeError,
          'Build is implemented in subclasses. ' \
          "Use #{described_class}.from to initialize a proper object"
        )
      end
    end

    context 'when method was defined with a string' do
      subject(:method_definition) do
        described_class.from(method_name, code)
      end

      let(:code) { '@x = @x.to_i + 1' }

      it_behaves_like 'MethodDefinition#build without cache'

      context 'with cached options' do
        subject(:method_definition) do
          described_class.from(method_name, code, cached: cached_option)
        end

        it_behaves_like 'MethodDefinition#build with cache options'
      end
    end

    context 'when method was defined with a block' do
      subject(:method_definition) do
        described_class.from(method_name) do
          @x = @x.to_i + 1
        end
      end

      it_behaves_like 'MethodDefinition#build without cache'

      context 'with cached options' do
        subject(:method_definition) do
          described_class.from(method_name, cached: cached_option) do
            @x = @x.to_i + 1
          end
        end

        it_behaves_like 'MethodDefinition#build with cache options'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinclair-1.4.1 spec/lib/sinclair/method_definition_spec.rb
sinclair-1.4.0 spec/lib/sinclair/method_definition_spec.rb
sinclair-1.3.4 spec/lib/sinclair/method_definition_spec.rb
sinclair-1.3.3 spec/lib/sinclair/method_definition_spec.rb
sinclair-1.3.2 spec/lib/sinclair/method_definition_spec.rb
sinclair-1.3.1 spec/lib/sinclair/method_definition_spec.rb