dry-logic 0.5.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +222 -17
- data/LICENSE +1 -1
- data/README.md +11 -20
- data/dry-logic.gemspec +36 -20
- data/lib/dry/logic/appliable.rb +2 -0
- data/lib/dry/logic/builder.rb +88 -0
- data/lib/dry/logic/evaluator.rb +1 -1
- data/lib/dry/logic/operations/abstract.rb +4 -6
- data/lib/dry/logic/operations/and.rb +12 -3
- data/lib/dry/logic/operations/attr.rb +1 -1
- data/lib/dry/logic/operations/binary.rb +4 -3
- data/lib/dry/logic/operations/check.rb +3 -5
- data/lib/dry/logic/operations/each.rb +1 -2
- data/lib/dry/logic/operations/implication.rb +1 -2
- data/lib/dry/logic/operations/key.rb +3 -5
- data/lib/dry/logic/operations/negation.rb +1 -2
- data/lib/dry/logic/operations/or.rb +1 -2
- data/lib/dry/logic/operations/set.rb +3 -4
- data/lib/dry/logic/operations/unary.rb +1 -1
- data/lib/dry/logic/operations/xor.rb +1 -2
- data/lib/dry/logic/operators.rb +6 -4
- data/lib/dry/logic/predicates.rb +110 -28
- data/lib/dry/logic/result.rb +2 -4
- data/lib/dry/logic/rule/interface.rb +143 -0
- data/lib/dry/logic/rule/predicate.rb +23 -17
- data/lib/dry/logic/rule.rb +31 -31
- data/lib/dry/logic/rule_compiler.rb +2 -7
- data/lib/dry/logic/version.rb +3 -1
- data/lib/dry/logic.rb +21 -5
- data/lib/dry-logic.rb +3 -1
- metadata +27 -143
- data/.codeclimate.yml +0 -23
- data/.gitignore +0 -7
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/.rubocop_todo.yml +0 -7
- data/.travis.yml +0 -30
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -17
- data/Rakefile +0 -12
- data/bin/console +0 -10
- data/examples/basic.rb +0 -14
- data/lib/dry/logic/operations.rb +0 -13
- data/spec/integration/result_spec.rb +0 -59
- data/spec/integration/rule_spec.rb +0 -53
- data/spec/shared/predicates.rb +0 -57
- data/spec/shared/rule.rb +0 -67
- data/spec/spec_helper.rb +0 -34
- data/spec/support/mutant.rb +0 -9
- data/spec/unit/operations/and_spec.rb +0 -64
- data/spec/unit/operations/attr_spec.rb +0 -27
- data/spec/unit/operations/check_spec.rb +0 -49
- data/spec/unit/operations/each_spec.rb +0 -47
- data/spec/unit/operations/implication_spec.rb +0 -30
- data/spec/unit/operations/key_spec.rb +0 -133
- data/spec/unit/operations/negation_spec.rb +0 -49
- data/spec/unit/operations/or_spec.rb +0 -73
- data/spec/unit/operations/set_spec.rb +0 -41
- data/spec/unit/operations/xor_spec.rb +0 -61
- data/spec/unit/predicates/array_spec.rb +0 -41
- data/spec/unit/predicates/attr_spec.rb +0 -29
- data/spec/unit/predicates/bool_spec.rb +0 -34
- data/spec/unit/predicates/case_spec.rb +0 -33
- data/spec/unit/predicates/date_spec.rb +0 -31
- data/spec/unit/predicates/date_time_spec.rb +0 -31
- data/spec/unit/predicates/decimal_spec.rb +0 -32
- data/spec/unit/predicates/empty_spec.rb +0 -38
- data/spec/unit/predicates/eql_spec.rb +0 -21
- data/spec/unit/predicates/even_spec.rb +0 -31
- data/spec/unit/predicates/excluded_from_spec.rb +0 -35
- data/spec/unit/predicates/excludes_spec.rb +0 -56
- data/spec/unit/predicates/false_spec.rb +0 -35
- data/spec/unit/predicates/filled_spec.rb +0 -38
- data/spec/unit/predicates/float_spec.rb +0 -31
- data/spec/unit/predicates/format_spec.rb +0 -21
- data/spec/unit/predicates/gt_spec.rb +0 -40
- data/spec/unit/predicates/gteq_spec.rb +0 -40
- data/spec/unit/predicates/included_in_spec.rb +0 -35
- data/spec/unit/predicates/includes_spec.rb +0 -24
- data/spec/unit/predicates/int_spec.rb +0 -34
- data/spec/unit/predicates/key_spec.rb +0 -29
- data/spec/unit/predicates/lt_spec.rb +0 -40
- data/spec/unit/predicates/lteq_spec.rb +0 -40
- data/spec/unit/predicates/max_size_spec.rb +0 -49
- data/spec/unit/predicates/min_size_spec.rb +0 -49
- data/spec/unit/predicates/none_spec.rb +0 -28
- data/spec/unit/predicates/not_eql_spec.rb +0 -21
- data/spec/unit/predicates/number_spec.rb +0 -37
- data/spec/unit/predicates/odd_spec.rb +0 -31
- data/spec/unit/predicates/size_spec.rb +0 -55
- data/spec/unit/predicates/str_spec.rb +0 -32
- data/spec/unit/predicates/time_spec.rb +0 -31
- data/spec/unit/predicates/true_spec.rb +0 -35
- data/spec/unit/predicates/type_spec.rb +0 -35
- data/spec/unit/predicates_spec.rb +0 -23
- data/spec/unit/rule/predicate_spec.rb +0 -53
- data/spec/unit/rule_compiler_spec.rb +0 -127
- data/spec/unit/rule_spec.rb +0 -141
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#array?' do
|
5
|
-
let(:predicate_name) { :array? }
|
6
|
-
|
7
|
-
context 'when value is an array' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[ [] ],
|
11
|
-
[ ['other', 'array'] ],
|
12
|
-
[ [123, 'really', :blah] ],
|
13
|
-
[ Array.new ],
|
14
|
-
[ [nil] ],
|
15
|
-
[ [false] ],
|
16
|
-
[ [true] ]
|
17
|
-
]
|
18
|
-
end
|
19
|
-
|
20
|
-
it_behaves_like 'a passing predicate'
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when value is not an array' do
|
24
|
-
let(:arguments_list) do
|
25
|
-
[
|
26
|
-
[''],
|
27
|
-
[{}],
|
28
|
-
[nil],
|
29
|
-
[:symbol],
|
30
|
-
[String],
|
31
|
-
[1],
|
32
|
-
[1.0],
|
33
|
-
[true],
|
34
|
-
[Hash.new]
|
35
|
-
]
|
36
|
-
end
|
37
|
-
|
38
|
-
it_behaves_like 'a failing predicate'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#attr?' do
|
5
|
-
let(:predicate_name) { :attr? }
|
6
|
-
|
7
|
-
context 'when value responds to the attr name' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[:name, Struct.new(:name).new('John')],
|
11
|
-
[:age, Struct.new(:age).new(18)]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with value does not respond to the attr name' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[:name, Struct.new(:age).new(18)],
|
22
|
-
[:age, Struct.new(:name).new('Jill')]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a failing predicate'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#bool?' do
|
5
|
-
let(:predicate_name) { :bool? }
|
6
|
-
|
7
|
-
context 'when value is a date' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[true], [false]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when value is not a bool' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[''],
|
19
|
-
[[]],
|
20
|
-
[{}],
|
21
|
-
[nil],
|
22
|
-
[:symbol],
|
23
|
-
[String],
|
24
|
-
[1],
|
25
|
-
[0],
|
26
|
-
['true'],
|
27
|
-
['false']
|
28
|
-
]
|
29
|
-
end
|
30
|
-
|
31
|
-
it_behaves_like 'a failing predicate'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#case?' do
|
5
|
-
let(:predicate_name) { :case? }
|
6
|
-
|
7
|
-
context 'when the value matches the pattern' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[11, 11],
|
11
|
-
[:odd?.to_proc, 11],
|
12
|
-
[/\Af/, 'foo'],
|
13
|
-
[Integer, 11]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when the value doesn't match the pattern" do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
[13, 14],
|
24
|
-
[:odd?.to_proc, 12],
|
25
|
-
[/\Af/, 'bar'],
|
26
|
-
[String, 11]
|
27
|
-
]
|
28
|
-
end
|
29
|
-
|
30
|
-
it_behaves_like 'a failing predicate'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#date?' do
|
5
|
-
let(:predicate_name) { :date? }
|
6
|
-
|
7
|
-
context 'when value is a date' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[Date.today]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with value is not an integer' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[''],
|
19
|
-
[[]],
|
20
|
-
[{}],
|
21
|
-
[nil],
|
22
|
-
[:symbol],
|
23
|
-
[String],
|
24
|
-
[1]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a failing predicate'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#date_time?' do
|
5
|
-
let(:predicate_name) { :date_time? }
|
6
|
-
|
7
|
-
context 'when value is a date' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[DateTime.now]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with value is not an integer' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[''],
|
19
|
-
[[]],
|
20
|
-
[{}],
|
21
|
-
[nil],
|
22
|
-
[:symbol],
|
23
|
-
[String],
|
24
|
-
[1]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a failing predicate'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#decimal?' do
|
5
|
-
let(:predicate_name) { :decimal? }
|
6
|
-
|
7
|
-
context 'when value is a date' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[1.2.to_d]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with value is not an integer' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[''],
|
19
|
-
[[]],
|
20
|
-
[{}],
|
21
|
-
[nil],
|
22
|
-
[:symbol],
|
23
|
-
[String],
|
24
|
-
[1],
|
25
|
-
[1.0]
|
26
|
-
]
|
27
|
-
end
|
28
|
-
|
29
|
-
it_behaves_like 'a failing predicate'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#empty?' do
|
5
|
-
let(:predicate_name) { :empty? }
|
6
|
-
|
7
|
-
context 'when value is empty' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[''],
|
11
|
-
[[]],
|
12
|
-
[{}],
|
13
|
-
[nil]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with value is not empty' do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
['Jill'],
|
24
|
-
[[1, 2, 3]],
|
25
|
-
[{ name: 'John' }],
|
26
|
-
[true],
|
27
|
-
[false],
|
28
|
-
['1'],
|
29
|
-
['0'],
|
30
|
-
[:symbol],
|
31
|
-
[String]
|
32
|
-
]
|
33
|
-
end
|
34
|
-
|
35
|
-
it_behaves_like 'a failing predicate'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates, '#eql?' do
|
4
|
-
let(:predicate_name) { :eql? }
|
5
|
-
|
6
|
-
context 'when value is equal to the arg' do
|
7
|
-
let(:arguments_list) do
|
8
|
-
[['Foo', 'Foo']]
|
9
|
-
end
|
10
|
-
|
11
|
-
it_behaves_like 'a passing predicate'
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'with value is not equal to the arg' do
|
15
|
-
let(:arguments_list) do
|
16
|
-
[['Bar', 'Foo']]
|
17
|
-
end
|
18
|
-
|
19
|
-
it_behaves_like 'a failing predicate'
|
20
|
-
end
|
21
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#even?' do
|
5
|
-
let(:predicate_name) { :even? }
|
6
|
-
|
7
|
-
context 'when value is an odd int' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[13],
|
11
|
-
[1],
|
12
|
-
[1111]
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
it_behaves_like 'a failing predicate'
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with value is an even int' do
|
20
|
-
let(:arguments_list) do
|
21
|
-
[
|
22
|
-
[0],
|
23
|
-
[2],
|
24
|
-
[2222]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a passing predicate'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#excluded_from?' do
|
5
|
-
let(:predicate_name) { :excluded_from? }
|
6
|
-
|
7
|
-
context 'when value is not present in list' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[['Jill', 'John'], 'Jack'],
|
11
|
-
[1..2, 0],
|
12
|
-
[1..2, 3],
|
13
|
-
[[nil, false], true]
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like 'a passing predicate'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with value is present in list' do
|
21
|
-
let(:arguments_list) do
|
22
|
-
[
|
23
|
-
[['Jill', 'John'], 'Jill'],
|
24
|
-
[['Jill', 'John'], 'John'],
|
25
|
-
[1..2, 1],
|
26
|
-
[1..2, 2],
|
27
|
-
[[nil, false], nil],
|
28
|
-
[[nil, false], false]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a failing predicate'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#excludes?' do
|
5
|
-
let(:predicate_name) { :excludes? }
|
6
|
-
|
7
|
-
context 'with input excludes value' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
['Jack', ['Jill', 'John']],
|
11
|
-
[0, 1..2],
|
12
|
-
[3, 1..2],
|
13
|
-
['foo', 'Hello World'],
|
14
|
-
[:foo, { bar: 0 }],
|
15
|
-
[true, [nil, false]]
|
16
|
-
]
|
17
|
-
end
|
18
|
-
|
19
|
-
it_behaves_like 'a passing predicate'
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with input of invalid type' do
|
23
|
-
let(:arguments_list) do
|
24
|
-
[
|
25
|
-
[2, 1],
|
26
|
-
[1, nil],
|
27
|
-
["foo", 1],
|
28
|
-
[1, "foo"],
|
29
|
-
[1..2, "foo"],
|
30
|
-
["foo", 1..2],
|
31
|
-
[:key, "foo"]
|
32
|
-
]
|
33
|
-
end
|
34
|
-
|
35
|
-
it_behaves_like 'a passing predicate'
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when input includes value' do
|
39
|
-
let(:arguments_list) do
|
40
|
-
[
|
41
|
-
['Jill', ['Jill', 'John']],
|
42
|
-
['John', ['Jill', 'John']],
|
43
|
-
[1, 1..2],
|
44
|
-
[2, 1..2],
|
45
|
-
['Hello', 'Hello World'],
|
46
|
-
['World', 'Hello World'],
|
47
|
-
[:bar, { bar: 0 }],
|
48
|
-
[nil, [nil, false]],
|
49
|
-
[false, [nil, false]]
|
50
|
-
]
|
51
|
-
end
|
52
|
-
|
53
|
-
it_behaves_like 'a failing predicate'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#false?' do
|
5
|
-
let(:predicate_name) { :false? }
|
6
|
-
|
7
|
-
context 'when value is a date' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[false]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when value is not false' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[true],
|
19
|
-
[''],
|
20
|
-
[[]],
|
21
|
-
[{}],
|
22
|
-
[nil],
|
23
|
-
[:symbol],
|
24
|
-
[String],
|
25
|
-
[1],
|
26
|
-
[0],
|
27
|
-
['true'],
|
28
|
-
['false']
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a failing predicate'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#filled?' do
|
5
|
-
let(:predicate_name) { :filled? }
|
6
|
-
|
7
|
-
context 'when value is filled' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
['Jill'],
|
11
|
-
[[1, 2, 3]],
|
12
|
-
[{ name: 'John' }],
|
13
|
-
[true],
|
14
|
-
[false],
|
15
|
-
['1'],
|
16
|
-
['0'],
|
17
|
-
[:symbol],
|
18
|
-
[String]
|
19
|
-
]
|
20
|
-
end
|
21
|
-
|
22
|
-
it_behaves_like 'a passing predicate'
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'with value is not filled' do
|
26
|
-
let(:arguments_list) do
|
27
|
-
[
|
28
|
-
[''],
|
29
|
-
[[]],
|
30
|
-
[{}],
|
31
|
-
[nil]
|
32
|
-
]
|
33
|
-
end
|
34
|
-
|
35
|
-
it_behaves_like 'a failing predicate'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#float?' do
|
5
|
-
let(:predicate_name) { :float? }
|
6
|
-
|
7
|
-
context 'when value is a float' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[[1.0]]
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like 'a passing predicate'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with value is not an integer' do
|
16
|
-
let(:arguments_list) do
|
17
|
-
[
|
18
|
-
[''],
|
19
|
-
[[]],
|
20
|
-
[{}],
|
21
|
-
[nil],
|
22
|
-
[:symbol],
|
23
|
-
[String],
|
24
|
-
[1]
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a failing predicate'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates, '#format?' do
|
4
|
-
let(:predicate_name) { :format? }
|
5
|
-
|
6
|
-
context 'when value matches provided regexp' do
|
7
|
-
let(:arguments_list) do
|
8
|
-
[['Foo', /^F/]]
|
9
|
-
end
|
10
|
-
|
11
|
-
it_behaves_like 'a passing predicate'
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when value does not match provided regexp' do
|
15
|
-
let(:arguments_list) do
|
16
|
-
[['Bar', /^F/]]
|
17
|
-
end
|
18
|
-
|
19
|
-
it_behaves_like 'a failing predicate'
|
20
|
-
end
|
21
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#gt?' do
|
5
|
-
let(:predicate_name) { :gt? }
|
6
|
-
|
7
|
-
context 'when value is greater than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[13, 14],
|
11
|
-
[13.37, 13.38]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when value is equal to n' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[13, 13],
|
22
|
-
[13.37, 13.37]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a failing predicate'
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with value is less than n' do
|
30
|
-
let(:arguments_list) do
|
31
|
-
[
|
32
|
-
[13, 12],
|
33
|
-
[13.37, 13.36]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#gteq?' do
|
5
|
-
let(:predicate_name) { :gteq? }
|
6
|
-
|
7
|
-
context 'when value is greater than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[13, 14],
|
11
|
-
[13.37, 13.38]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when value is equal to n' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[13, 13],
|
22
|
-
[13.37, 13.37]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a passing predicate'
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with value is less than n' do
|
30
|
-
let(:arguments_list) do
|
31
|
-
[
|
32
|
-
[13, 12],
|
33
|
-
[13.37, 13.36]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates do
|
4
|
-
describe '#included_in?' do
|
5
|
-
let(:predicate_name) { :included_in? }
|
6
|
-
|
7
|
-
context 'when value is present in list' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[['Jill', 'John'], 'Jill'],
|
11
|
-
[['Jill', 'John'], 'John'],
|
12
|
-
[1..2, 1],
|
13
|
-
[1..2, 2],
|
14
|
-
[[nil, false], nil],
|
15
|
-
[[nil, false], false]
|
16
|
-
]
|
17
|
-
end
|
18
|
-
|
19
|
-
it_behaves_like 'a passing predicate'
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with value is not present in list' do
|
23
|
-
let(:arguments_list) do
|
24
|
-
[
|
25
|
-
[['Jill', 'John'], 'Jack'],
|
26
|
-
[1..2, 0],
|
27
|
-
[1..2, 3],
|
28
|
-
[[nil, false], true]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a failing predicate'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'dry/logic/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Logic::Predicates, '#is?' do
|
4
|
-
let(:predicate_name) { :is? }
|
5
|
-
let(:one) { Object.new }
|
6
|
-
let(:two) { Object.new }
|
7
|
-
|
8
|
-
context 'when value is equal to the arg' do
|
9
|
-
let(:arguments_list) do
|
10
|
-
[[one, one], [:one, :one]]
|
11
|
-
end
|
12
|
-
|
13
|
-
it_behaves_like 'a passing predicate'
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'with value is not equal to the arg' do
|
17
|
-
let(:arguments_list) do
|
18
|
-
# Strings are not equal. Yet
|
19
|
-
[[one, two], ['one', 'one']]
|
20
|
-
end
|
21
|
-
|
22
|
-
it_behaves_like 'a failing predicate'
|
23
|
-
end
|
24
|
-
end
|