<commit_before>RSpec.describe Dry::Types::Definition do
  subject(:type) { Dry::Types::Definition.new(String) }

  it_behaves_like 'Dry::Types::Definition#meta'

  it 'is frozen' do
    expect(type).to be_frozen
  end

  describe '#constructor' do
    it 'returns a constructor' do
      coercible_string = type.constructor(&:to_s)

      expect(coercible_string[{}]).to eql({}.to_s)
    end
  end
end<commit_msg>Add tests for `Result` and `Definition`<commit_after>RSpec.describe Dry::Types::Definition do
  subject(:type) { Dry::Types::Definition.new(String) }

  it_behaves_like 'Dry::Types::Definition#meta'

  it 'is frozen' do
    expect(type).to be_frozen
  end

  describe '#constructor' do
    it 'returns a constructor' do
      coercible_string = type.constructor(&:to_s)

      expect(coercible_string[{}]).to eql({}.to_s)
    end
  end

  describe '#try' do
    subject(:try) { type.try(value) }

    let(:success) { try.success?    }
    let(:failure) { try.failure?    }
    let(:input)   { try.input       }

    context 'when given valid input' do
      let(:value) { 'foo' }

      specify { expect(success).to be(true)  }
      specify { expect(failure).to be(false) }
      specify { expect(input).to be(value)   }
    end

    context 'when given invalid input' do
      let(:value) { :foo }

      specify { expect(success).to be(false) }
      specify { expect(failure).to be(true)  }
      specify { expect(input).to be(value)   }

      it "provides an error message" do
        expect(try.error).to eql(':foo must be an instance of String')
      end

      it "yields failure when given a block" do
        expect { |probe| type.try(value, &probe) }.to yield_with_args(try)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13252314814814814, 'fraction_numerical': 0.0, 'mean_word_length': 3.0303030303030303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6324308', 'n_tokens_mistral': 585, 'n_tokens_neox': 567, 'n_words': 140}