Sha256: 05ac0ed861e30479328b53475068f8049dce205f2d23bec1f7dc93eda61027f3

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 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
      builder = Sinclair.new(klass)
      builder.add_method(:full_name, '[first_name, last_name].join(" ")')
      builder.build

      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
      builder = Sinclair.new(klass)
      builder.add_method(:bond_name) { "#{last_name}, #{first_name} #{last_name}" }
      builder.build

      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
      builder = Sinclair.new(klass)
      builder.add_method(:bond_name, type: :block, cached: true) do
        "#{last_name}, #{first_name} #{last_name}"
      end
      builder.build
      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

7 entries across 7 versions & 1 rubygems

Version Path
sinclair-1.14.2 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.14.1 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.14.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.13.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.12.1 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.12.0 spec/integration/yard/sinclair/add_method_spec.rb
sinclair-1.11.0 spec/integration/yard/sinclair/add_method_spec.rb