Sha256: 5b28aea16dd42508ec9921f7f8e23e57ca963d207f28b3b3cdd01a80d3b57cf1

Contents?: true

Size: 938 Bytes

Versions: 6

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

describe Sinclair::MethodDefinition::StringDefinition do
  describe 'yard' do
    describe '#build' do
      subject(:method_definition) do
        described_class.new(name, code)
      end

      let(:klass)    { Class.new }
      let(:instance) { klass.new }
      let(:code)     { '@x = @x.to_i ** 2 + 1' }
      let(:name)     { :sequence }

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

      it 'changes instance variable' do
        method_definition.build(klass)

        expect { instance.sequence }
          .to change { instance.instance_variable_get(:@x) }
          .from(nil).to 1
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinclair-1.4.1 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb
sinclair-1.4.0 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb
sinclair-1.3.4 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb
sinclair-1.3.3 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb
sinclair-1.3.2 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb
sinclair-1.3.1 spec/integration/yard/sinclair/method_definition/string_definition_spec.rb