Sha256: 375f0d2e201d04ea29ea028a584a75eb9f26498a44eb36df9809b02aee695b7f

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodDefinition::ClassMethodDefinition do
  describe 'yard' do
    describe '#build' do
      describe 'using block with cache option' do
        subject(:method_definition) do
          described_class.from(name, cached: true) do
            @x = @x.to_i**2 + 1
          end
        end

        let(:klass)    { Class.new }
        let(:name)     { :sequence }

        it 'adds a dynamic method' do
          expect { method_definition.build(klass) }.to add_class_method(name).to(klass)
          expect { klass.sequence }
            .to change { klass.instance_variable_get(:@x) }.from(nil).to 1
          expect { klass.sequence }.not_to change(klass, :sequence)
          expect(klass.instance_variable_get(:@sequence)).to eq(1)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinclair-1.4.2 spec/integration/yard/sinclair/method_definition/class_method_definition_spec.rb