rspec-matchers-power_assert_matchers 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7848df26d206ed3701ce48dba26ababbc006a8a7526fdc2dd4115d7606262f65
4
+ data.tar.gz: 6abaa1b1122699706d6371b7f6f523adbe80fa028b2a6a03a9535156050daf3c
5
+ SHA512:
6
+ metadata.gz: d44db9e8b5a8900b9f0c58b29b13bfa2b5aa5bbbe9ead6ffa7757c8a18d73bd74285d4c0fa7a320f8aaebc8c7aa8f6f510d76560c50ba5e4c1711fc196270c0a
7
+ data.tar.gz: bd1e868d1f523e1a74dfebfbc3ae1bf72e783b84a7c3997630e7ec45f42daf211e9889a7bc8d7a0becb91f96eb8958c5e511583f2df28f4b4a90872715b21edb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Kenichi Kamiya
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,100 @@
1
+ # rspec-matchers-power_assert_matchers
2
+
3
+ ![Build Status](https://github.com/kachick/rspec-matchers-power_assert_matchers/actions/workflows/spec.yml/badge.svg?branch=main)
4
+ [![Gem Version](https://badge.fury.io/rb/rspec-matchers-power_assert_matchers.png)](http://badge.fury.io/rb/rspec-matchers-power_assert_matchers)
5
+
6
+ ## Overview
7
+
8
+ ![screenshot1](https://user-images.githubusercontent.com/1180335/118840923-c9b3a980-b902-11eb-8c8c-afb17fa87d31.png)
9
+ ![screenshot2](https://user-images.githubusercontent.com/1180335/118840930-cb7d6d00-b902-11eb-8d8e-f6fcdc801367.png)
10
+
11
+ [ruby/power_assert](https://github.com/ruby/power_assert) integration for RSpec.
12
+
13
+ Without no monkey patching for Ruby and RSpec.
14
+
15
+ Just using [RSpec's Custom matchers way](https://relishapp.com/rspec/rspec-expectations/v/3-10/docs/custom-matchers)
16
+
17
+ I hope this might be a choice of using `PowerAssert` for RSpec lovers.
18
+
19
+ ## Usage
20
+
21
+ Require Ruby 2.5 or later
22
+
23
+ Add below code into your `library`'s gemspec
24
+
25
+ ```ruby
26
+ Gem::Specification.new do |gem|
27
+ gem.add_development_dependency 'rspec-matchers-power_assert_matchers', '0.0.1'
28
+ end
29
+ ```
30
+
31
+ Or add below into your `application`'s `Gemfile`
32
+
33
+ ```ruby
34
+ group :test do
35
+ gem 'rspec-matchers-power_assert_matchers', '0.0.1'
36
+ end
37
+ ```
38
+
39
+ So adding this into your `spec_helper.rb` or `rails_helper.rb`
40
+
41
+ ```ruby
42
+ require 'rspec/matchers/power_assert_matchers'
43
+ ```
44
+
45
+ The you can use `power_assert` with a simple custom matcher in rspec.
46
+
47
+ Use `expect` with block, and use `be_assert` matcher.
48
+
49
+ ```ruby
50
+ RSpec.describe RSpec::Matchers::PowerAssertMatchers do
51
+ context 'when the given block returns falsy' do
52
+ it 'shows power_assert inspection' do
53
+ expect {
54
+ '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
55
+ }.to be_assert
56
+ end
57
+ end
58
+ end
59
+ ```
60
+
61
+ ```text
62
+ 1) RSpec::Matchers::PowerAssertMatchers when the given block returns falsy shows power_assert inspection
63
+ Failure/Error:
64
+ expect {
65
+ '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
66
+ }.to be_assert
67
+
68
+ '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
69
+ | | | | | |
70
+ | | | | | Array
71
+ | | | | [1, 2, 3]
72
+ | | | #<Enumerator: ...>
73
+ | | 3
74
+ | false
75
+ String
76
+ # ./examples/spec/example_spec.rb:6:in `block (3 levels) in <top (required)>'
77
+ ```
78
+
79
+ If you want to easy to check the behavior, this repository has example specs.
80
+
81
+ ```console
82
+ $ git clone git@github.com:kachick/rspec-matchers-power_assert_matchers.git
83
+ $ cd rspec-matchers-power_assert_matchers
84
+ $ cat ./examples/spec/example_spec.rb
85
+ Rough examples will be shown!
86
+ $ bundle install
87
+ $ bundle exec rake look_at_examples
88
+ Some results will be shown!
89
+ ```
90
+
91
+ ## NOTE
92
+
93
+ * Currently the matcher is named `be_assert`. I don't have confident it is good ot not.
94
+ * Extending built-in `be_truthy` sounds good for considering the role, but I would not like to add monkey patching for built-in features...
95
+
96
+ ## References
97
+
98
+ * [power-assert-js/power-assert](https://github.com/power-assert-js/power-assert)
99
+ * [Power Assert in Ruby](https://speakerdeck.com/k_tsj/power-assert-in-ruby)
100
+ * [Another way of power_assert in rspec - joker1007/rspec-power_assert](https://github.com/joker1007/rspec-power_assert)
@@ -0,0 +1,63 @@
1
+ # coding: us-ascii
2
+ # frozen_string_literal: true
3
+ # Copyright (C) 2021 Kenichi Kamiya
4
+
5
+ require 'power_assert'
6
+ require 'power_assert/colorize'
7
+ require 'rspec'
8
+ require 'rspec/expectations'
9
+
10
+ module RSpec
11
+ module Matchers
12
+ module PowerAssertMatchers
13
+ end
14
+ end
15
+ end
16
+
17
+ # refs for implementations:
18
+ # * https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/lib/rspec/matchers.rb
19
+ # * https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/features/custom_matchers/define_block_matcher.feature
20
+ # * https://github.com/rspec/rspec-expectations/blob/040d1b0bba83031c9ae432fd3a4462fdd1cc74e7/lib/rspec/matchers/dsl.rb#L64-L78
21
+ RSpec::Matchers.define(:be_assert) do
22
+ dsl_context = self
23
+
24
+ # https://github.com/rspec/rspec-expectations/blob/040d1b0bba83031c9ae432fd3a4462fdd1cc74e7/lib/rspec/matchers/dsl.rb#L104-L142
25
+ match(notify_expectation_failures: true) do |actual|
26
+ case actual
27
+ when Proc
28
+ result = ::PowerAssert.start(actual, assertion_method: __callee__) do |pa|
29
+ # https://github.com/rspec/rspec-expectations/blob/040d1b0bba83031c9ae432fd3a4462fdd1cc74e7/lib/rspec/matchers/dsl.rb#L200-L217
30
+ # @TODO: Should simulate be_truthy message? https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/lib/rspec/matchers/built_in/be.rb#L7-L18
31
+ dsl_context.failure_message do
32
+ pa.message_proc.call
33
+ end
34
+
35
+ pa.yield
36
+ end
37
+
38
+ result
39
+ when String
40
+ raise NotImplementedError
41
+ else
42
+ actual
43
+ end
44
+ end
45
+
46
+ supports_block_expectations
47
+
48
+ description do
49
+ 'as a be_truthy with power_assert'
50
+ end
51
+ end
52
+
53
+ require_relative 'power_assert_matchers/version'
54
+
55
+ module PowerAssert
56
+ INTERNAL_LIB_DIRS[RSpec::Matchers::PowerAssertMatchers] = File.dirname(
57
+ File.dirname(
58
+ File.dirname(
59
+ caller_locations(1, 1).first.path
60
+ )
61
+ )
62
+ )
63
+ end
@@ -0,0 +1,10 @@
1
+ # coding: us-ascii
2
+ # frozen_string_literal: true
3
+
4
+ module RSpec
5
+ module Matchers
6
+ module PowerAssertMatchers
7
+ VERSION = '0.0.1'
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,245 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-matchers-power_assert_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.5.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: power_assert
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: irb
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.3.5
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.5
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rspec
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.10.0
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.10.0
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '4.0'
93
+ - !ruby/object:Gem::Dependency
94
+ name: warning
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.2.0
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 1.2.0
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '2.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 13.0.3
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '20.0'
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 13.0.3
130
+ - - "<"
131
+ - !ruby/object:Gem::Version
132
+ version: '20.0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: rubocop
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.14.0
140
+ - - "<"
141
+ - !ruby/object:Gem::Version
142
+ version: 1.15.0
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 1.14.0
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.15.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-performance
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-rubycw
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-rspec
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description: "`power_assert in rspec` as a pure custom matcher"
210
+ email:
211
+ - kachick1+ruby@gmail.com
212
+ executables: []
213
+ extensions: []
214
+ extra_rdoc_files: []
215
+ files:
216
+ - LICENSE
217
+ - README.md
218
+ - lib/rspec/matchers/power_assert_matchers.rb
219
+ - lib/rspec/matchers/power_assert_matchers/version.rb
220
+ homepage: https://github.com/kachick/rspec-matchers-power_assert_matchers
221
+ licenses:
222
+ - MIT
223
+ metadata:
224
+ homepage_uri: https://github.com/kachick/rspec-matchers-power_assert_matchers
225
+ source_code_uri: https://github.com/kachick/rspec-matchers-power_assert_matchers
226
+ post_install_message:
227
+ rdoc_options: []
228
+ require_paths:
229
+ - lib
230
+ required_ruby_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: 2.5.0
235
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ requirements: []
241
+ rubygems_version: 3.2.15
242
+ signing_key:
243
+ specification_version: 4
244
+ summary: "`power_assert in rspec` as a pure custom matcher"
245
+ test_files: []