Sha256: 3b562625d4e16dfea07c60571d27702fb8ffb1b5823329b206c64fda0d751b97

Contents?: true

Size: 966 Bytes

Versions: 6

Compression:

Stored size: 966 Bytes

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.5.1 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.5.0 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.4.0 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.3.0 spec/fortnox/api/types/required_spec.rb
fortnox-api-0.2.0 spec/fortnox/api/types/required_spec.rb