Sha256: d7c88c23690db7a8507c9f4f35f381120097a3ee6e8a01793f28d8229b1853e8
Contents?: true
Size: 1.71 KB
Versions: 14
Compression:
Stored size: 1.71 KB
Contents
require 'rails_helper' require 'sorbet-rails/custom_types/boolean_string' require 'sorbet-runtime' RSpec.describe BooleanString do shared_examples 'boolean string' do |str| it 'acts as BooleanString perfectly' do expect(str.is_a?(BooleanString)).to be(true) expect(str.kind_of?(BooleanString)).to be(true) expect(str.instance_of?(BooleanString)).to be(true) expect(BooleanString === str).to be(true) end end include_examples 'boolean string', 'true' include_examples 'boolean string', 'false' include_examples 'boolean string', 'True' include_examples 'boolean string', 'False' shared_examples 'non boolean string' do |str| it 'does not acts as BooleanString' do expect(str.is_a?(BooleanString)).to be(false) expect(str.kind_of?(BooleanString)).to be(false) expect(str.instance_of?(BooleanString)).to be(false) expect(BooleanString === str).to be(false) end end include_examples 'non boolean string', 'yes' include_examples 'non boolean string', 'no' include_examples 'non boolean string', 'alala' context 'sorbet recognizes it at runtime' do it 'lets boolean string pass runtime check' do expect(T.let('true', BooleanString)).to eql('true') end it 'doesnt let normal string pass runtime typecheck' do expect { T.let('yes', BooleanString) }.to raise_error(TypeError) end end context 'using with TypeAssert' do let!(:ta) { TA[BooleanString].new } it 'lets boolean string pass runtime typecheck' do expect(ta.assert('true')).to eql('true') end it 'doesnt let normal string pass runtime typecheck' do expect { ta.assert('yes') }.to raise_error(TypeError) end end end
Version data entries
14 entries across 14 versions & 1 rubygems