Sha256: e76b631c713adb3fb329853cd2e9577c1e8985dd9324d578696f84e23d948b97

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Arstotzka::MethodBuilder do
  describe 'yard' do
    subject(:builder) { described_class.new(attributes, klass, options) }

    let!(:instance) { klass.new(hash) }
    let(:hash) do
      {
        'name' => { first: 'John', last: 'Williams' },
        :age => '20',
        'cars' => 2.0
      }
    end

    describe '#first_name' do
      let(:klass)      { Class.new(MyModel) }
      let(:attributes) { [:first_name] }
      let(:options)    { { full_path: 'name.first' } }

      before do
        builder.build
      end

      it 'crawls into the hash to find the value of the first name' do
        expect(instance.first_name).to eq('John')
      end
    end

    describe '#age' do
      let(:klass)      { Class.new(MyModel) }
      let(:attributes) { %i[age cars] }
      let(:options)    { { type: :integer } }

      before do
        builder.build
      end

      it 'crawls into the hash to find the value of the age' do
        expect(instance.age).to eq(20)
      end

      it do
        expect(instance.age).to be_a(Integer)
      end
    end

    describe '#cars' do
      let(:klass)      { Class.new(MyModel) }
      let(:attributes) { %i[age cars] }
      let(:options)    { { type: :integer } }

      before do
        builder.build
      end

      it 'crawls into the hash to find the value of the age' do
        expect(instance.cars).to eq(2)
      end

      it do
        expect(instance.cars).to be_a(Integer)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
arstotzka-1.6.2 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.6.1 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.6.0 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.5.0 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.4.4 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.4.3 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.4.2 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.4.1 spec/integration/yard/arstotzka/method_builder_spec.rb
arstotzka-1.4.0 spec/integration/yard/arstotzka/method_builder_spec.rb