Sha256: 6f6af6cb6ed534f615d05405d69c64c370b5288a95a5e89619272e153c7f87b1

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: false

require 'spec_helper'

describe 'yard Sinclair#add_method' do
  describe 'Using string code to add a string defined method' do
    let(:klass) { Class.new(Person) }

    it 'creates new method' do
      Sinclair.build(klass) do
        add_method(:full_name, '[first_name, last_name].join(" ")')
      end

      expect(klass.new('john', 'wick').full_name).to eq('john wick')
    end
  end

  describe 'Using block to add a block method' do
    let(:klass) { Class.new(Person) }

    it 'creates new method' do
      Sinclair.build(klass) do
        add_method(:bond_name) { "#{last_name}, #{first_name} #{last_name}" }
      end

      expect(klass.new('john', 'wick').bond_name).to eq('wick, john wick')
    end
  end

  describe 'Passing type block' do
    let(:klass) { Class.new(Person) }

    it 'creates new method' do
      Sinclair.build(klass) do
        add_method(:bond_name, type: :block, cached: true) do
          "#{last_name}, #{first_name} #{last_name}"
        end
      end

      person = klass.new('john', 'wick')

      expect(person.bond_name).to eq('wick, john wick')
      person.first_name = 'Johny'
      expect(person.bond_name).to eq('wick, john wick')
    end
  end

  describe 'Passing type call' do
    let(:klass) { Class.new }

    it 'creates new method' do
      builder = Sinclair.new(klass)
      builder.add_method(:attr_accessor, :bond_name, type: :call)
      builder.build
      person = klass.new

      person.bond_name = 'Bond, James Bond'
      expect(person.bond_name).to eq('Bond, James Bond')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-2.1.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-2.0.1 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-2.0.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.16.3 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.16.2 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.16.1 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.16.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.15.0 spec/integration/yard/sinclair/add_method_spec.rb