defi 2.0.4 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +18 -25
- data/lib/defi/challenge.rb +26 -32
- data/lib/defi/value.rb +8 -2
- data/lib/defi.rb +5 -5
- metadata +57 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f62cb331ea97335ed07945d26c22a25f3ee7c826ded161d1432018e2e1005c
|
4
|
+
data.tar.gz: 1067904cd927baeb4c4f5bb8a52260ff813b66f1987e774baaf5916dd10922fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fbd50efbc1db138975db94ab8c5b876b203443719d780032ac97a2e9129366b85dec847fc8cff0655b3046b02b423f8f2717c8c36b6c11fe45ba03772fc674e
|
7
|
+
data.tar.gz: a6ee3bb73c8dbbca088d2df08239f31c3451b0bee4075d4f6499d1d45625daab3314ce954fcde3b354d3a564bcbee3557201f74fa7fce65640776ada36e9a214
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# Defi
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
3
|
+
[![Version](https://img.shields.io/github/v/tag/fixrb/defi?label=Version&logo=github)](https://github.com/fixrb/defi/releases)
|
4
|
+
[![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/defi/main)
|
5
|
+
[![CI](https://github.com/fixrb/defi/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/defi/actions?query=workflow%3Aci+branch%3Amain)
|
6
|
+
[![RuboCop](https://github.com/fixrb/defi/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/defi/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
|
+
[![License](https://img.shields.io/github/license/fixrb/defi?label=License&logo=github)](https://github.com/fixrb/defi/raw/main/LICENSE.md)
|
7
8
|
|
8
9
|
> Challenge library.
|
9
10
|
|
@@ -12,16 +13,20 @@
|
|
12
13
|
Add this line to your application's Gemfile:
|
13
14
|
|
14
15
|
```ruby
|
15
|
-
gem
|
16
|
+
gem "defi"
|
16
17
|
```
|
17
18
|
|
18
19
|
And then execute:
|
19
20
|
|
20
|
-
|
21
|
+
```sh
|
22
|
+
bundle install
|
23
|
+
```
|
21
24
|
|
22
25
|
Or install it yourself as:
|
23
26
|
|
24
|
-
|
27
|
+
```sh
|
28
|
+
gem install defi
|
29
|
+
```
|
25
30
|
|
26
31
|
## Usage
|
27
32
|
|
@@ -34,27 +39,20 @@ Defi.send(:*, 7).to(6).call # => 42
|
|
34
39
|
Now, let's challenge "`foo`" with `boom` method:
|
35
40
|
|
36
41
|
```ruby
|
37
|
-
Defi.send(:boom).to(
|
42
|
+
Defi.send(:boom).to("foo").call # NoMethodError: undefined method `boom' for "foo":String
|
38
43
|
```
|
39
44
|
|
40
45
|
Let's challenge "`hello world`" with `gsub!` in isolation:
|
41
46
|
|
42
47
|
```ruby
|
43
|
-
some_text =
|
44
|
-
Defi.send(:gsub!,
|
48
|
+
some_text = "hello world"
|
49
|
+
Defi.send(:gsub!, "world", "Alice").to!(some_text).call # => "hello Alice"
|
45
50
|
some_text # => "hello world"
|
46
51
|
```
|
47
52
|
|
48
53
|
## Contact
|
49
54
|
|
50
|
-
*
|
51
|
-
* Bugs/issues: https://github.com/fixrb/defi/issues
|
52
|
-
|
53
|
-
## Rubies
|
54
|
-
|
55
|
-
* [MRI](https://www.ruby-lang.org/)
|
56
|
-
* [Rubinius](https://rubinius.com/)
|
57
|
-
* [JRuby](https://www.jruby.org/)
|
55
|
+
* Source code: https://github.com/fixrb/defi/issues
|
58
56
|
|
59
57
|
## Versioning
|
60
58
|
|
@@ -62,18 +60,13 @@ __Defi__ follows [Semantic Versioning 2.0](https://semver.org/).
|
|
62
60
|
|
63
61
|
## License
|
64
62
|
|
65
|
-
The gem is available as open source under the terms of the [MIT License](https://
|
63
|
+
The [gem](https://rubygems.org/gems/defi) is available as open source under the terms of the [MIT License](https://github.com/fixrb/defi/raw/main/LICENSE.md).
|
66
64
|
|
67
65
|
***
|
68
66
|
|
69
67
|
<p>
|
70
68
|
This project is sponsored by:<br />
|
71
69
|
<a href="https://sashite.com/"><img
|
72
|
-
src="https://github.com/fixrb/defi/raw/
|
70
|
+
src="https://github.com/fixrb/defi/raw/main/img/sashite.png"
|
73
71
|
alt="Sashite" /></a>
|
74
72
|
</p>
|
75
|
-
|
76
|
-
[gem]: https://rubygems.org/gems/defi
|
77
|
-
[travis]: https://travis-ci.org/fixrb/defi
|
78
|
-
[inchpages]: https://inch-ci.org/github/fixrb/defi
|
79
|
-
[rubydoc]: https://rubydoc.info/gems/defi/frames
|
data/lib/defi/challenge.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "aw"
|
4
4
|
|
5
5
|
module Defi
|
6
6
|
# This class contains a challenge to apply against an object.
|
@@ -18,25 +18,11 @@ module Defi
|
|
18
18
|
@block = block
|
19
19
|
end
|
20
20
|
|
21
|
-
# @
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def to(object)
|
27
|
-
Value.new { object.public_send(@method, *@args, **@opts, &@block) }
|
28
|
-
end
|
29
|
-
else
|
30
|
-
# @param object [#object_id] The object to challenge.
|
31
|
-
#
|
32
|
-
# @return [Defi::Value] The actual value, to raise or to return.
|
33
|
-
def to(object)
|
34
|
-
if @opts.empty?
|
35
|
-
Value.new { object.public_send(@method, *@args, &@block) }
|
36
|
-
else
|
37
|
-
Value.new { object.public_send(@method, *@args, **@opts, &@block) }
|
38
|
-
end
|
39
|
-
end
|
21
|
+
# @param object [#object_id] The object to challenge.
|
22
|
+
#
|
23
|
+
# @return [Defi::Value] The actual value, to raise or to return.
|
24
|
+
def to(object)
|
25
|
+
Value.new { object.public_send(@method, *@args, **@opts, &@block) }
|
40
26
|
end
|
41
27
|
|
42
28
|
# @param object [#object_id] The object to challenge in code isolation.
|
@@ -60,6 +46,10 @@ module Defi
|
|
60
46
|
}
|
61
47
|
end
|
62
48
|
|
49
|
+
# rubocop:disable Metrics/AbcSize
|
50
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
51
|
+
# rubocop:disable Metrics/MethodLength
|
52
|
+
|
63
53
|
# String of the challenge.
|
64
54
|
#
|
65
55
|
# @return [String] The string representation of the challenge.
|
@@ -70,9 +60,9 @@ module Defi
|
|
70
60
|
|
71
61
|
stringified_args = @args.inspect[1..-2]
|
72
62
|
stringified_opts = @opts.inspect[1..-2]
|
73
|
-
stringified_block =
|
63
|
+
stringified_block = "<Proc>" unless @block.nil?
|
74
64
|
|
75
|
-
string +=
|
65
|
+
string += "("
|
76
66
|
|
77
67
|
stringified_items = []
|
78
68
|
|
@@ -80,9 +70,13 @@ module Defi
|
|
80
70
|
stringified_items << stringified_opts unless @opts.empty?
|
81
71
|
stringified_items << stringified_block unless @block.nil?
|
82
72
|
|
83
|
-
string
|
73
|
+
"#{string}#{stringified_items.join(", ")})"
|
84
74
|
end
|
85
75
|
|
76
|
+
# rubocop:enable Metrics/AbcSize
|
77
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
78
|
+
# rubocop:enable Metrics/MethodLength
|
79
|
+
|
86
80
|
# A string containing a human-readable representation of the challenge.
|
87
81
|
#
|
88
82
|
# @return [String] The human-readable representation of the challenge.
|
@@ -90,16 +84,16 @@ module Defi
|
|
90
84
|
inspected_method = @method.inspect
|
91
85
|
inspected_args = @args.inspect
|
92
86
|
inspected_opts = @opts.inspect
|
93
|
-
inspected_block = @block.nil? ?
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
87
|
+
inspected_block = @block.nil? ? "nil" : "<Proc>"
|
88
|
+
|
89
|
+
"Defi(" \
|
90
|
+
"method: #{inspected_method}, " \
|
91
|
+
"args: #{inspected_args}, " \
|
92
|
+
"opts: #{inspected_opts}, " \
|
93
|
+
"block: #{inspected_block}" \
|
94
|
+
")"
|
101
95
|
end
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
105
|
-
require_relative
|
99
|
+
require_relative "value"
|
data/lib/defi/value.rb
CHANGED
@@ -48,8 +48,7 @@ module Defi
|
|
48
48
|
#
|
49
49
|
# @return [String] The string representation of the value.
|
50
50
|
def to_s
|
51
|
-
|
52
|
-
"#{string} #{object}"
|
51
|
+
"#{raise_or_return} #{object}"
|
53
52
|
end
|
54
53
|
|
55
54
|
# A string containing a human-readable representation of the value.
|
@@ -58,5 +57,12 @@ module Defi
|
|
58
57
|
def inspect
|
59
58
|
"Value(object: #{object}, raised: #{raised?})"
|
60
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# @return [String] A "raise" or "return" string.
|
64
|
+
def raise_or_return
|
65
|
+
raised? ? "raise" : "return"
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
data/lib/defi.rb
CHANGED
@@ -5,18 +5,18 @@
|
|
5
5
|
module Defi
|
6
6
|
# Expectations are built with this method.
|
7
7
|
#
|
8
|
-
# @example
|
8
|
+
# @example A :foo challenge
|
9
9
|
# send(:foo) # => #<Defi::Challenge:0x007f96a40925f8 @method=:foo, @args=[]>
|
10
10
|
#
|
11
11
|
# @param method [#to_sym] The method to send to an object.
|
12
12
|
# @param args [Array] Any arguments of the method.
|
13
|
-
# @param
|
13
|
+
# @param kwargs [Hash] Any keyword arguments of the method.
|
14
14
|
# @param block [Proc] Any block argument of the method.
|
15
15
|
#
|
16
16
|
# @return [Challenge] The challenge instance.
|
17
|
-
def self.send(method, *args, **
|
18
|
-
Challenge.new(method, *args, **
|
17
|
+
def self.send(method, *args, **kwargs, &block)
|
18
|
+
Challenge.new(method, *args, **kwargs, &block)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
require_relative File.join(
|
22
|
+
require_relative File.join("defi", "challenge")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aw
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
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: 0.
|
26
|
+
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
56
|
+
name: rubocop-md
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop-performance
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,34 +80,62 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-thread_safety
|
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'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: simplecov
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
117
|
+
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: yard
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
|
-
- - "
|
129
|
+
- - ">="
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0
|
131
|
+
version: '0'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
|
-
- - "
|
136
|
+
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0
|
138
|
+
version: '0'
|
111
139
|
description: Challenge library.
|
112
140
|
email: contact@cyril.email
|
113
141
|
executables: []
|
@@ -122,7 +150,8 @@ files:
|
|
122
150
|
homepage: https://github.com/fixrb/defi
|
123
151
|
licenses:
|
124
152
|
- MIT
|
125
|
-
metadata:
|
153
|
+
metadata:
|
154
|
+
rubygems_mfa_required: 'true'
|
126
155
|
post_install_message:
|
127
156
|
rdoc_options: []
|
128
157
|
require_paths:
|
@@ -131,14 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
160
|
requirements:
|
132
161
|
- - ">="
|
133
162
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
163
|
+
version: 2.7.0
|
135
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
165
|
requirements:
|
137
166
|
- - ">="
|
138
167
|
- !ruby/object:Gem::Version
|
139
168
|
version: '0'
|
140
169
|
requirements: []
|
141
|
-
rubygems_version: 3.1.
|
170
|
+
rubygems_version: 3.1.6
|
142
171
|
signing_key:
|
143
172
|
specification_version: 4
|
144
173
|
summary: Challenge library.
|