irb-power_assert 0.2.0 → 0.3.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 +4 -4
- data/README.md +28 -44
- data/lib/irb/cmd/pa.rb +34 -13
- data/lib/irb/power_assert/version.rb +1 -1
- data/lib/irb/power_assert.rb +2 -11
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34cab348502eee4a1187962266285e636698fa21fd0b79f95f1a7ca36f1fe498
|
4
|
+
data.tar.gz: d4c4e37efd959eea65260eda2aca9388a083382459bd7fc3db8ecc6b488bb2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f5530d85217e1493182c8c9078f0a3271c41d2b386c7f5b9e9221ac7b237cd56325862c767fac6dfefaf3c980df9381376c63d7485f699564fb5f7685c0beb
|
7
|
+
data.tar.gz: 9fc63bdefc97312dcfc16a1e7afd543a1ce30252956aadc321bd44112d38afa1291b5be4771a617d1dbd6eb4f37f897199d9990d935439722e86c2e44ed4d74e
|
data/README.md
CHANGED
@@ -3,34 +3,21 @@
|
|
3
3
|
[](https://github.com/kachick/irb-power_assert/actions/workflows/ci-ruby.yml?query=branch%3Amain+)
|
4
4
|
[](http://badge.fury.io/rb/irb-power_assert)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-

|
9
|
-
|
10
|
-
[ruby/power_assert](https://github.com/ruby/power_assert) is a recent my favorites.\
|
11
|
-
(the author is [@k-tsj](https://github.com/k-tsj), thank you!)
|
12
|
-
|
13
|
-
It is super helpful in complex testing.
|
14
|
-
|
15
|
-
Don't say [ruby/irb](https://github.com/ruby/irb) is old-fashioned.
|
16
|
-
|
17
|
-
I just would get irb version of
|
18
|
-
[yui-knk/pry-power_assert](https://github.com/yui-knk/pry-power_assert)
|
19
|
-
|
20
|
-
Honor should be bestowed upon them.
|
6
|
+
Use power_assert inspection in irb
|
21
7
|
|
22
8
|
## Usage
|
23
9
|
|
24
|
-
|
10
|
+
Tested only in ruby-head and the last 2 stable versions\
|
11
|
+
So require Ruby 3.2 or higher
|
25
12
|
|
26
13
|
```console
|
27
14
|
$ gem install irb-power_assert
|
28
|
-
|
15
|
+
...installed
|
29
16
|
```
|
30
17
|
|
31
18
|
```console
|
32
19
|
$ irb -r irb-power_assert
|
33
|
-
#
|
20
|
+
# enabled this gem
|
34
21
|
```
|
35
22
|
|
36
23
|
Or specify in your `~/.irbrc` as below
|
@@ -41,37 +28,14 @@ require 'irb/power_assert'
|
|
41
28
|
|
42
29
|
```console
|
43
30
|
$ irb
|
44
|
-
|
31
|
+
irb(main):004> help pa
|
32
|
+
Print PowerAssert inspection for the given expression.
|
45
33
|
```
|
46
34
|
|
47
35
|
Then you can use `pa` as an IRB command.
|
48
36
|
|
49
|
-
```ruby
|
50
|
-
irb(main):001:0> pa %q{ "0".class == "3".to_i.times.map {|i| i + 1 }.class }
|
51
|
-
result: false
|
52
|
-
|
53
|
-
"0".class == "3".to_i.times.map {|i| i + 1 }.class
|
54
|
-
| | | | | |
|
55
|
-
| | | | | Array
|
56
|
-
| | | | [1, 2, 3]
|
57
|
-
| | | #<Enumerator: ...>
|
58
|
-
| | 3
|
59
|
-
| false
|
60
|
-
String
|
61
|
-
=> nil
|
62
|
-
```
|
63
|
-
|
64
|
-
The `pa` just takes strings of the code.
|
65
|
-
|
66
|
-
If you want to directly pass `expression`, [.irbrc](examples/.irbrc) is the hack for single line code.\
|
67
|
-
if you don't have the file yet, putting the file as one of your `$IRBRC`, `$XDG_CONFIG_HOME/irb/irbrc` or `$HOME/.irbrc`
|
68
|
-
|
69
|
-
Then you can use the `pa` as below...
|
70
|
-
|
71
37
|
```ruby
|
72
38
|
irb(main):001:0> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class
|
73
|
-
result: false
|
74
|
-
|
75
39
|
"0".class == "3".to_i.times.map {|i| i + 1 }.class
|
76
40
|
| | | | | |
|
77
41
|
| | | | | Array
|
@@ -80,11 +44,31 @@ result: false
|
|
80
44
|
| | 3
|
81
45
|
| false
|
82
46
|
String
|
83
|
-
|
47
|
+
|
48
|
+
=> false
|
84
49
|
```
|
85
50
|
|
51
|
+
No hack is needed in your irbrc
|
52
|
+
|
53
|
+
## Thanks!
|
54
|
+
|
55
|
+
[ruby/power_assert](https://github.com/ruby/power_assert) is a recent my favorites.\
|
56
|
+
(the author is [@k-tsj](https://github.com/k-tsj), thank you!)
|
57
|
+
|
58
|
+
It is super helpful in complex testing.
|
59
|
+
|
60
|
+
Don't say [ruby/irb](https://github.com/ruby/irb) is old-fashioned.
|
61
|
+
|
62
|
+
I just would get irb version of
|
63
|
+
[yui-knk/pry-power_assert](https://github.com/yui-knk/pry-power_assert).
|
64
|
+
|
65
|
+
Latest IRB is much helpful to [create own command](https://github.com/ruby/irb/pull/886)
|
66
|
+
|
67
|
+
Honor should be bestowed upon them.
|
68
|
+
|
86
69
|
## References
|
87
70
|
|
88
71
|
- [power-assert-js/power-assert](https://github.com/power-assert-js/power-assert)
|
89
72
|
- [Power Assert in Ruby](https://speakerdeck.com/k_tsj/power-assert-in-ruby)
|
90
73
|
- [ja - IRB is new than Pry](https://k0kubun.hatenablog.com/entry/2021/04/02/211455)
|
74
|
+
- [pry-power_assert implementation](https://github.com/yui-knk/pry-power_assert/blob/2d10ee3df8efaf9c448f31d51bff8033a1792739/lib/pry-power_assert.rb#L26-L35)
|
data/lib/irb/cmd/pa.rb
CHANGED
@@ -1,24 +1,45 @@
|
|
1
1
|
# coding: us-ascii
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'irb/cmd/nop'
|
5
4
|
require 'power_assert'
|
6
5
|
require 'power_assert/colorize'
|
7
6
|
|
8
7
|
module IRB
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
class PaCommand < IRB::Command::Base
|
9
|
+
description 'Show inspections for each result.'
|
10
|
+
category 'Misc'
|
11
|
+
help_message 'Print PowerAssert inspection for the given expression.'
|
12
|
+
|
13
|
+
def usage
|
14
|
+
<<~'EOD'
|
15
|
+
`pa` command will work for expressions that includes method calling.
|
16
|
+
e.g. `pa (2 * 3 * 7).abs == 1010102.to_s.to_i(2)`
|
17
|
+
EOD
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute(expression)
|
21
|
+
if expression == ''
|
22
|
+
# Avoid warn and raise here, warn does not appear in irb and exception sounds like a IRB bug
|
23
|
+
puts usage
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
result = nil
|
28
|
+
inspection = nil
|
29
|
+
::PowerAssert.start(expression, source_binding: irb_context.workspace.binding) do |pa|
|
30
|
+
result = pa.yield
|
31
|
+
inspection = pa.message_proc.call
|
21
32
|
end
|
33
|
+
|
34
|
+
if inspection == ''
|
35
|
+
puts usage
|
36
|
+
else
|
37
|
+
puts inspection, "\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "=> #{result.inspect}"
|
22
41
|
end
|
23
42
|
end
|
43
|
+
|
44
|
+
Command.register(:pa, PaCommand)
|
24
45
|
end
|
data/lib/irb/power_assert.rb
CHANGED
@@ -4,19 +4,10 @@
|
|
4
4
|
|
5
5
|
require 'irb'
|
6
6
|
require 'power_assert'
|
7
|
-
require_relative '
|
8
|
-
|
9
|
-
module IRB
|
10
|
-
module PowerAssert
|
11
|
-
end
|
12
|
-
|
13
|
-
module ExtendCommandBundle
|
14
|
-
def_extend_command(:irb_pa, :Pa, "#{__dir__}/cmd/pa.rb", [:pa, NO_OVERRIDE])
|
15
|
-
end
|
16
|
-
end
|
7
|
+
require_relative 'power_assert/version'
|
17
8
|
|
18
9
|
module PowerAssert
|
19
10
|
INTERNAL_LIB_DIRS[IRB::PowerAssert] = File.dirname(File.dirname(caller_locations(1, 1).first.path))
|
20
11
|
end
|
21
12
|
|
22
|
-
require_relative '
|
13
|
+
require_relative 'cmd/pa'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb-power_assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Kamiya
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.13.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.13.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '3.0'
|
53
|
-
description: power_assert in irb
|
53
|
+
description: Use power_assert inspection in irb
|
54
54
|
email:
|
55
55
|
- kachick1+ruby@gmail.com
|
56
56
|
executables: []
|
@@ -67,11 +67,10 @@ homepage: https://github.com/kachick/irb-power_assert
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
metadata:
|
70
|
-
homepage_uri: https://github.com/kachick/irb-power_assert
|
71
70
|
source_code_uri: https://github.com/kachick/irb-power_assert
|
72
71
|
bug_tracker_uri: https://github.com/kachick/irb-power_assert/issues
|
73
72
|
rubygems_mfa_required: 'true'
|
74
|
-
post_install_message:
|
73
|
+
post_install_message:
|
75
74
|
rdoc_options: []
|
76
75
|
require_paths:
|
77
76
|
- lib
|
@@ -79,15 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
80
79
|
- - ">="
|
81
80
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
81
|
+
version: '3.2'
|
83
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
83
|
requirements:
|
85
84
|
- - ">="
|
86
85
|
- !ruby/object:Gem::Version
|
87
86
|
version: '0'
|
88
87
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
88
|
+
rubygems_version: 3.5.3
|
89
|
+
signing_key:
|
91
90
|
specification_version: 4
|
92
91
|
summary: power_assert in irb
|
93
92
|
test_files: []
|