dry-result_matcher 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5ea86f91bd7f5f0025e631a78c82562a38d5d66
4
+ data.tar.gz: 1300f23cad999c0c25dad32b39f019d694fd287c
5
+ SHA512:
6
+ metadata.gz: 5c5fa1e332fe40a13462eeae6d959bb27d6e2122ae472414449060833e7a82de50f17c2ceaefbddd55eebe08aae7c109ceccb75dd3c8d8b5cc982c8d7c28f977
7
+ data.tar.gz: f34884099fa596d6bbccd990de8c378afd7c9fcfb0dd458db0ecaebccc2e38c3f17aac80b2c4920cb65205e864c8e47ba3dcaef3b26343e8cbee246d498683ad
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dry-result_matcher (0.3.0)
5
+ kleisli
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ docile (1.1.5)
12
+ json (1.8.3)
13
+ kleisli (0.2.7)
14
+ rake (10.4.2)
15
+ rspec (3.3.0)
16
+ rspec-core (~> 3.3.0)
17
+ rspec-expectations (~> 3.3.0)
18
+ rspec-mocks (~> 3.3.0)
19
+ rspec-core (3.3.2)
20
+ rspec-support (~> 3.3.0)
21
+ rspec-expectations (3.3.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.3.0)
24
+ rspec-mocks (3.3.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.3.0)
27
+ rspec-support (3.3.0)
28
+ simplecov (0.10.0)
29
+ docile (~> 1.1.0)
30
+ json (~> 1.8)
31
+ simplecov-html (~> 0.10.0)
32
+ simplecov-html (0.10.0)
33
+ yard (0.8.7.6)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.10)
40
+ dry-result_matcher!
41
+ rake (~> 10.4.2)
42
+ rspec (~> 3.3.0)
43
+ simplecov (~> 0.10.0)
44
+ yard
45
+
46
+ BUNDLED WITH
47
+ 1.11.2
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2015 [Icelab](http://icelab.com.au/).
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ [gitter]: https://gitter.im/dry-rb/chat
2
+ [gem]: https://rubygems.org/gems/dry-result_matcher
3
+ [travis]: https://travis-ci.org/dry-rb/dry-result_matcher
4
+ [code_climate]: https://codeclimate.com/github/dry-rb/dry-result_matcher
5
+ [inch]: http://inch-ci.org/github/dry-rb/dry-result_matcher
6
+
7
+ # dry-result_matcher [![Join the Gitter chat](https://badges.gitter.im/Join%20Chat.svg)][gitter]
8
+
9
+ [![Gem Version](https://img.shields.io/gem/v/dry-result_matcher.svg)][gem]
10
+ [![Build Status](https://travis-ci.org/dry-rb/dry-result_matcher.svg?branch=master)][travis]
11
+ [![Code Climate](https://img.shields.io/codeclimate/github/dry-rb/dry-result_matcher.svg)][code_climate]
12
+ [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-result_matcher.svg)][inch]
13
+
14
+ An expressive, all-in-one API for operating on [Kleisli](https://github.com/txus/kleisli) `Either` results.
15
+
16
+ ## Usage
17
+
18
+ Operate an an `Either` object from the outside:
19
+
20
+ ```ruby
21
+ result = Right("some result")
22
+
23
+ Dry::ResultMatcher.match(result) do |m|
24
+ m.success do |v|
25
+ "Success: #{v}"
26
+ end
27
+
28
+ m.failure do |v|
29
+ "Failure: #{v}"
30
+ end
31
+ end
32
+ ```
33
+
34
+ Or extend your own `Either`-returning classes to support result match blocks:
35
+
36
+ ```ruby
37
+ class MyOperation
38
+ include Dry::ResultMatcher.for(:call)
39
+
40
+ def call
41
+ Right("some result")
42
+ end
43
+ end
44
+
45
+ my_op = MyOperation.new
46
+ my_op.call() do |m|
47
+ m.success do |v|
48
+ "Success: #{v}"
49
+ end
50
+
51
+ m.failure do |v|
52
+ "Failure: #{v}"
53
+ end
54
+ end
55
+ ```
56
+
57
+ ## License
58
+
59
+ Copyright © 2015-2016 [Icelab](http://icelab.com.au/). dry-result_matcher is free software, and may be redistributed under the terms specified in the [license](LICENSE.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ require "kleisli"
2
+
3
+ module Dry
4
+ module ResultMatcher
5
+ class Matcher
6
+ attr_reader :result
7
+ attr_reader :output
8
+
9
+ def initialize(result)
10
+ @result = result
11
+ end
12
+
13
+ def success(&block)
14
+ return output unless result.is_a?(Kleisli::Either::Right)
15
+ @output = block.call(result.value)
16
+ end
17
+
18
+ def failure(&block)
19
+ return output unless result.is_a?(Kleisli::Either::Left)
20
+ @output = block.call(result.value)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Dry
2
+ module ResultMatcher
3
+ VERSION = "0.3.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require "dry/result_matcher/matcher"
2
+
3
+ module Dry
4
+ module ResultMatcher
5
+ def self.match(result, &block)
6
+ block.call(Matcher.new(result))
7
+ end
8
+
9
+ def self.for(*match_methods)
10
+ matchers_mod = Module.new do
11
+ match_methods.each do |match_method|
12
+ define_method(match_method) do |*args, &block|
13
+ result = super(*args)
14
+
15
+ if block
16
+ Dry::ResultMatcher.match(result, &block)
17
+ else
18
+ result
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Module.new do
25
+ const_set :Matchers, matchers_mod
26
+
27
+ def self.included(klass)
28
+ klass.prepend const_get(:Matchers)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require "dry/result_matcher"
data/spec/examples.txt ADDED
@@ -0,0 +1,8 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/integration/result_matcher_spec.rb[1:1:1:1] | passed | 0.00008 seconds |
4
+ ./spec/integration/result_matcher_spec.rb[1:1:2:1] | passed | 0.00014 seconds |
5
+ ./spec/integration/result_matcher_spec.rb[1:2:1:1:1] | passed | 0.00013 seconds |
6
+ ./spec/integration/result_matcher_spec.rb[1:2:1:2:1] | passed | 0.00012 seconds |
7
+ ./spec/integration/result_matcher_spec.rb[1:2:2:1:1] | passed | 0.00014 seconds |
8
+ ./spec/integration/result_matcher_spec.rb[1:2:2:2:1] | passed | 0.00098 seconds |
@@ -0,0 +1,93 @@
1
+ RSpec.describe Dry::ResultMatcher do
2
+ describe "external matching" do
3
+ subject(:match) {
4
+ Dry::ResultMatcher.match(result) do |m|
5
+ m.success do |v|
6
+ "Matched success: #{v}"
7
+ end
8
+
9
+ m.failure do |v|
10
+ "Matched failure: #{v}"
11
+ end
12
+ end
13
+ }
14
+
15
+ context "successful result" do
16
+ let(:result) { Right("a success") }
17
+
18
+ it "matches on success" do
19
+ expect(match).to eq "Matched success: a success"
20
+ end
21
+ end
22
+
23
+ context "failed result" do
24
+ let(:result) { Left("a failure") }
25
+
26
+ it "matches on failure" do
27
+ expect(match).to eq "Matched failure: a failure"
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "class enhancement" do
33
+ let(:operation) {
34
+ Class.new do
35
+ include Dry::ResultMatcher.for(:call)
36
+
37
+ def call(bool)
38
+ bool ? Right("a success") : Left("a failure")
39
+ end
40
+ end.new
41
+ }
42
+
43
+ describe "match blocks" do
44
+ subject(:match) {
45
+ operation.call(input) do |m|
46
+ m.success do |v|
47
+ "Matched success: #{v}"
48
+ end
49
+
50
+ m.failure do |v|
51
+ "Matched failure: #{v}"
52
+ end
53
+ end
54
+ }
55
+
56
+ context "successful result" do
57
+ let(:input) { true }
58
+
59
+ it "matches on success" do
60
+ expect(match).to eq "Matched success: a success"
61
+ end
62
+ end
63
+
64
+ context "failed result" do
65
+ let(:input) { false }
66
+
67
+ it "matches on failure" do
68
+ expect(match).to eq "Matched failure: a failure"
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "without match blocks" do
74
+ subject(:result) { operation.call(input) }
75
+
76
+ context "successful result" do
77
+ let(:input) { true }
78
+
79
+ it "returns the result" do
80
+ expect(result).to eq Right("a success")
81
+ end
82
+ end
83
+
84
+ context "failed result" do
85
+ let(:input) { false }
86
+
87
+ it "returns the result" do
88
+ expect(result).to eq Left("a failure")
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,99 @@
1
+ require "simplecov"
2
+ SimpleCov.minimum_coverage 100
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+
7
+ require "dry-result_matcher"
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc, in
10
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
11
+ # run as spec files by default. This means that files in spec/support that end
12
+ # in _spec.rb will both be required and run as specs, causing the specs to be
13
+ # run twice. It is recommended that you do not name files matching this glob to
14
+ # end with _spec.rb. You can configure this pattern with the --pattern
15
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
16
+ #
17
+ # The following line is provided for convenience purposes. It has the downside
18
+ # of increasing the boot-up time by auto-requiring all files in the support
19
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
20
+ # require only the support files necessary.
21
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each do |f| require f end
22
+
23
+ # This file was generated by the `rspec --init` command. Conventionally, all
24
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
25
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
26
+ # this file to always be loaded, without a need to explicitly require it in any
27
+ # files.
28
+ #
29
+ # Given that it is always loaded, you are encouraged to keep this file as
30
+ # light-weight as possible. Requiring heavyweight dependencies from this file
31
+ # will add to the boot time of your test suite on EVERY test run, even for an
32
+ # individual file that may not need all of that loaded. Instead, consider making
33
+ # a separate helper file that requires the additional dependencies and performs
34
+ # the additional setup, and require it from the spec files that actually need
35
+ # it.
36
+ #
37
+ # The `.rspec` file also contains a few flags that are not defaults but that
38
+ # users commonly want.
39
+ #
40
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
41
+ RSpec.configure do |config|
42
+ # rspec-expectations config goes here. You can use an alternate
43
+ # assertion/expectation library such as wrong or the stdlib/minitest
44
+ # assertions if you prefer.
45
+ config.expect_with :rspec do |expectations|
46
+ # This option will default to `true` in RSpec 4. It makes the `description`
47
+ # and `failure_message` of custom matchers include text for helper methods
48
+ # defined using `chain`, e.g.:
49
+ # be_bigger_than(2).and_smaller_than(4).description
50
+ # # => "be bigger than 2 and smaller than 4"
51
+ # ...rather than:
52
+ # # => "be bigger than 2"
53
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
54
+ end
55
+
56
+ # rspec-mocks config goes here. You can use an alternate test double
57
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
58
+ config.mock_with :rspec do |mocks|
59
+ # Prevents you from mocking or stubbing a method that does not exist on
60
+ # a real object. This is generally recommended, and will default to
61
+ # `true` in RSpec 4.
62
+ mocks.verify_partial_doubles = true
63
+ end
64
+
65
+ # Allows RSpec to persist some state between runs in order to support
66
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
67
+ # you configure your source control system to ignore this file.
68
+ config.example_status_persistence_file_path = "spec/examples.txt"
69
+
70
+ # Limits the available syntax to the non-monkey patched syntax that is
71
+ # recommended.
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = "doc"
86
+ end
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-result_matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Riley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kleisli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 10.4.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.4.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - tim@icelab.com.au
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.md
107
+ - README.md
108
+ - Rakefile
109
+ - lib/dry-result_matcher.rb
110
+ - lib/dry/result_matcher.rb
111
+ - lib/dry/result_matcher/matcher.rb
112
+ - lib/dry/result_matcher/version.rb
113
+ - spec/examples.txt
114
+ - spec/integration/result_matcher_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/dry-rb/dry-result_matcher
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Expressive, all-in-one match API for Kleisli Either monads
140
+ test_files: []
141
+ has_rdoc: