bacon-custom_matchers_messages 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +16 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +93 -0
- data/Rakefile +5 -0
- data/bacon-custom_matchers_messages.gemspec +25 -0
- data/lib/bacon/custom_matchers_messages.rb +37 -0
- data/lib/bacon/custom_matchers_messages/version.rb +5 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee7e81802514302f8b01976c544786cb6f826bc7ac04fd909d8543a11d674559
|
4
|
+
data.tar.gz: b8ce21baf9b741468c77ed99bd74f2043d1d6d27659db08ba3e8b088b47f4762
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32d47ae16dcc850ec06a7e58b1b5123f9c2be55dbf8b9778d2ac3b82da963a0fc5d46184e300e19c445f69d57cd0a898f999313507950c8c062e109e5f6bb289
|
7
|
+
data.tar.gz: 8750650fdfbc8b4dd0579a5115fda4619065d8130ae6a8bd896fba8342134bd5e681a34bb38f5c30055d66fc3967d3918c07d589ef62295e256dfe13db18b377
|
data/.editorconfig
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
root = true
|
2
|
+
|
3
|
+
[*]
|
4
|
+
indent_style = tab
|
5
|
+
indent_size = 2
|
6
|
+
end_of_line = lf
|
7
|
+
charset = utf-8
|
8
|
+
trim_trailing_whitespace = true
|
9
|
+
insert_final_newline = true
|
10
|
+
|
11
|
+
[*.yml]
|
12
|
+
indent_style = space
|
13
|
+
|
14
|
+
[*.md]
|
15
|
+
indent_style = space
|
16
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alexander Popov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Bacon::CustomMatchersMessages
|
2
|
+
|
3
|
+
Errors messages for [`bacon`](https://github.com/chneukirchen/bacon) custom matchers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bacon-custom_matchers_messages'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install bacon-custom_matchers_messages
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'bacon/custom_matchers_messages'
|
29
|
+
|
30
|
+
## Old style, without message:
|
31
|
+
|
32
|
+
def shorter_than(max_size)
|
33
|
+
->(obj) { obj.size < max_size }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Bacon::Error:
|
37
|
+
|
38
|
+
|
39
|
+
## Old style, with error message:
|
40
|
+
|
41
|
+
def shorter_than(max_size)
|
42
|
+
lambda do |obj|
|
43
|
+
obj.size < max_size ||
|
44
|
+
"#{obj.inspect} doesn't shorter than #{max_size}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Bacon::Error: "foo bar baz" doesn't shorter than 2
|
49
|
+
|
50
|
+
|
51
|
+
## New style, with generated error message:
|
52
|
+
|
53
|
+
custom_matcher :shorter_than do |obj, max_size|
|
54
|
+
obj.size < max_size
|
55
|
+
end
|
56
|
+
|
57
|
+
# Bacon::Error: "foo bar baz" doesn't shorter than 2
|
58
|
+
|
59
|
+
|
60
|
+
## Old style, with custom arguments in message:
|
61
|
+
|
62
|
+
def include_words(*words)
|
63
|
+
lambda do |obj|
|
64
|
+
words.all? { |word| obj.split.include? word } ||
|
65
|
+
"#{obj.inspect} doesn't include words" \
|
66
|
+
" #{(words - obj.split).map!(&:inspect).join(',')}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Bacon::Error: "foo bar baz" doesn't include words "hello"
|
71
|
+
|
72
|
+
|
73
|
+
## New style, with custom arguments for generated error message:
|
74
|
+
|
75
|
+
custom_matcher :include_words do |obj, *words|
|
76
|
+
words.all? { |word| obj.split.include? word } ||
|
77
|
+
(words - obj.split)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Bacon::Error: "foo bar baz" doesn't include words "hello"
|
81
|
+
```
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at [AlexWayfer/bacon-custom_matchers_messages](https://github.com/AlexWayfer/bacon-custom_matchers_messages).
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'lib/bacon/custom_matchers_messages/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'bacon-custom_matchers_messages'
|
5
|
+
spec.version = Bacon::CustomMatchersMessages::VERSION
|
6
|
+
spec.authors = ['Alexander Popov']
|
7
|
+
spec.email = ['alex.wayfer@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Specify errors messages for `bacon` custom matchers.'
|
10
|
+
spec.description = 'Allows add errors messages for `bacon` custom matchers'
|
11
|
+
spec.homepage =
|
12
|
+
'https://github.com/AlexWayfer/bacon-custom_matchers_messages'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bacon', '~> 1.2'
|
21
|
+
spec.add_development_dependency 'bacon-colored_output', '~> 1.1'
|
22
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.4'
|
23
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.65.0'
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'custom_matchers_messages/version'
|
2
|
+
|
3
|
+
module Bacon
|
4
|
+
## Extend bacon for errors messages of custom matchers
|
5
|
+
module CustomMatchersMessages
|
6
|
+
::Should.prepend(
|
7
|
+
Module.new do
|
8
|
+
def satisfy(description = '', &block)
|
9
|
+
r = yield(@object)
|
10
|
+
if r.is_a? String
|
11
|
+
description = r
|
12
|
+
block = ->(_obj) { false }
|
13
|
+
end
|
14
|
+
super(description, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
## Add private method into Kernel for custom matchers
|
22
|
+
module Kernel
|
23
|
+
private
|
24
|
+
|
25
|
+
def custom_matcher(name, &_block)
|
26
|
+
description = name.to_s.tr('_', ' ')
|
27
|
+
define_method name do |*args|
|
28
|
+
lambda do |obj|
|
29
|
+
result = yield(obj, *args)
|
30
|
+
return result if result == true
|
31
|
+
|
32
|
+
"#{obj.inspect} doesn't #{description}" \
|
33
|
+
" #{(result || args).map(&:inspect).join(', ')}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bacon-custom_matchers_messages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Popov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bacon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bacon-colored_output
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
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.65.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.65.0
|
83
|
+
description: Allows add errors messages for `bacon` custom matchers
|
84
|
+
email:
|
85
|
+
- alex.wayfer@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".editorconfig"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bacon-custom_matchers_messages.gemspec
|
99
|
+
- lib/bacon/custom_matchers_messages.rb
|
100
|
+
- lib/bacon/custom_matchers_messages/version.rb
|
101
|
+
homepage: https://github.com/AlexWayfer/bacon-custom_matchers_messages
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.7.6
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Specify errors messages for `bacon` custom matchers.
|
125
|
+
test_files: []
|