From 57240a262c99dd9647b73bdc9c2cf1174ff1f9b1 Mon Sep 17 00:00:00 2001 From: Max VelDink Date: Wed, 21 Feb 2024 09:59:05 -0500 Subject: [PATCH] docs: Update version and supporting docs --- CHANGELOG.md | 6 ++++++ Gemfile.lock | 2 +- README.md | 23 +++++++++++++++++++++++ sorbet-result.gemspec | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 950f7c8..88c8354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.0] - 2024-02-21 + +### Added + +- Add minitest assertions for Results + ### Changed - Switched to Standard over using Rubocop directly diff --git a/Gemfile.lock b/Gemfile.lock index 56da152..96485f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sorbet-result (1.0.0) + sorbet-result (1.1.0) sorbet-runtime (~> 0.5) GEM diff --git a/README.md b/README.md index 17ba7ac..8d59f36 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,29 @@ res = retrieve_user(user_id) If the above chain does not fail, the `puts` statement is never run. If the chain does yield a `Failure`, the `puts` block is executed and the `Failure` is ultimately returned. +### Testing + +We ship with a few Minitest assertions that can be used to easily verify Results. + +```ruby +# test_helper.rb + +require "minitest/results_assertions" +# You also need add this to `sorbet/tapioca/require.rb` and rebuild the Minitest gem RBIs + +# *_test.rb + +@success = Typed::Success.new("Test Payload") +@failure = Typed::Failure.new("Test Error") + +assert_success(@success) +assert_failure(@failure) +assert_payload("Test Payload", @success) +assert_error("Test Error", @failure) + +# We also have the `refute_*` counterparts +``` + ## Why use Results? Let's say you're working on a method that reaches out to an API and fetches a resource. We hope to get a successful response and continue on in our program, but you can imagine several scenarios where we don't get that response: our authentication could fail, the server could return a 5XX response code, or the resource we were querying could have moved or not exist any more. diff --git a/sorbet-result.gemspec b/sorbet-result.gemspec index 9b7a187..ae8d004 100644 --- a/sorbet-result.gemspec +++ b/sorbet-result.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "sorbet-result" - spec.version = "1.0.0" + spec.version = "1.1.0" spec.authors = ["Max VelDink"] spec.email = ["maxveldink@gmail.com"]