either_result_matcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.md +9 -0
- data/README.md +17 -0
- data/Rakefile +12 -0
- data/lib/either_result_matcher/either_extensions.rb +12 -0
- data/lib/either_result_matcher/matcher.rb +22 -0
- data/lib/either_result_matcher/version.rb +3 -0
- data/lib/either_result_matcher.rb +5 -0
- data/spec/examples.txt +4 -0
- data/spec/integration/match_either_result_spec.rb +29 -0
- data/spec/spec_helper.rb +99 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c1e5589196cbb40e8ef62a6511a303e0daed1fb
|
4
|
+
data.tar.gz: f5b0fccbf089e4810018e1da59290063ed47fc90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd6181b2cae7ee09a3eca63c19ae4b0e3a0ec578c7f68cdfb7ac75b88d8531a314d042b28c211bf7eefe69967774eef263141076f9a64311acc95340799ba35f
|
7
|
+
data.tar.gz: c811660449fba53db8ed32da6e969dee9696f2dadde5525c2f02a758a9c7cb67db12edd309ed3f7260b76663fd7e514a9097a28a405792af7819b22f20d68f17
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
either_result_matcher (0.1.0)
|
5
|
+
kleisli
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.1.0)
|
11
|
+
astrolabe (1.3.1)
|
12
|
+
parser (~> 2.2)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
docile (1.1.5)
|
15
|
+
json (1.8.3)
|
16
|
+
kleisli (0.2.6)
|
17
|
+
parser (2.2.3.0)
|
18
|
+
ast (>= 1.1, < 3.0)
|
19
|
+
powerpack (0.1.1)
|
20
|
+
rainbow (2.0.0)
|
21
|
+
rake (10.4.2)
|
22
|
+
rspec (3.3.0)
|
23
|
+
rspec-core (~> 3.3.0)
|
24
|
+
rspec-expectations (~> 3.3.0)
|
25
|
+
rspec-mocks (~> 3.3.0)
|
26
|
+
rspec-core (3.3.2)
|
27
|
+
rspec-support (~> 3.3.0)
|
28
|
+
rspec-expectations (3.3.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.3.0)
|
31
|
+
rspec-mocks (3.3.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.3.0)
|
34
|
+
rspec-support (3.3.0)
|
35
|
+
rubocop (0.34.2)
|
36
|
+
astrolabe (~> 1.3)
|
37
|
+
parser (>= 2.2.2.5, < 3.0)
|
38
|
+
powerpack (~> 0.1)
|
39
|
+
rainbow (>= 1.99.1, < 3.0)
|
40
|
+
ruby-progressbar (~> 1.4)
|
41
|
+
ruby-progressbar (1.7.5)
|
42
|
+
simplecov (0.10.0)
|
43
|
+
docile (~> 1.1.0)
|
44
|
+
json (~> 1.8)
|
45
|
+
simplecov-html (~> 0.10.0)
|
46
|
+
simplecov-html (0.10.0)
|
47
|
+
yard (0.8.7.6)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.10)
|
54
|
+
either_result_matcher!
|
55
|
+
rake (~> 10.4.2)
|
56
|
+
rspec (~> 3.3.0)
|
57
|
+
rubocop (~> 0.34.2)
|
58
|
+
simplecov (~> 0.10.0)
|
59
|
+
yard
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.10.6
|
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
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "kleisli"
|
2
|
+
|
3
|
+
module EitherResultMatcher
|
4
|
+
class Matcher
|
5
|
+
attr_reader :result
|
6
|
+
attr_reader :output
|
7
|
+
|
8
|
+
def initialize(result)
|
9
|
+
@result = result
|
10
|
+
end
|
11
|
+
|
12
|
+
def success(&block)
|
13
|
+
return output unless result.is_a?(Kleisli::Either::Right)
|
14
|
+
@output = block.call(result.value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure(&block)
|
18
|
+
return output unless result.is_a?(Kleisli::Either::Left)
|
19
|
+
@output = block.call(result.value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/examples.txt
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/integration/match_either_result_spec.rb[1:1:1] | passed | 0.00089 seconds |
|
4
|
+
./spec/integration/match_either_result_spec.rb[1:2:1] | passed | 0.00012 seconds |
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec.describe "MatchEitherResult" do
|
2
|
+
subject(:match) {
|
3
|
+
MatchEitherResult(result) do |m|
|
4
|
+
m.success do |v|
|
5
|
+
"Matched success: #{v}"
|
6
|
+
end
|
7
|
+
|
8
|
+
m.failure do |v|
|
9
|
+
"Matched failure: #{v}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
context "successful result" do
|
15
|
+
let(:result) { Right("a success") }
|
16
|
+
|
17
|
+
it "matches on success" do
|
18
|
+
expect(match).to eq "Matched success: a success"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "failed result" do
|
23
|
+
let(:result) { Left("a failure") }
|
24
|
+
|
25
|
+
it "matches on failure" do
|
26
|
+
expect(match).to eq "Matched failure: a failure"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -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 "either_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,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: either_result_matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Riley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-03 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: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.34.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.34.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.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.10.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- tim@icelab.com.au
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- LICENSE.md
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/either_result_matcher.rb
|
124
|
+
- lib/either_result_matcher/either_extensions.rb
|
125
|
+
- lib/either_result_matcher/matcher.rb
|
126
|
+
- lib/either_result_matcher/version.rb
|
127
|
+
- spec/examples.txt
|
128
|
+
- spec/integration/match_either_result_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/icelab/either_result_matcher
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.5.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Expressive, all-in-one match API for Kleisli Either monads
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|