the_array_comparator 0.2.0 → 0.3.0
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.
- data/.rspec +2 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +21 -21
- data/README.md +2 -2
- data/TODO.md +2 -1
- data/gemfiles/Gemfile.default +1 -1
- data/lib/the_array_comparator/cache.rb +43 -44
- data/lib/the_array_comparator/caching_strategies/anonymous_cache.rb +69 -0
- data/lib/the_array_comparator/caching_strategies/single_value_cache.rb +69 -0
- data/lib/the_array_comparator/comparator.rb +48 -40
- data/lib/the_array_comparator/exceptions.rb +31 -2
- data/lib/the_array_comparator/{strategies → searching_strategies}/base.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_all.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_all_with_substring_search.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_any.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_any_with_substring_search.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_not.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/contains_not_with_substring_search.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/is_equal.rb +1 -1
- data/lib/the_array_comparator/{strategies → searching_strategies}/is_not_equal.rb +1 -1
- data/lib/the_array_comparator/strategy_dispatcher.rb +110 -0
- data/lib/the_array_comparator/version.rb +2 -2
- data/lib/the_array_comparator.rb +12 -20
- data/spec/benchmark/benchmark_spec.rb +50 -9
- data/spec/cache/anonymous_cache_spec.rb +89 -0
- data/spec/cache/single_value_cache_spec.rb +77 -0
- data/spec/cache_spec.rb +21 -70
- data/spec/comparator/base_spec.rb +2 -2
- data/spec/comparator/comparator_spec.rb +7 -37
- data/spec/comparator/contains_all_spec.rb +7 -7
- data/spec/comparator/contains_all_with_substring_search_spec.rb +6 -6
- data/spec/comparator/contains_any_spec.rb +6 -6
- data/spec/comparator/contains_any_with_substring_search_spec.rb +5 -5
- data/spec/comparator/contains_not_spec.rb +6 -6
- data/spec/comparator/contains_not_with_substring_search_spec.rb +4 -4
- data/spec/comparator/is_equal_spec.rb +7 -7
- data/spec/comparator/is_not_equal_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -1
- data/spec/strategy_dispatcher/strategy_dispatcher_spec.rb +159 -0
- metadata +20 -11
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::ContainsAllWithSubstringSearch do
|
6
6
|
let(:data) { %w{ ab c e} }
|
7
7
|
let(:exceptions) { %w{ b } }
|
8
8
|
let(:keywords_overlap) { %w{ a } }
|
@@ -11,31 +11,31 @@ describe Strategies::ContainsAllWithSubstringSearch do
|
|
11
11
|
|
12
12
|
it "is successfull when there's a data overlap" do
|
13
13
|
sample = SampleDouble.new(data,keywords_overlap)
|
14
|
-
comparator =
|
14
|
+
comparator = SearchingStrategies::ContainsAllWithSubstringSearch.new(sample)
|
15
15
|
expect(comparator.success?).to eq(true)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "doesn't find something if there's no overlap" do
|
19
19
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
20
|
-
comparator =
|
20
|
+
comparator = SearchingStrategies::ContainsAllWithSubstringSearch.new(sample)
|
21
21
|
expect(comparator.success?).to eq(false)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "doesn't find something if there's an exception defined" do
|
25
25
|
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
26
|
-
comparator =
|
26
|
+
comparator = SearchingStrategies::ContainsAllWithSubstringSearch.new(sample)
|
27
27
|
expect(comparator.success?).to eq(false)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "doesn't find something if there's an exception defined" do
|
31
31
|
sample = SampleDouble.new(data,multiple_keywords_with_one_no_overlap, exceptions)
|
32
|
-
comparator =
|
32
|
+
comparator = SearchingStrategies::ContainsAllWithSubstringSearch.new(sample)
|
33
33
|
expect(comparator.success?).to eq(false)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "fails if not all keywords can be found within the data" do
|
37
37
|
sample = SampleDouble.new(data,multiple_keywords_with_one_no_overlap)
|
38
|
-
comparator =
|
38
|
+
comparator = SearchingStrategies::ContainsAllWithSubstringSearch.new(sample)
|
39
39
|
expect(comparator.success?).to eq(false)
|
40
40
|
end
|
41
41
|
end
|
@@ -2,38 +2,38 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::ContainsAny do
|
6
6
|
let(:data) { %w{ a b c e} }
|
7
7
|
let(:keywords_overlap) { %w{ a } }
|
8
8
|
let(:keywords_no_overlap) { %w{ d } }
|
9
9
|
|
10
10
|
it "fails if keywords are empty" do
|
11
11
|
sample = SampleDouble.new(data,[])
|
12
|
-
comparator =
|
12
|
+
comparator = SearchingStrategies::ContainsAny.new(sample)
|
13
13
|
expect(comparator.success?).to eq(false)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "fails if data is empty" do
|
17
17
|
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
-
comparator =
|
18
|
+
comparator = SearchingStrategies::ContainsAny.new(sample)
|
19
19
|
expect(comparator.success?).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "is successfull if both keywords and data are empty" do
|
23
23
|
sample = SampleDouble.new([],[])
|
24
|
-
comparator =
|
24
|
+
comparator = SearchingStrategies::ContainsAny.new(sample)
|
25
25
|
expect(comparator.success?).to eq(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "is successfull when there's a data overlap" do
|
29
29
|
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
-
comparator =
|
30
|
+
comparator = SearchingStrategies::ContainsAny.new(sample)
|
31
31
|
expect(comparator.success?).to eq(true)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "doesn't find something if there's no overlap" do
|
35
35
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
-
comparator =
|
36
|
+
comparator = SearchingStrategies::ContainsAny.new(sample)
|
37
37
|
expect(comparator.success?).to eq(false)
|
38
38
|
end
|
39
39
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::ContainsAnyWithSubstringSearch do
|
6
6
|
let(:data) { %w{ ab c e} }
|
7
7
|
let(:exceptions) { %w{ b} }
|
8
8
|
let(:keywords_overlap) { %w{ a } }
|
@@ -11,25 +11,25 @@ describe Strategies::ContainsAnyWithSubstringSearch do
|
|
11
11
|
|
12
12
|
it "is successfull when there's a data overlap (at least one element)" do
|
13
13
|
sample = SampleDouble.new(data,keywords_overlap)
|
14
|
-
comparator =
|
14
|
+
comparator = SearchingStrategies::ContainsAnyWithSubstringSearch.new(sample)
|
15
15
|
expect(comparator.success?).to eq(true)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "doesn't find something if there's no overlap" do
|
19
19
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
20
|
-
comparator =
|
20
|
+
comparator = SearchingStrategies::ContainsAnyWithSubstringSearch.new(sample)
|
21
21
|
expect(comparator.success?).to eq(false)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "doesn't find something if there's an exception defined" do
|
25
25
|
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
26
|
-
comparator =
|
26
|
+
comparator = SearchingStrategies::ContainsAnyWithSubstringSearch.new(sample)
|
27
27
|
expect(comparator.success?).to eq(false)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "is successfull, if there's a least one match (second match 'c' -> exception -> no match) " do
|
31
31
|
sample = SampleDouble.new(data,multiple_overlap, exceptions)
|
32
|
-
comparator =
|
32
|
+
comparator = SearchingStrategies::ContainsAnyWithSubstringSearch.new(sample)
|
33
33
|
expect(comparator.success?).to eq(true)
|
34
34
|
end
|
35
35
|
end
|
@@ -2,38 +2,38 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::ContainsNot do
|
6
6
|
let(:data) { %w{ a b c e} }
|
7
7
|
let(:keywords_overlap) { %w{ a } }
|
8
8
|
let(:keywords_no_overlap) { %w{ d } }
|
9
9
|
|
10
10
|
it "is successfull if keywords are empty" do
|
11
11
|
sample = SampleDouble.new(data,[])
|
12
|
-
comparator =
|
12
|
+
comparator = SearchingStrategies::ContainsNot.new(sample)
|
13
13
|
expect(comparator.success?).to eq(true)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "is successfull if data is empty" do
|
17
17
|
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
-
comparator =
|
18
|
+
comparator = SearchingStrategies::ContainsNot.new(sample)
|
19
19
|
expect(comparator.success?).to eq(true)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "fails if both keywords and data are empty" do
|
23
23
|
sample = SampleDouble.new([],[])
|
24
|
-
comparator =
|
24
|
+
comparator = SearchingStrategies::ContainsNot.new(sample)
|
25
25
|
expect(comparator.success?).to eq(false)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "is successfull if there's a data overlap" do
|
29
29
|
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
-
comparator =
|
30
|
+
comparator = SearchingStrategies::ContainsNot.new(sample)
|
31
31
|
expect(comparator.success?).to eq(false)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "doesn't find something if there's no overlap" do
|
35
35
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
-
comparator =
|
36
|
+
comparator = SearchingStrategies::ContainsNot.new(sample)
|
37
37
|
expect(comparator.success?).to eq(true)
|
38
38
|
end
|
39
39
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::ContainsNotWithSubstringSearch do
|
6
6
|
let(:data) { %w{ ab c e } }
|
7
7
|
let(:exceptions) { %w{ a } }
|
8
8
|
let(:keywords_overlap) { %w{ ab } }
|
@@ -10,19 +10,19 @@ describe Strategies::ContainsNotWithSubstringSearch do
|
|
10
10
|
|
11
11
|
it "is successfull when there's a no overlap" do
|
12
12
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
13
|
-
comparator =
|
13
|
+
comparator = SearchingStrategies::ContainsNotWithSubstringSearch.new(sample)
|
14
14
|
expect(comparator.success?).to eq(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "doesn't find something if there's an overlap" do
|
18
18
|
sample = SampleDouble.new(data,keywords_overlap)
|
19
|
-
comparator =
|
19
|
+
comparator = SearchingStrategies::ContainsNotWithSubstringSearch.new(sample)
|
20
20
|
expect(comparator.success?).to eq(false)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "is successfull although there's an overlap, but an exception defined" do
|
24
24
|
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
25
|
-
comparator =
|
25
|
+
comparator = SearchingStrategies::ContainsNotWithSubstringSearch.new(sample)
|
26
26
|
expect(comparator.success?).to eq(true)
|
27
27
|
end
|
28
28
|
end
|
@@ -2,38 +2,38 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::IsEqual do
|
6
6
|
let(:data) { %w{ a } }
|
7
7
|
let(:keywords_overlap) { %w{ a } }
|
8
8
|
let(:keywords_no_overlap) { %w{ d } }
|
9
9
|
|
10
10
|
it "fails if keywords are empty" do
|
11
11
|
sample = SampleDouble.new(data,[])
|
12
|
-
comparator =
|
12
|
+
comparator = SearchingStrategies::IsEqual.new(sample)
|
13
13
|
expect(comparator.success?).to eq(false)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "fails if data is empty" do
|
17
17
|
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
-
comparator =
|
18
|
+
comparator = SearchingStrategies::IsEqual.new(sample)
|
19
19
|
expect(comparator.success?).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "is successfull if both keywords and data are empty" do
|
23
23
|
sample = SampleDouble.new([],[])
|
24
|
-
comparator =
|
24
|
+
comparator = SearchingStrategies::IsEqual.new(sample)
|
25
25
|
expect(comparator.success?).to eq(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "is successfull if data and keywords are equal" do
|
29
29
|
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
-
comparator =
|
30
|
+
comparator = SearchingStrategies::IsEqual.new(sample)
|
31
31
|
expect(comparator.success?).to eq(true)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "fails if data and keywords are different" do
|
35
35
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
-
comparator =
|
36
|
+
comparator = SearchingStrategies::IsEqual.new(sample)
|
37
37
|
expect(comparator.success?).to eq(false)
|
38
38
|
end
|
39
39
|
|
@@ -43,7 +43,7 @@ describe Strategies::IsEqual do
|
|
43
43
|
sample = SampleDouble.new(data,keywords_no_overlap,%w{a})
|
44
44
|
|
45
45
|
msg = capture(:stderr) do
|
46
|
-
|
46
|
+
SearchingStrategies::IsEqual.new(sample)
|
47
47
|
end
|
48
48
|
|
49
49
|
expect(msg).to eq(needed_msg)
|
@@ -2,38 +2,38 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'strategies_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe SearchingStrategies::IsNotEqual do
|
6
6
|
let(:data) { %w{ a } }
|
7
7
|
let(:keywords_overlap) { %w{ a } }
|
8
8
|
let(:keywords_no_overlap) { %w{ d } }
|
9
9
|
|
10
10
|
it "is successfull if keywords are empty" do
|
11
11
|
sample = SampleDouble.new(data,[])
|
12
|
-
comparator =
|
12
|
+
comparator = SearchingStrategies::IsNotEqual.new(sample)
|
13
13
|
expect(comparator.success?).to eq(true)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "is successfull if data is empty" do
|
17
17
|
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
-
comparator =
|
18
|
+
comparator = SearchingStrategies::IsNotEqual.new(sample)
|
19
19
|
expect(comparator.success?).to eq(true)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "fails if both keywords and data are empty" do
|
23
23
|
sample = SampleDouble.new([],[])
|
24
|
-
comparator =
|
24
|
+
comparator = SearchingStrategies::IsNotEqual.new(sample)
|
25
25
|
expect(comparator.success?).to eq(false)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "fails if data and keywords are equal" do
|
29
29
|
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
-
comparator =
|
30
|
+
comparator = SearchingStrategies::IsNotEqual.new(sample)
|
31
31
|
expect(comparator.success?).to eq(false)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "is successfull if data and keywords are different" do
|
35
35
|
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
-
comparator =
|
36
|
+
comparator = SearchingStrategies::IsNotEqual.new(sample)
|
37
37
|
expect(comparator.success?).to eq(true)
|
38
38
|
end
|
39
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,7 +28,7 @@ require 'the_array_comparator/testing_helper/test_data'
|
|
28
28
|
require 'the_array_comparator/testing_helper'
|
29
29
|
|
30
30
|
RSpec.configure do |c|
|
31
|
-
c.treat_symbols_as_metadata_keys_with_true_values = true
|
31
|
+
# c.treat_symbols_as_metadata_keys_with_true_values = true
|
32
32
|
# c.filter_run_including :focus => true
|
33
33
|
end
|
34
34
|
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe StrategyDispatcher do
|
5
|
+
let(:dispatcher_klass) do
|
6
|
+
Class.new(StrategyDispatcher) do
|
7
|
+
def initialize; end
|
8
|
+
|
9
|
+
def class_must_have_methods
|
10
|
+
[
|
11
|
+
:success?
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
def exception_to_raise_for_invalid_strategy; end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:strategy_klass) do
|
20
|
+
Class.new do
|
21
|
+
def success?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "let you define must have methods" do
|
28
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do
|
29
|
+
def class_must_have_methods; end
|
30
|
+
end
|
31
|
+
|
32
|
+
expect {
|
33
|
+
dispatcher_klass.new.class_must_have_methods
|
34
|
+
}.to_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "expects that must have methods are defined" do
|
38
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do; end
|
39
|
+
|
40
|
+
expect {
|
41
|
+
dispatcher_klass.new.class_must_have_methods
|
42
|
+
}.to raise_error Exceptions::MustHaveMethodNotImplemented
|
43
|
+
|
44
|
+
expect {
|
45
|
+
dispatcher_klass.new.exception_to_raise_for_invalid_strategy
|
46
|
+
}.to raise_error Exceptions::MustHaveMethodNotImplemented
|
47
|
+
end
|
48
|
+
|
49
|
+
it "let you register classes" do
|
50
|
+
invalid_strategy_exception = Class.new(Exception)
|
51
|
+
|
52
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do
|
53
|
+
def class_must_have_methods; end
|
54
|
+
|
55
|
+
def exception_to_raise_for_invalid_strategy
|
56
|
+
invalid_strategy_exception
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
expect {
|
61
|
+
dispatcher_klass.new.register(:is_eqal_new, strategy_klass)
|
62
|
+
}.to_not raise_error invalid_strategy_exception
|
63
|
+
end
|
64
|
+
|
65
|
+
it "fails when you did not set a strategy reader but defined your own initializer" do
|
66
|
+
expect {
|
67
|
+
dispatcher_klass.new.register(:is_eqal_new, strategy_klass)
|
68
|
+
}.to raise_error Exceptions::WrongUsageOfLibrary
|
69
|
+
end
|
70
|
+
|
71
|
+
it "is happy if you define a strategy reader" do
|
72
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do
|
73
|
+
strategy_reader :avail_strategies
|
74
|
+
|
75
|
+
def class_must_have_methods
|
76
|
+
[
|
77
|
+
:success?
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
def exception_to_raise_for_invalid_strategy; end
|
82
|
+
end
|
83
|
+
|
84
|
+
expect {
|
85
|
+
dispatcher_klass.new.register(:is_eqal_new, strategy_klass)
|
86
|
+
}.to_not raise_error Exceptions::WrongUsageOfLibrary
|
87
|
+
end
|
88
|
+
|
89
|
+
it "gives you access to the defined strategies via the reader" do
|
90
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do
|
91
|
+
strategy_reader :strategies
|
92
|
+
|
93
|
+
def class_must_have_methods
|
94
|
+
[
|
95
|
+
:success?
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
def exception_to_raise_for_invalid_strategy; end
|
100
|
+
end
|
101
|
+
|
102
|
+
d = dispatcher_klass.new
|
103
|
+
d.register(:is_eqal_new, strategy_klass)
|
104
|
+
s = d.strategies[:is_eqal_new]
|
105
|
+
expect(s).to be(strategy_klass)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "fails if you try to register an internal keyword" do
|
109
|
+
forbidden_keywords = [
|
110
|
+
:initialize,
|
111
|
+
:strategy_reader,
|
112
|
+
:register,
|
113
|
+
:exception_to_raise_for_invalid_strategy,
|
114
|
+
:class_must_have_methods,
|
115
|
+
:each,
|
116
|
+
:interal_keywords,
|
117
|
+
:valid_strategy?,
|
118
|
+
:exception_if_not_implemented,
|
119
|
+
]
|
120
|
+
|
121
|
+
def dispatcher_klass(reader)
|
122
|
+
Class.new(StrategyDispatcher) do
|
123
|
+
strategy_reader reader.to_sym
|
124
|
+
|
125
|
+
def class_must_have_methods
|
126
|
+
[
|
127
|
+
:success?
|
128
|
+
]
|
129
|
+
end
|
130
|
+
|
131
|
+
def exception_to_raise_for_invalid_strategy; end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
forbidden_keywords.each do |w|
|
136
|
+
expect{ dispatcher_klass(w) }.to raise_error Exceptions::UsedInternalKeyword
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "fails when registering a not suitable class" do
|
141
|
+
Invalid_strategy_exception = Class.new(Exception)
|
142
|
+
|
143
|
+
dispatcher_klass = Class.new(StrategyDispatcher) do
|
144
|
+
def class_must_have_methods
|
145
|
+
[
|
146
|
+
:wow_what_a_method
|
147
|
+
]
|
148
|
+
end
|
149
|
+
|
150
|
+
def exception_to_raise_for_invalid_strategy
|
151
|
+
Invalid_strategy_exception
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
expect {
|
156
|
+
dispatcher_klass.new.register(:is_eqal_new, strategy_klass)
|
157
|
+
}.to raise_error Invalid_strategy_exception
|
158
|
+
end
|
159
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_array_comparator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_support
|
@@ -52,20 +52,23 @@ files:
|
|
52
52
|
- gemfiles/Gemfile.travis
|
53
53
|
- lib/the_array_comparator.rb
|
54
54
|
- lib/the_array_comparator/cache.rb
|
55
|
+
- lib/the_array_comparator/caching_strategies/anonymous_cache.rb
|
56
|
+
- lib/the_array_comparator/caching_strategies/single_value_cache.rb
|
55
57
|
- lib/the_array_comparator/check.rb
|
56
58
|
- lib/the_array_comparator/comparator.rb
|
57
59
|
- lib/the_array_comparator/exceptions.rb
|
58
60
|
- lib/the_array_comparator/result.rb
|
59
61
|
- lib/the_array_comparator/sample.rb
|
60
|
-
- lib/the_array_comparator/
|
61
|
-
- lib/the_array_comparator/
|
62
|
-
- lib/the_array_comparator/
|
63
|
-
- lib/the_array_comparator/
|
64
|
-
- lib/the_array_comparator/
|
65
|
-
- lib/the_array_comparator/
|
66
|
-
- lib/the_array_comparator/
|
67
|
-
- lib/the_array_comparator/
|
68
|
-
- lib/the_array_comparator/
|
62
|
+
- lib/the_array_comparator/searching_strategies/base.rb
|
63
|
+
- lib/the_array_comparator/searching_strategies/contains_all.rb
|
64
|
+
- lib/the_array_comparator/searching_strategies/contains_all_with_substring_search.rb
|
65
|
+
- lib/the_array_comparator/searching_strategies/contains_any.rb
|
66
|
+
- lib/the_array_comparator/searching_strategies/contains_any_with_substring_search.rb
|
67
|
+
- lib/the_array_comparator/searching_strategies/contains_not.rb
|
68
|
+
- lib/the_array_comparator/searching_strategies/contains_not_with_substring_search.rb
|
69
|
+
- lib/the_array_comparator/searching_strategies/is_equal.rb
|
70
|
+
- lib/the_array_comparator/searching_strategies/is_not_equal.rb
|
71
|
+
- lib/the_array_comparator/strategy_dispatcher.rb
|
69
72
|
- lib/the_array_comparator/testing_helper.rb
|
70
73
|
- lib/the_array_comparator/testing_helper/data_set.rb
|
71
74
|
- lib/the_array_comparator/testing_helper/test_data.rb
|
@@ -73,6 +76,8 @@ files:
|
|
73
76
|
- script/console
|
74
77
|
- script/terminal
|
75
78
|
- spec/benchmark/benchmark_spec.rb
|
79
|
+
- spec/cache/anonymous_cache_spec.rb
|
80
|
+
- spec/cache/single_value_cache_spec.rb
|
76
81
|
- spec/cache_spec.rb
|
77
82
|
- spec/check_spec.rb
|
78
83
|
- spec/comparator/base_spec.rb
|
@@ -89,6 +94,7 @@ files:
|
|
89
94
|
- spec/sample_spec.rb
|
90
95
|
- spec/spec_helper.rb
|
91
96
|
- spec/strategies_helper.rb
|
97
|
+
- spec/strategy_dispatcher/strategy_dispatcher_spec.rb
|
92
98
|
- spec/testing_helper/testing_helper_spec.rb
|
93
99
|
- the_array_comparator.gemspec
|
94
100
|
homepage: https://www.github.com/max_meyer/the_array_comparator
|
@@ -117,6 +123,8 @@ specification_version: 3
|
|
117
123
|
summary: you need to compare arrays? then this gem is very suitable for you.
|
118
124
|
test_files:
|
119
125
|
- spec/benchmark/benchmark_spec.rb
|
126
|
+
- spec/cache/anonymous_cache_spec.rb
|
127
|
+
- spec/cache/single_value_cache_spec.rb
|
120
128
|
- spec/cache_spec.rb
|
121
129
|
- spec/check_spec.rb
|
122
130
|
- spec/comparator/base_spec.rb
|
@@ -133,5 +141,6 @@ test_files:
|
|
133
141
|
- spec/sample_spec.rb
|
134
142
|
- spec/spec_helper.rb
|
135
143
|
- spec/strategies_helper.rb
|
144
|
+
- spec/strategy_dispatcher/strategy_dispatcher_spec.rb
|
136
145
|
- spec/testing_helper/testing_helper_spec.rb
|
137
146
|
has_rdoc:
|