iba 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/LICENSE +1 -3
- data/README.md +67 -0
- data/lib/iba/version.rb +5 -0
- data/lib/iba.rb +114 -69
- metadata +80 -30
- data/README.rdoc +0 -62
- data/Rakefile +0 -16
- data/test/.rubocop.yml +0 -10
- data/test/analyse_test.rb +0 -78
- data/test/assert_test.rb +0 -51
- data/test/call_test.rb +0 -18
- data/test/display_test.rb +0 -57
- data/test/test_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdfcd93322a8c4127a2de4efcf83856c0c8a8432224ca5e202e17b6a290d9795
|
4
|
+
data.tar.gz: 78badd47ea46837d1189fb2806dcffa8d3c9a5ed957556200d32908071648a03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66a5c8de935f7afabeadf5aa6f07da23ee6ade4ec99b2c827b46d0a70e92d162dbf08850e6163e36c408f9b90e83c97437ef96f01d24804daf00d50bbab867c
|
7
|
+
data.tar.gz: 72b770be1f2bd34e296ee3b9d7ca3a2e2c170ec3758d465c44f22092d64c2754f328b3ad431d4dd824b03c712d39c24dc818ab4221d269daa20bbe41e9cb7f13
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.0.7 / 2024-01-05
|
4
|
+
|
5
|
+
* Support Ruby 3.0 through 3.3, and JRuby 9.4 ([#63], [#64] and [#68] by [mvz])
|
6
|
+
|
7
|
+
[#63]: https://github.com/mvz/iba/pull/63
|
8
|
+
[#64]: https://github.com/mvz/iba/pull/64
|
9
|
+
[#68]: https://github.com/mvz/iba/pull/68
|
10
|
+
|
11
|
+
## 0.0.6 / 2022-01-21
|
12
|
+
|
13
|
+
* Support Ruby 2.6 and up, as well as JRuby 9.3
|
14
|
+
* Display more subexpressions ([#13] by [mvz])
|
15
|
+
* Add and use VERSION constant ([#49] by [mvz])
|
16
|
+
|
17
|
+
[#13]: https://github.com/mvz/iba/pull/13
|
18
|
+
[#49]: https://github.com/mvz/iba/pull/49
|
19
|
+
|
20
|
+
## 0.0.5 / 2018-03-25
|
21
|
+
|
22
|
+
* Target Ruby 2.2 and up
|
23
|
+
* Remove all use of eval ([#1] by [mvz])
|
24
|
+
|
25
|
+
[mvz]: https://github.com/mvz
|
26
|
+
|
27
|
+
[#1]: https://github.com/mvz/iba/pull/1
|
28
|
+
|
29
|
+
## 0.0.4 / 2017-12-15
|
30
|
+
|
31
|
+
* Target Ruby 2.1 and up
|
32
|
+
|
33
|
+
## 0.0.3 / 2014-05-09
|
34
|
+
|
35
|
+
* Make Iba work with Ruby 1.9
|
36
|
+
|
37
|
+
## 0.0.2 / 2011-02-25
|
38
|
+
|
39
|
+
* Properly analyse comparison with arrays and strings
|
40
|
+
* Allow instance variables in asserted expression
|
41
|
+
|
42
|
+
## 0.0.1 / 2011-01-02
|
43
|
+
|
44
|
+
* Initial release
|
45
|
+
|
46
|
+
No match for: Prepare version 0.0.7 for release
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010--2011 Matijs van Zuijlen
|
1
|
+
Copyright (c) 2010--2011, 2014-2024 Matijs van Zuijlen
|
2
2
|
|
3
3
|
Iba is free software; you can redistribute it and/or modify it under the
|
4
4
|
terms of the GNU Lesser General Public License as published by the Free Software
|
@@ -12,5 +12,3 @@ more details.
|
|
12
12
|
|
13
13
|
You should have received a copy of the GNU Lesser General Public License
|
14
14
|
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Iba
|
2
|
+
|
3
|
+
by Matijs van Zuijlen
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Introspective Block Assertions
|
8
|
+
|
9
|
+
## Features/Problems
|
10
|
+
|
11
|
+
* Write assertions as a (one-expression) block
|
12
|
+
* Assertion message deconstructs the block's expression.
|
13
|
+
* Not done yet.
|
14
|
+
|
15
|
+
## Synopsis
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# In your test helper:
|
19
|
+
require 'iba'
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
include Iba::BlockAssertion
|
22
|
+
end
|
23
|
+
|
24
|
+
# In your test:
|
25
|
+
foo = 24
|
26
|
+
assert { foo == 23 } # => "(foo == 23) is false
|
27
|
+
# foo is 24."
|
28
|
+
```
|
29
|
+
|
30
|
+
## Details
|
31
|
+
|
32
|
+
Iba provides an assert method that takes a block. If the block returns
|
33
|
+
false, it will try to construct an insightful error message based on the
|
34
|
+
contents of the block.
|
35
|
+
|
36
|
+
Iba's functionality is inspired by [Wrong], but doesn't use an external
|
37
|
+
Ruby parser. This means it will work in contexts where Wrong does not
|
38
|
+
(generated code, on the command line). It also means there are more limits
|
39
|
+
to the contents of the block.
|
40
|
+
|
41
|
+
Current limits:
|
42
|
+
|
43
|
+
* Only single-expression blocks are supported.
|
44
|
+
* The expression must start with a method-like identifier or an instance
|
45
|
+
variable (like `foo` or `@foo`, but not `Foo` or `23`). In practice,
|
46
|
+
this produces quite natural results.
|
47
|
+
* Local and instance variables whose names start with an underscore should
|
48
|
+
not be used inside the block.
|
49
|
+
|
50
|
+
Iba's implementation is inspired by [Arlo], a generic combinator library
|
51
|
+
for Python. The implementation of Arlo is now [on github][arlo-code].
|
52
|
+
|
53
|
+
## Install
|
54
|
+
|
55
|
+
```
|
56
|
+
gem install iba
|
57
|
+
```
|
58
|
+
|
59
|
+
<!-- Links -->
|
60
|
+
|
61
|
+
[Wrong]: https://github.com/sconover/wrong
|
62
|
+
[Arlo]: https://web.archive.org/web/20081228090759/http://withoutane.com:80/rants/2008/12/arlo-generic-combinators-for-python
|
63
|
+
[arlo-code]: https://github.com/tangentstorm/workshop/blob/main/code/arlo.py
|
64
|
+
|
65
|
+
## Licence
|
66
|
+
|
67
|
+
See the LICENSE file
|
data/lib/iba/version.rb
ADDED
data/lib/iba.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "iba/version"
|
4
|
+
|
1
5
|
module Iba
|
2
6
|
class Combinator
|
3
|
-
def initialize
|
7
|
+
def initialize(&blk)
|
4
8
|
@block = blk
|
5
9
|
end
|
6
10
|
|
@@ -17,38 +21,24 @@ module Iba
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def analyse
|
20
|
-
str = "#{self} is #{call.inspect}"
|
21
|
-
|
22
|
-
|
23
|
-
rgt = expression._args.first
|
24
|
-
exprs = [lft, rgt].map { |e| display_subexpression e }.compact
|
25
|
-
str << "\n"
|
26
|
-
str << exprs.join(', ')
|
27
|
-
end
|
24
|
+
str = +"#{self} is #{call.inspect}"
|
25
|
+
sub = expression._display_subexpressions(@block.binding)
|
26
|
+
str << "\n#{sub}" if sub
|
28
27
|
str
|
29
28
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def display_subexpression expr
|
34
|
-
if expr.class == LiteralExpression
|
35
|
-
nil
|
36
|
-
else
|
37
|
-
str = expr._to_s
|
38
|
-
value = expr._evaluate(@block.binding).inspect
|
39
|
-
"#{str} is #{value}"
|
40
|
-
end
|
41
|
-
end
|
42
29
|
end
|
43
30
|
|
44
31
|
class BaseExpression
|
45
|
-
def method_missing
|
46
|
-
|
32
|
+
def method_missing(method, *args)
|
33
|
+
# FIXME: Remove to_s once support for Ruby < 2.7 is dropped
|
34
|
+
super if method.to_s.start_with? "_"
|
47
35
|
MethodCallExpression.new self, method, args
|
48
36
|
end
|
49
37
|
|
50
|
-
def respond_to_missing?
|
51
|
-
|
38
|
+
def respond_to_missing?(method)
|
39
|
+
# FIXME: Remove to_s once support for Ruby < 2.7 is dropped
|
40
|
+
return super if method.to_s.start_with? "_"
|
41
|
+
|
52
42
|
true
|
53
43
|
end
|
54
44
|
|
@@ -56,11 +46,15 @@ module Iba
|
|
56
46
|
method_missing :to_s
|
57
47
|
end
|
58
48
|
|
59
|
-
def ==
|
49
|
+
def ==(other)
|
60
50
|
method_missing :==, other
|
61
51
|
end
|
62
52
|
|
63
|
-
def
|
53
|
+
def !=(other)
|
54
|
+
method_missing :!=, other
|
55
|
+
end
|
56
|
+
|
57
|
+
def _wrap(arg)
|
64
58
|
if arg.is_a? BaseExpression
|
65
59
|
arg
|
66
60
|
else
|
@@ -68,13 +62,22 @@ module Iba
|
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
71
|
-
def
|
65
|
+
def _display(_bnd)
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def _display_subexpressions(_bnd)
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# Handle numeric operator coersion
|
74
|
+
def coerce(other)
|
72
75
|
[_wrap(other), self]
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
79
|
class EmptyExpression < BaseExpression
|
77
|
-
def _parse
|
80
|
+
def _parse(&blk)
|
78
81
|
bnd = blk.binding
|
79
82
|
|
80
83
|
vars = bnd.local_variables
|
@@ -92,35 +95,42 @@ module Iba
|
|
92
95
|
result
|
93
96
|
end
|
94
97
|
|
95
|
-
def _override_instance_variables
|
98
|
+
def _override_instance_variables(vars)
|
96
99
|
vars.each do |v|
|
97
|
-
|
100
|
+
# FIXME: Remove to_s once support for Ruby < 2.7 is dropped
|
101
|
+
next if v.to_s.start_with? "@_"
|
102
|
+
|
98
103
|
instance_variable_set v, Iba::InstanceVariableExpression.new(v.to_sym)
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
102
|
-
def _override_local_variables
|
107
|
+
def _override_local_variables(vars, bnd)
|
103
108
|
vars.each do |v|
|
104
|
-
|
109
|
+
# FIXME: Remove to_s once support for Ruby < 2.7 is dropped
|
110
|
+
next if v.to_s.start_with? "_"
|
111
|
+
|
105
112
|
bnd.local_variable_set "_#{v}", bnd.local_variable_get(v)
|
106
113
|
bnd.local_variable_set v, LocalVariableExpression.new(v.to_sym)
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
110
|
-
def _restore_local_variables
|
117
|
+
def _restore_local_variables(vars, bnd)
|
111
118
|
vars.each do |v|
|
112
|
-
|
119
|
+
# FIXME: Remove to_s once support for Ruby < 2.7 is dropped
|
120
|
+
next if v.to_s.start_with? "_"
|
121
|
+
|
113
122
|
bnd.local_variable_set v, bnd.local_variable_get("_#{v}")
|
114
123
|
end
|
115
124
|
end
|
116
125
|
|
117
126
|
def _to_s
|
118
|
-
|
127
|
+
""
|
119
128
|
end
|
120
129
|
end
|
121
130
|
|
122
131
|
class LiteralExpression < BaseExpression
|
123
|
-
def initialize
|
132
|
+
def initialize(val)
|
133
|
+
super()
|
124
134
|
@value = val
|
125
135
|
end
|
126
136
|
|
@@ -128,13 +138,22 @@ module Iba
|
|
128
138
|
@value.inspect
|
129
139
|
end
|
130
140
|
|
131
|
-
def _evaluate
|
141
|
+
def _evaluate(_bnd)
|
132
142
|
@value
|
133
143
|
end
|
134
144
|
end
|
135
145
|
|
136
|
-
class
|
137
|
-
def
|
146
|
+
class DisplayableExpression < BaseExpression
|
147
|
+
def _display(bnd)
|
148
|
+
str = _to_s
|
149
|
+
value = _evaluate(bnd).inspect
|
150
|
+
"#{str} is #{value}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class InstanceVariableExpression < DisplayableExpression
|
155
|
+
def initialize(ivar_name)
|
156
|
+
super()
|
138
157
|
@_ivar_name = ivar_name
|
139
158
|
end
|
140
159
|
|
@@ -142,13 +161,14 @@ module Iba
|
|
142
161
|
@_ivar_name.to_s
|
143
162
|
end
|
144
163
|
|
145
|
-
def _evaluate
|
164
|
+
def _evaluate(bnd)
|
146
165
|
bnd.receiver.instance_variable_get @_ivar_name
|
147
166
|
end
|
148
167
|
end
|
149
168
|
|
150
|
-
class LocalVariableExpression <
|
151
|
-
def initialize
|
169
|
+
class LocalVariableExpression < DisplayableExpression
|
170
|
+
def initialize(lvar_name)
|
171
|
+
super()
|
152
172
|
@_lvar_name = lvar_name
|
153
173
|
end
|
154
174
|
|
@@ -156,69 +176,94 @@ module Iba
|
|
156
176
|
@_lvar_name.to_s
|
157
177
|
end
|
158
178
|
|
159
|
-
def _evaluate
|
179
|
+
def _evaluate(bnd)
|
160
180
|
bnd.local_variable_get @_lvar_name
|
161
181
|
end
|
162
182
|
end
|
163
183
|
|
164
|
-
class MethodCallExpression <
|
184
|
+
class MethodCallExpression < DisplayableExpression
|
165
185
|
attr_reader :_method, :_reciever, :_args
|
166
186
|
|
167
|
-
def initialize
|
187
|
+
def initialize(reciever, methodname, args)
|
188
|
+
super()
|
168
189
|
@_reciever = reciever
|
169
190
|
@_method = methodname
|
170
191
|
@_args = args.map { |a| _wrap(a) }
|
171
192
|
end
|
172
193
|
|
173
194
|
def _to_s
|
174
|
-
rcv = @_reciever._to_s
|
175
|
-
args = @_args.map { |a| a.respond_to?(:_to_s) ? a._to_s : a.to_s }
|
176
|
-
|
177
195
|
if @_method == :[]
|
178
|
-
|
196
|
+
_index_to_s
|
179
197
|
elsif _method_is_operator?
|
180
|
-
|
181
|
-
when 0
|
182
|
-
"#{@_method.to_s.sub(/@$/, '')}#{rcv}"
|
183
|
-
when 1
|
184
|
-
"(#{rcv} #{@_method} #{args.first})"
|
185
|
-
else
|
186
|
-
raise NotImplementedError
|
187
|
-
end
|
198
|
+
_operator_to_s
|
188
199
|
else
|
189
|
-
|
190
|
-
str << @_method.to_s
|
191
|
-
str << "(#{args.join(', ')})" unless @_args.empty?
|
192
|
-
str
|
200
|
+
_regular_method_to_s
|
193
201
|
end
|
194
202
|
end
|
195
203
|
|
196
|
-
def _evaluate
|
204
|
+
def _evaluate(bnd)
|
197
205
|
rcv = @_reciever._evaluate(bnd)
|
198
206
|
args = @_args.map { |arg| arg._evaluate(bnd) }
|
199
207
|
rcv.send @_method, *args
|
200
208
|
end
|
201
209
|
|
210
|
+
def _display_subexpressions(bnd)
|
211
|
+
rcv = @_reciever._display(bnd)
|
212
|
+
args = @_args.map { |arg| arg._display(bnd) }
|
213
|
+
[rcv, *args].compact.join(", ")
|
214
|
+
end
|
215
|
+
|
202
216
|
private
|
203
217
|
|
218
|
+
def _receiver_s
|
219
|
+
@_reciever._to_s
|
220
|
+
end
|
221
|
+
|
222
|
+
def _args_s
|
223
|
+
@_args.map { |a| a.respond_to?(:_to_s) ? a._to_s : a.to_s }
|
224
|
+
end
|
225
|
+
|
226
|
+
def _index_to_s
|
227
|
+
"#{_receiver_s}[#{_args_s[0]}]"
|
228
|
+
end
|
229
|
+
|
230
|
+
def _operator_to_s
|
231
|
+
case @_args.length
|
232
|
+
when 0
|
233
|
+
"#{@_method.to_s.sub(/@$/, '')}#{_receiver_s}"
|
234
|
+
when 1
|
235
|
+
"(#{_receiver_s} #{@_method} #{_args_s.first})"
|
236
|
+
else
|
237
|
+
raise NotImplementedError
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def _regular_method_to_s
|
242
|
+
rcv = _receiver_s
|
243
|
+
str = rcv == "" ? +"" : +"#{rcv}."
|
244
|
+
str << @_method.to_s
|
245
|
+
str << "(#{_args_s.join(', ')})" unless @_args.empty?
|
246
|
+
str
|
247
|
+
end
|
248
|
+
|
204
249
|
def _method_is_operator?
|
205
250
|
@_method.to_s !~ /^[a-z]/
|
206
251
|
end
|
207
252
|
end
|
208
253
|
|
209
254
|
module BlockAssertion
|
210
|
-
def assert
|
211
|
-
if
|
255
|
+
def assert(*args, &block)
|
256
|
+
if block
|
212
257
|
if yield
|
213
|
-
assert_block(
|
258
|
+
assert_block("true") { true }
|
214
259
|
else
|
215
|
-
msg = args.empty? ?
|
216
|
-
ana = Combinator.new(&
|
260
|
+
msg = args.empty? ? "" : "#{args.first}.\n"
|
261
|
+
ana = Combinator.new(&block).analyse
|
217
262
|
assert_block("#{msg}#{ana}.") { false }
|
218
263
|
end
|
219
264
|
else
|
220
265
|
test, msg = *args
|
221
|
-
super
|
266
|
+
super(test, msg)
|
222
267
|
end
|
223
268
|
end
|
224
269
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matijs van Zuijlen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '13.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-manifest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.52'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.52'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-packaging
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.18'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.18'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: test-unit
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,57 +94,51 @@ dependencies:
|
|
38
94
|
- - "~>"
|
39
95
|
- !ruby/object:Gem::Version
|
40
96
|
version: '3.1'
|
41
|
-
description: Asserts blocks, prints introspective failure messages.
|
97
|
+
description: 'Asserts blocks, prints introspective failure messages.
|
98
|
+
|
99
|
+
'
|
42
100
|
email:
|
43
101
|
- matijs@matijs.net
|
44
102
|
executables: []
|
45
103
|
extensions: []
|
46
104
|
extra_rdoc_files:
|
47
|
-
- README.
|
105
|
+
- README.md
|
48
106
|
- LICENSE
|
49
107
|
- COPYING.LESSER
|
50
108
|
files:
|
109
|
+
- CHANGELOG.md
|
51
110
|
- COPYING.LESSER
|
52
111
|
- LICENSE
|
53
|
-
- README.
|
54
|
-
- Rakefile
|
112
|
+
- README.md
|
55
113
|
- lib/iba.rb
|
56
|
-
-
|
57
|
-
- test/analyse_test.rb
|
58
|
-
- test/assert_test.rb
|
59
|
-
- test/call_test.rb
|
60
|
-
- test/display_test.rb
|
61
|
-
- test/test_helper.rb
|
114
|
+
- lib/iba/version.rb
|
62
115
|
homepage: http://www.github.com/mvz/iba
|
63
116
|
licenses:
|
64
|
-
- LGPL-3
|
65
|
-
metadata:
|
66
|
-
|
117
|
+
- LGPL-3.0+
|
118
|
+
metadata:
|
119
|
+
homepage_uri: http://www.github.com/mvz/iba
|
120
|
+
source_code_uri: https://github.com/mvz/iba
|
121
|
+
changelog_uri: https://github.com/mvz/iba/blob/master/CHANGELOG.md
|
122
|
+
rubygems_mfa_required: 'true'
|
123
|
+
post_install_message:
|
67
124
|
rdoc_options:
|
68
125
|
- "--main"
|
69
|
-
- README.
|
126
|
+
- README.md
|
70
127
|
require_paths:
|
71
128
|
- lib
|
72
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
130
|
requirements:
|
74
131
|
- - ">="
|
75
132
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
133
|
+
version: 3.0.0
|
77
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
135
|
requirements:
|
79
136
|
- - ">="
|
80
137
|
- !ruby/object:Gem::Version
|
81
138
|
version: '0'
|
82
139
|
requirements: []
|
83
|
-
|
84
|
-
|
85
|
-
signing_key:
|
140
|
+
rubygems_version: 3.5.3
|
141
|
+
signing_key:
|
86
142
|
specification_version: 4
|
87
143
|
summary: Introspective Block Assertions
|
88
|
-
test_files:
|
89
|
-
- test/.rubocop.yml
|
90
|
-
- test/analyse_test.rb
|
91
|
-
- test/assert_test.rb
|
92
|
-
- test/call_test.rb
|
93
|
-
- test/display_test.rb
|
94
|
-
- test/test_helper.rb
|
144
|
+
test_files: []
|
data/README.rdoc
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
= Iba
|
2
|
-
|
3
|
-
by Matijs van Zuijlen
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
Introspective Block Assertions
|
8
|
-
|
9
|
-
== Features/Problems
|
10
|
-
|
11
|
-
* Write assertions as a (one-expression) block
|
12
|
-
* Assertion message deconstructs the block's expression.
|
13
|
-
* Not done yet.
|
14
|
-
|
15
|
-
== Synopsis
|
16
|
-
|
17
|
-
# In your test helper:
|
18
|
-
require 'iba'
|
19
|
-
class Test::Unit::TestCase
|
20
|
-
include Iba::BlockAssertion
|
21
|
-
end
|
22
|
-
|
23
|
-
# In your test:
|
24
|
-
foo = 24
|
25
|
-
assert { foo == 23 } # => "(foo == 23) is false
|
26
|
-
# foo is 24."
|
27
|
-
|
28
|
-
== Details
|
29
|
-
|
30
|
-
Iba provides an assert method that takes a block. If the block returns
|
31
|
-
false, it will try to construct an insightful error message based on the
|
32
|
-
contents of the block.
|
33
|
-
|
34
|
-
Iba's functionality is inspired by Wrong[1], but doesn't use an external
|
35
|
-
Ruby parser. This means it will work in contexts where Wrong does not
|
36
|
-
(generated code, on the command line). It also means there are more limits
|
37
|
-
to the contents of the block.
|
38
|
-
|
39
|
-
Current limits:
|
40
|
-
|
41
|
-
* Only single-expression blocks are supported.
|
42
|
-
* The expression must start with a method-like identifier or an instance
|
43
|
-
variable (like 'foo' or '@foo', but not 'Foo' or '23'). In practice,
|
44
|
-
this produces quite natural results.
|
45
|
-
* Local and instance variables whose names start with an underscore should
|
46
|
-
not be used inside the block.
|
47
|
-
|
48
|
-
Iba's implementation is inspired by Arlo[2], a generic combinator library
|
49
|
-
for Python.
|
50
|
-
|
51
|
-
== Install
|
52
|
-
|
53
|
-
gem install iba
|
54
|
-
|
55
|
-
== Links
|
56
|
-
|
57
|
-
[1] https://github.com/sconover/wrong
|
58
|
-
[2] http://withoutane.com/rants/2008/12/arlo-generic-combinators-for-python
|
59
|
-
|
60
|
-
== Licence
|
61
|
-
|
62
|
-
See the LICENSE file.
|
data/Rakefile
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rake/clean'
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
namespace :test do
|
6
|
-
Rake::TestTask.new(:run) do |t|
|
7
|
-
t.libs = ['lib']
|
8
|
-
t.test_files = FileList['test/**/*_test.rb']
|
9
|
-
t.ruby_opts += ['-w']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Alias to test:run'
|
14
|
-
task test: 'test:run'
|
15
|
-
|
16
|
-
task default: 'test:run'
|
data/test/.rubocop.yml
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
inherit_from: ../.rubocop.yml
|
2
|
-
|
3
|
-
# We need to rescue Exception to test exceptions thrown by assert
|
4
|
-
# TODO: Remove once support for Ruby 1.8 is dropped.
|
5
|
-
Lint/RescueException:
|
6
|
-
Enabled: false
|
7
|
-
|
8
|
-
# Allow compact syntax when adding to Test::Unit::TestCase
|
9
|
-
Style/ClassAndModuleChildren:
|
10
|
-
Enabled: false
|
data/test/analyse_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
# Test how the combinator analyses the parsed block contents.
|
4
|
-
class AnalyseTest < Test::Unit::TestCase
|
5
|
-
def test_empty_block
|
6
|
-
assert_equal 'nil is nil', combinator {}.analyse
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_variable
|
10
|
-
foo = 23
|
11
|
-
assert_equal 'foo is 23', combinator { foo }.analyse
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_operator_equals
|
15
|
-
foo = 42
|
16
|
-
bar = 23
|
17
|
-
result = combinator { foo == bar }.analyse
|
18
|
-
assert_equal "(foo == bar) is false\nfoo is 42, bar is 23", result
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_operator_equals_literal
|
22
|
-
foo = 42
|
23
|
-
result = combinator { foo == 23 }.analyse
|
24
|
-
assert_equal "(foo == 23) is false\nfoo is 42", result
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_operator_equals_array_literal
|
28
|
-
foo = [1, 'bar']
|
29
|
-
result = combinator { foo == [2, 'baz'] }.analyse
|
30
|
-
assert_equal "(foo == [2, \"baz\"]) is false\nfoo is [1, \"bar\"]", result
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_string_variable
|
34
|
-
foo = 'blub'
|
35
|
-
assert_equal 'foo is "blub"', combinator { foo }.analyse
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_array_variable
|
39
|
-
foo = [1, 2]
|
40
|
-
assert_equal 'foo is [1, 2]', combinator { foo }.analyse
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_object_variable
|
44
|
-
foo = Object.new
|
45
|
-
insp = foo.inspect
|
46
|
-
assert_equal "foo is #{insp}", combinator { foo }.analyse
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_literal
|
50
|
-
assert_equal '23 is 23', combinator { 23 }.analyse
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_instance_variable
|
54
|
-
@foo = 23
|
55
|
-
assert_equal '@foo is 23', combinator { @foo }.analyse
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_instance_variable_method_call
|
59
|
-
@foo = 23
|
60
|
-
assert_equal "(@foo == 23) is true\n@foo is 23", combinator { @foo == 23 }.analyse
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_instance_variable_as_argument_of_operator
|
64
|
-
@foo = 23
|
65
|
-
assert_equal '(23 + @foo) is 46', combinator { 23 + @foo }.analyse
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_complex_subexpressions
|
69
|
-
@foo = 23
|
70
|
-
bar = 42
|
71
|
-
baz = [42]
|
72
|
-
result = combinator { (@foo + baz.first) == (bar + 23) }.analyse
|
73
|
-
assert_equal \
|
74
|
-
"((@foo + baz.first) == (bar + 23)) is true\n" \
|
75
|
-
'(@foo + baz.first) is 65, (bar + 23) is 65',
|
76
|
-
result
|
77
|
-
end
|
78
|
-
end
|
data/test/assert_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
# Test behavior of overridden assert method.
|
4
|
-
class AssertTest < Test::Unit::TestCase
|
5
|
-
def test_simple_assert
|
6
|
-
assert { true }
|
7
|
-
end
|
8
|
-
|
9
|
-
def failing_block_assertion_test message, &block
|
10
|
-
assert(&block)
|
11
|
-
rescue Exception => e
|
12
|
-
assert_equal message, e.message
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_simple_failing_assert
|
16
|
-
failing_block_assertion_test('false is false.') { false }
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_operator_equals_assert
|
20
|
-
foo = 24
|
21
|
-
failing_block_assertion_test("(foo == 23) is false\nfoo is 24.") { foo == 23 }
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_instance_variable_assert
|
25
|
-
@foo = 24
|
26
|
-
failing_block_assertion_test("(@foo == 23) is false\n@foo is 24.") { @foo == 23 }
|
27
|
-
end
|
28
|
-
|
29
|
-
# Special cases
|
30
|
-
|
31
|
-
def test_assert_with_custom_message
|
32
|
-
foo = false
|
33
|
-
begin
|
34
|
-
assert('We want foo') { foo }
|
35
|
-
rescue Exception => e
|
36
|
-
assert_equal "We want foo.\nfoo is false.", e.message
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_blockless_assert
|
41
|
-
assert false
|
42
|
-
rescue Exception => e
|
43
|
-
assert_equal '<false> is not true.', e.message
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_blockless_assert_with_custom_message
|
47
|
-
assert false, 'We want the truth'
|
48
|
-
rescue Exception => e
|
49
|
-
assert_equal "We want the truth.\n<false> is not true.", e.message
|
50
|
-
end
|
51
|
-
end
|
data/test/call_test.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
# Test how the combinator calls the passed block.
|
4
|
-
class CallTest < Test::Unit::TestCase
|
5
|
-
def test_empty_combinator
|
6
|
-
assert_equal nil, combinator {}.call
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_variable
|
10
|
-
foo = 23
|
11
|
-
assert_equal 23, combinator { foo }.call
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_operator_call
|
15
|
-
foo = 23
|
16
|
-
assert_equal true, combinator { foo == 23 }.call
|
17
|
-
end
|
18
|
-
end
|
data/test/display_test.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
# Test how the combinator displays the parsed block contents.
|
4
|
-
class DisplayTest < Test::Unit::TestCase
|
5
|
-
def test_empty_combinator
|
6
|
-
assert_equal 'nil', combinator {}.to_s
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_literal_number
|
10
|
-
assert_equal '23', combinator { 23 }.to_s
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_literal_string
|
14
|
-
assert_equal '"aa"', combinator { 'aa' }.to_s
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_method_calls
|
18
|
-
assert_equal 'foo', combinator { foo }.to_s
|
19
|
-
assert_equal 'foo.foo', combinator { foo.foo }.to_s
|
20
|
-
assert_equal 'foo.foo(1)', combinator { foo.foo 1 }.to_s
|
21
|
-
assert_equal 'foo(1)', combinator { foo 1 }.to_s
|
22
|
-
assert_equal 'foo(bar)', combinator { foo bar }.to_s
|
23
|
-
assert_equal 'foo(1).bar', combinator { foo(1).bar }.to_s
|
24
|
-
assert_equal 'foo.foo.foo', combinator { foo.foo.foo }.to_s
|
25
|
-
assert_equal 'foo(bar.baz)', combinator { foo bar.baz }.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_operators
|
29
|
-
assert_equal '(foo + 1)', combinator { foo + 1 }.to_s
|
30
|
-
assert_equal '(foo - 1)', combinator { foo - 1 }.to_s
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_operator_equals
|
34
|
-
assert_equal '(foo == 1)', combinator { foo == 1 }.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_array_index
|
38
|
-
assert_equal 'foo[1]', combinator { foo[1] }.to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_to_s_method
|
42
|
-
assert_equal 'foo.to_s', combinator { foo.to_s }.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_operator_unary_minus
|
46
|
-
assert_equal '-foo', combinator { -foo }.to_s
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_operator_if_wont_work
|
50
|
-
assert_equal 'bar', combinator { foo ? bar : baz }.to_s
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_defined_instance_variables
|
54
|
-
@foo = 1
|
55
|
-
assert_equal '@foo', combinator { @foo }.to_s
|
56
|
-
end
|
57
|
-
end
|