v1.8.0
Added
-
New extension for RSpec (@flash-gordon in #183): One of the pain points of testing monads is referencing class constants from specs. This extension catches missing class constants, analyzes the call site and returns a matching constant.
Before, this code would raise a
NameErrorbecauseFailureis a constant that is missing inObject:example "missing constant" do expect(call_operation).to eql(Failure[:some_error, "some message"]) endNow, after enabling the extension, it will return the correct constant:
Dry::Monads.load_extensions(:rspec) example "missing constant" do Failure[:some_error, "some message"] # => Failure[:some_error, "some message"] endOut of the box, the extension will check if
Success,Failure,Some, andNoneare referenced from a file ending with_spec.rb.More involved analysis is possible if you add
debug_inspectorto your Gemfile:group :test do gem "debug_inspector" endThis will allow referencing constants from other modules, such as rspec helpers.
The extension also adds new matchers for
Success,Failure,Some, andNonevalues.expect(Success(1)).to be_success expect(Success(1)).to be_success(1) expect(Success(1)).to be_success { |x| x > 0 } expect(Success(1)).to be_a_success { |x| x > 0 } expect(Failure(1)).to be_failure(1) expect(Some(1)).to be_some expect(Some(1)).to be_success expect(None()).to be_none expect(None()).to be_failure -
New extension for super_diff (@flash-gordon in #184):
Adds support for improved diff output in specs when using the super_diff gem. This makes it easier to understand the differences between monad values in test failures.
To use this extension:
- Add super_diff to your Gemfile's test group:
group :test do gem "super_diff" end - Load the extension:
require "dry/monads" Dry::Monads.load_extensions(:super_diff)
This will change the diff output for monad values to be more readable.
Before:
-Success({a: 2, c: 2}) +Success({a: 1, b: 2})After:
Success( - a: 2, + a: 1, - c: 2 + b: 2 ) - Add super_diff to your Gemfile's test group: