Sha256: 6ba2004aa0dadbb15ab79dfbc070a4be6f3130be04e2b377d870bd7b30991a42

Contents?: true

Size: 995 Bytes

Versions: 8

Compression:

Stored size: 995 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'fortnox/api/types'
require 'fortnox/api/types/required'

describe Fortnox::API::Types::Required, type: :type do
  using_test_class do
    class TestClass < Dry::Struct
    end
  end

  shared_examples_for 'required attribute' do |_type|
    subject { -> { TestClass.new({}) } }

    let(:error_message) do
      "[#{TestClass}.new] #{:required_attribute.inspect} is missing in Hash input"
    end

    it 'raises an error' do
      is_expected.to raise_error(Dry::Struct::Error, error_message)
    end
  end

  describe 'String' do
    before do
      class TestClass
        attribute :required_attribute, Fortnox::API::Types::Required::String
      end
    end

    include_examples 'required attribute', String
  end

  describe 'Float' do
    before do
      class TestClass
        attribute :required_attribute, Fortnox::API::Types::Required::Float
      end
    end

    include_examples 'required attribute', Float
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fortnox-api-0.8.0 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.7.2 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.7.1 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.7.0 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.6.3 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.6.2 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.6.1 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.6.0 spec/fortnox/api/types/required_spec.rb