Sha256: 779ed276ce5bc7260bff7b06218f0684ccdab12c1adf86daf9ee872c37dbabed

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

require 'rails_helper'
require 'sorbet-rails/custom_types/integer_string'
require 'sorbet-runtime'

RSpec.describe IntegerString do
  it 'lets integer string acts as IntegerString perfectly' do
    expect('1'.is_a?(IntegerString)).to be(true)
    expect('12'.kind_of?(IntegerString)).to be(true)
    expect('123'.instance_of?(IntegerString)).to be(true)
    expect(IntegerString === '1234').to be(true)
  end

  it 'does not let other string acts as IntegerString' do
    expect('a1'.is_a?(IntegerString)).to be(false)
    expect('a12'.kind_of?(IntegerString)).to be(false)
    expect('a123'.instance_of?(IntegerString)).to be(false)
    expect(IntegerString === 'a1234').to be(false)
  end

  context 'sorbet recognizes it at runtime' do
    it 'lets integer string pass runtime check' do
      expect(T.let('123', IntegerString)).to eql('123')
    end

    it 'doesnt let normal string pass runtime typecheck' do
      expect {
        T.let('a123', IntegerString)
      }.to raise_error(TypeError)
    end
  end

  context 'using with TypeAssert' do
    let!(:ta) { TA[IntegerString].new }

    it 'lets integer string pass runtime typecheck' do
      expect(ta.assert('123')).to eql('123')
    end

    it 'doesnt let normal string pass runtime typecheck' do
      expect {
        ta.assert('a123')
      }.to raise_error(TypeError)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sorbet-rails-0.6.5.1 spec/integer_string_spec.rb
sorbet-rails-0.6.5 spec/integer_string_spec.rb
sorbet-rails-0.6.4 spec/integer_string_spec.rb
sorbet-rails-0.6.3 spec/integer_string_spec.rb
sorbet-rails-0.6.2 spec/integer_string_spec.rb
sorbet-rails-0.6.1 spec/integer_string_spec.rb
sorbet-rails-0.6.0 spec/integer_string_spec.rb
sorbet-rails-0.5.9.1 spec/integer_string_spec.rb
sorbet-rails-0.5.9 spec/integer_string_spec.rb
sorbet-rails-0.5.8.1 spec/integer_string_spec.rb
sorbet-rails-0.5.8 spec/integer_string_spec.rb
sorbet-rails-0.5.7 spec/integer_string_spec.rb
sorbet-rails-0.5.6 spec/integer_string_spec.rb
sorbet-rails-0.5.5.1 spec/integer_string_spec.rb