the_array_comparator 0.1.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.
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CONTRIBUTIONS.md +7 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +122 -0
- data/LICENSE.md +20 -0
- data/README.md +121 -0
- data/RELEASE_NOTES.md +0 -0
- data/Rakefile +93 -0
- data/TODO.md +1 -0
- data/gemfiles/Gemfile.default +30 -0
- data/gemfiles/Gemfile.travis +15 -0
- data/lib/the_array_comparator/check.rb +27 -0
- data/lib/the_array_comparator/comparator.rb +123 -0
- data/lib/the_array_comparator/exceptions.rb +21 -0
- data/lib/the_array_comparator/result.rb +21 -0
- data/lib/the_array_comparator/sample.rb +28 -0
- data/lib/the_array_comparator/strategies/base.rb +41 -0
- data/lib/the_array_comparator/strategies/contains_all.rb +35 -0
- data/lib/the_array_comparator/strategies/contains_all_with_substring_search.rb +39 -0
- data/lib/the_array_comparator/strategies/contains_any.rb +34 -0
- data/lib/the_array_comparator/strategies/contains_any_with_substring_search.rb +33 -0
- data/lib/the_array_comparator/strategies/contains_not.rb +32 -0
- data/lib/the_array_comparator/strategies/contains_not_with_substring_search.rb +33 -0
- data/lib/the_array_comparator/strategies/is_equal.rb +30 -0
- data/lib/the_array_comparator/strategies/is_not_equal.rb +30 -0
- data/lib/the_array_comparator/testing_helper/data_set.rb +63 -0
- data/lib/the_array_comparator/testing_helper/test_data.rb +33 -0
- data/lib/the_array_comparator/testing_helper.rb +55 -0
- data/lib/the_array_comparator/version.rb +6 -0
- data/lib/the_array_comparator.rb +34 -0
- data/script/console +8 -0
- data/script/terminal +12 -0
- data/spec/benchmark/benchmark_spec.rb +28 -0
- data/spec/check_spec.rb +30 -0
- data/spec/comparator/base_spec.rb +16 -0
- data/spec/comparator/comparator_spec.rb +198 -0
- data/spec/comparator/contains_all_spec.rb +52 -0
- data/spec/comparator/contains_all_with_substring_search_spec.rb +41 -0
- data/spec/comparator/contains_any_spec.rb +45 -0
- data/spec/comparator/contains_any_with_substring_search_spec.rb +35 -0
- data/spec/comparator/contains_not_spec.rb +45 -0
- data/spec/comparator/contains_not_with_substring_search_spec.rb +28 -0
- data/spec/comparator/is_equal_spec.rb +51 -0
- data/spec/comparator/is_not_equal_spec.rb +39 -0
- data/spec/result_spec.rb +31 -0
- data/spec/sample_spec.rb +24 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/strategies_helper.rb +11 -0
- data/spec/testing_helper/testing_helper_spec.rb +27 -0
- data/the_array_comparator.gemspec +21 -0
- metadata +132 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Comparator do
|
5
|
+
it "let you register classes" do
|
6
|
+
comparator_instance = double('TestComparatorInstance')
|
7
|
+
comparator_instance.stub(:success?).and_return(true)
|
8
|
+
|
9
|
+
comparator_klass = double('TestComparatorClass')
|
10
|
+
comparator_klass.stub(:new).and_return(comparator_instance)
|
11
|
+
|
12
|
+
expect {
|
13
|
+
Comparator.register(:is_eqal_new, comparator_klass)
|
14
|
+
}.to_not raise_error Exceptions::IncompatibleComparator
|
15
|
+
end
|
16
|
+
|
17
|
+
it "fails when registering a not suitable class" do
|
18
|
+
comparator_instance = double('TestComparatorInstance')
|
19
|
+
comparator_instance.stub(:successasdf?).and_return(true)
|
20
|
+
|
21
|
+
comparator_klass = double('TestComparatorClass')
|
22
|
+
comparator_klass.stub(:new).and_return(comparator_instance)
|
23
|
+
expect {
|
24
|
+
Comparator.register(:is_eqal_new, comparator_klass)
|
25
|
+
}.to raise_error Exceptions::IncompatibleComparator
|
26
|
+
end
|
27
|
+
|
28
|
+
it "let you add check to check for" do
|
29
|
+
testrun = Comparator.new
|
30
|
+
data = %w{ a b c d}
|
31
|
+
keyword = %w{ a }
|
32
|
+
|
33
|
+
expect {
|
34
|
+
testrun.add_check data , :contains_all , keyword
|
35
|
+
}.to_not raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "fails if an unknown check is given" do
|
39
|
+
testrun = Comparator.new
|
40
|
+
data = %w{ a b c d}
|
41
|
+
keyword = %w{ a }
|
42
|
+
|
43
|
+
expect {
|
44
|
+
testrun.add_check data , :contains_all_abc , keyword
|
45
|
+
}.to raise_error Exceptions::UnknownCheckType
|
46
|
+
end
|
47
|
+
|
48
|
+
it "let you register and use classes" do
|
49
|
+
comparator_instance = double('TestComparatorInstance')
|
50
|
+
comparator_instance.stub(:success?).and_return(true)
|
51
|
+
|
52
|
+
comparator_klass = double('TestComparatorClass')
|
53
|
+
comparator_klass.stub(:new).and_return(comparator_instance)
|
54
|
+
|
55
|
+
Comparator.register(:new_comp, comparator_klass)
|
56
|
+
|
57
|
+
comparator = Comparator.new
|
58
|
+
comparator.add_check %w{a}, :new_comp , %{a}
|
59
|
+
result = comparator.success?
|
60
|
+
|
61
|
+
expect(result).to eq(true)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "support some comparators by default" do
|
65
|
+
testrun = Comparator.new
|
66
|
+
data = %w{ a b c d}
|
67
|
+
keyword = %w{ a }
|
68
|
+
|
69
|
+
expect {
|
70
|
+
testrun.add_check data , :contains_all , keyword
|
71
|
+
testrun.add_check data , :contains_any , keyword
|
72
|
+
testrun.add_check data , :not_contains , keyword
|
73
|
+
testrun.add_check data , :contains_all_as_substring , keyword
|
74
|
+
testrun.add_check data , :contains_any_as_substring , keyword
|
75
|
+
testrun.add_check data , :not_contains_substring , keyword
|
76
|
+
testrun.add_check data , :is_equal , keyword
|
77
|
+
testrun.add_check data , :is_not_equal , keyword
|
78
|
+
}.to_not raise_error
|
79
|
+
end
|
80
|
+
|
81
|
+
it "is successfull if all subtests are successfull" do
|
82
|
+
comparator = Comparator.new
|
83
|
+
data = %w{ a b c d }
|
84
|
+
keyword_overlap = %w{ a b }
|
85
|
+
keyword_no_overlap = %w{ e }
|
86
|
+
|
87
|
+
comparator.add_check data , :contains_all , keyword_overlap
|
88
|
+
comparator.add_check data , :not_contains , keyword_no_overlap
|
89
|
+
|
90
|
+
result = comparator.success?
|
91
|
+
expect(result).to eq(true)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "fails if a least one subtest fails", :test => true do
|
95
|
+
comparator = Comparator.new
|
96
|
+
data = %w{ a b c d }
|
97
|
+
keyword_overlap = %w{ a }
|
98
|
+
keyword_no_overlap = %w{ e }
|
99
|
+
|
100
|
+
comparator.add_check data , :contains_all , keyword_overlap #should not fail
|
101
|
+
comparator.add_check data , :not_contains , keyword_overlap #should fail
|
102
|
+
|
103
|
+
result = comparator.success?
|
104
|
+
expect(result).to eq(false)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "supports the addition of exceptions as well" do
|
108
|
+
comparator = Comparator.new
|
109
|
+
data = %w{ ab c d}
|
110
|
+
keyword_overlap = %w{ a }
|
111
|
+
exceptions = %w{ ab }
|
112
|
+
|
113
|
+
comparator.add_check data , :contains_any_as_substring , keyword_overlap
|
114
|
+
comparator.add_check data , :not_contains_substring , keyword_overlap, :exceptions => exceptions
|
115
|
+
|
116
|
+
result = comparator.success?
|
117
|
+
expect(result).to eq(true)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "list all added check" do
|
121
|
+
comparator = Comparator.new
|
122
|
+
data = []
|
123
|
+
keywords = []
|
124
|
+
|
125
|
+
check = comparator.add_check data , :contains_any, keywords
|
126
|
+
list = comparator.list_checks.first
|
127
|
+
|
128
|
+
expect(list).to eq(check)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "deletes the n-th check" do
|
132
|
+
comparator = Comparator.new
|
133
|
+
data = []
|
134
|
+
keywords = []
|
135
|
+
|
136
|
+
test_comps = []
|
137
|
+
|
138
|
+
test_comps << comparator.add_check(data , :contains_any, keywords)
|
139
|
+
comparator.add_check(data , :contains_any, keywords)
|
140
|
+
test_comps << comparator.add_check(data , :contains_any, keywords)
|
141
|
+
comparator.delete_check(1)
|
142
|
+
|
143
|
+
list = comparator.list_checks
|
144
|
+
expect(list).to eq(test_comps)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "raises an error if a user tries to delete an unexisting check" do
|
148
|
+
comparator = Comparator.new
|
149
|
+
|
150
|
+
expect {
|
151
|
+
comparator.delete_last_check
|
152
|
+
}.to raise_error Exceptions::CheckDoesNotExist
|
153
|
+
end
|
154
|
+
|
155
|
+
it "deletes the last check" do
|
156
|
+
comparator = Comparator.new
|
157
|
+
data = []
|
158
|
+
keywords = []
|
159
|
+
|
160
|
+
test_comps = []
|
161
|
+
|
162
|
+
test_comps << comparator.add_check(data , :contains_any, keywords)
|
163
|
+
test_comps << comparator.add_check(data , :contains_any, keywords)
|
164
|
+
comparator.add_check(data , :contains_any, keywords)
|
165
|
+
comparator.delete_last_check
|
166
|
+
|
167
|
+
list = comparator.list_checks
|
168
|
+
expect(list).to eq(test_comps)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "tells you the result of the check" do
|
172
|
+
comparator = Comparator.new
|
173
|
+
data = %w{ a b c d }
|
174
|
+
keyword_overlap = %w{ a b }
|
175
|
+
keyword_no_overlap = %w{ e }
|
176
|
+
|
177
|
+
comparator.add_check data , :contains_all , keyword_overlap
|
178
|
+
comparator.add_check data , :not_contains , keyword_no_overlap
|
179
|
+
|
180
|
+
comparator.success?
|
181
|
+
result = comparator.result
|
182
|
+
expect(result.of_checks).to eq(true)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "tells you which check has failed and made the whole thing failed" do
|
186
|
+
comparator = Comparator.new
|
187
|
+
data = %w{ a b c d }
|
188
|
+
keyword_successfull = %w{ a b }
|
189
|
+
keyword_failed = %w{ e }
|
190
|
+
|
191
|
+
comparator.add_check data , :contains_all , keyword_successfull
|
192
|
+
c = comparator.add_check data , :contains_all , keyword_failed, tag: 'this is a failed sample'
|
193
|
+
|
194
|
+
comparator.success?
|
195
|
+
result = comparator.result
|
196
|
+
expect(result.failed_sample).to eq(c.sample)
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsAll do
|
6
|
+
let(:data) { %w{ a b c e} }
|
7
|
+
let(:keywords_overlap) { %w{ a } }
|
8
|
+
let(:keywords_no_overlap) { %w{ d } }
|
9
|
+
let(:multiple_keywords_with_one_no_overlap) { %w{ a b cd } }
|
10
|
+
|
11
|
+
it "fails if keywords are empty" do
|
12
|
+
sample = SampleDouble.new(data,[])
|
13
|
+
comparator = Strategies::ContainsAll.new(sample)
|
14
|
+
expect(comparator.success?).to eq(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "fails if data is empty" do
|
18
|
+
sample = SampleDouble.new([],keywords_no_overlap)
|
19
|
+
comparator = Strategies::ContainsAll.new(sample)
|
20
|
+
expect(comparator.success?).to eq(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is successfull if both keywords and data are empty" do
|
24
|
+
sample = SampleDouble.new([],[])
|
25
|
+
comparator = Strategies::ContainsAll.new(sample)
|
26
|
+
expect(comparator.success?).to eq(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "is successfull when there's a data overlap" do
|
30
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
31
|
+
comparator = Strategies::ContainsAll.new(sample)
|
32
|
+
expect(comparator.success?).to eq(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "doesn't find something if there's no overlap" do
|
36
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
37
|
+
comparator = Strategies::ContainsAll.new(sample)
|
38
|
+
expect(comparator.success?).to eq(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "fails if not all keywords can be found within the data" do
|
42
|
+
sample = SampleDouble.new(data,multiple_keywords_with_one_no_overlap)
|
43
|
+
comparator = Strategies::ContainsAll.new(sample)
|
44
|
+
expect(comparator.success?).to eq(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "doesn't find something if there's an exception" do
|
48
|
+
#not implemented since it's not neccessary
|
49
|
+
#just leave the unneed element out of the
|
50
|
+
#keyword array
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsAllWithSubstringSearch do
|
6
|
+
let(:data) { %w{ ab c e} }
|
7
|
+
let(:exceptions) { %w{ b } }
|
8
|
+
let(:keywords_overlap) { %w{ a } }
|
9
|
+
let(:keywords_no_overlap) { %w{ d } }
|
10
|
+
let(:multiple_keywords_with_one_no_overlap) { %w{ a b cd } }
|
11
|
+
|
12
|
+
it "is successfull when there's a data overlap" do
|
13
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
14
|
+
comparator = Strategies::ContainsAllWithSubstringSearch.new(sample)
|
15
|
+
expect(comparator.success?).to eq(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "doesn't find something if there's no overlap" do
|
19
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
20
|
+
comparator = Strategies::ContainsAllWithSubstringSearch.new(sample)
|
21
|
+
expect(comparator.success?).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't find something if there's an exception defined" do
|
25
|
+
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
26
|
+
comparator = Strategies::ContainsAllWithSubstringSearch.new(sample)
|
27
|
+
expect(comparator.success?).to eq(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "doesn't find something if there's an exception defined" do
|
31
|
+
sample = SampleDouble.new(data,multiple_keywords_with_one_no_overlap, exceptions)
|
32
|
+
comparator = Strategies::ContainsAllWithSubstringSearch.new(sample)
|
33
|
+
expect(comparator.success?).to eq(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "fails if not all keywords can be found within the data" do
|
37
|
+
sample = SampleDouble.new(data,multiple_keywords_with_one_no_overlap)
|
38
|
+
comparator = Strategies::ContainsAllWithSubstringSearch.new(sample)
|
39
|
+
expect(comparator.success?).to eq(false)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsAny do
|
6
|
+
let(:data) { %w{ a b c e} }
|
7
|
+
let(:keywords_overlap) { %w{ a } }
|
8
|
+
let(:keywords_no_overlap) { %w{ d } }
|
9
|
+
|
10
|
+
it "fails if keywords are empty" do
|
11
|
+
sample = SampleDouble.new(data,[])
|
12
|
+
comparator = Strategies::ContainsAny.new(sample)
|
13
|
+
expect(comparator.success?).to eq(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails if data is empty" do
|
17
|
+
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
+
comparator = Strategies::ContainsAny.new(sample)
|
19
|
+
expect(comparator.success?).to eq(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is successfull if both keywords and data are empty" do
|
23
|
+
sample = SampleDouble.new([],[])
|
24
|
+
comparator = Strategies::ContainsAny.new(sample)
|
25
|
+
expect(comparator.success?).to eq(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is successfull when there's a data overlap" do
|
29
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
+
comparator = Strategies::ContainsAny.new(sample)
|
31
|
+
expect(comparator.success?).to eq(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "doesn't find something if there's no overlap" do
|
35
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
+
comparator = Strategies::ContainsAny.new(sample)
|
37
|
+
expect(comparator.success?).to eq(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "doesn't find something if there's an exception" do
|
41
|
+
#not implemented since it's not neccessary
|
42
|
+
#just leave the unneed element out of the
|
43
|
+
#keyword array
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsAnyWithSubstringSearch do
|
6
|
+
let(:data) { %w{ ab c e} }
|
7
|
+
let(:exceptions) { %w{ b} }
|
8
|
+
let(:keywords_overlap) { %w{ a } }
|
9
|
+
let(:multiple_overlap) { %w{ a c d} }
|
10
|
+
let(:keywords_no_overlap) { %w{ d } }
|
11
|
+
|
12
|
+
it "is successfull when there's a data overlap (at least one element)" do
|
13
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
14
|
+
comparator = Strategies::ContainsAnyWithSubstringSearch.new(sample)
|
15
|
+
expect(comparator.success?).to eq(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "doesn't find something if there's no overlap" do
|
19
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
20
|
+
comparator = Strategies::ContainsAnyWithSubstringSearch.new(sample)
|
21
|
+
expect(comparator.success?).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't find something if there's an exception defined" do
|
25
|
+
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
26
|
+
comparator = Strategies::ContainsAnyWithSubstringSearch.new(sample)
|
27
|
+
expect(comparator.success?).to eq(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "is successfull, if there's a least one match (second match 'c' -> exception -> no match) " do
|
31
|
+
sample = SampleDouble.new(data,multiple_overlap, exceptions)
|
32
|
+
comparator = Strategies::ContainsAnyWithSubstringSearch.new(sample)
|
33
|
+
expect(comparator.success?).to eq(true)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsNot do
|
6
|
+
let(:data) { %w{ a b c e} }
|
7
|
+
let(:keywords_overlap) { %w{ a } }
|
8
|
+
let(:keywords_no_overlap) { %w{ d } }
|
9
|
+
|
10
|
+
it "is successfull if keywords are empty" do
|
11
|
+
sample = SampleDouble.new(data,[])
|
12
|
+
comparator = Strategies::ContainsNot.new(sample)
|
13
|
+
expect(comparator.success?).to eq(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is successfull if data is empty" do
|
17
|
+
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
+
comparator = Strategies::ContainsNot.new(sample)
|
19
|
+
expect(comparator.success?).to eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails if both keywords and data are empty" do
|
23
|
+
sample = SampleDouble.new([],[])
|
24
|
+
comparator = Strategies::ContainsNot.new(sample)
|
25
|
+
expect(comparator.success?).to eq(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is successfull if there's a data overlap" do
|
29
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
+
comparator = Strategies::ContainsNot.new(sample)
|
31
|
+
expect(comparator.success?).to eq(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "doesn't find something if there's no overlap" do
|
35
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
+
comparator = Strategies::ContainsNot.new(sample)
|
37
|
+
expect(comparator.success?).to eq(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "doesn't find something if there's an exception" do
|
41
|
+
#not implemented since it's not neccessary
|
42
|
+
#just leave the unneed element out of the
|
43
|
+
#keyword array
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::ContainsNotWithSubstringSearch do
|
6
|
+
let(:data) { %w{ ab c e } }
|
7
|
+
let(:exceptions) { %w{ a } }
|
8
|
+
let(:keywords_overlap) { %w{ ab } }
|
9
|
+
let(:keywords_no_overlap) { %w{ d } }
|
10
|
+
|
11
|
+
it "is successfull when there's a no overlap" do
|
12
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
13
|
+
comparator = Strategies::ContainsNotWithSubstringSearch.new(sample)
|
14
|
+
expect(comparator.success?).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "doesn't find something if there's an overlap" do
|
18
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
19
|
+
comparator = Strategies::ContainsNotWithSubstringSearch.new(sample)
|
20
|
+
expect(comparator.success?).to eq(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is successfull although there's an overlap, but an exception defined" do
|
24
|
+
sample = SampleDouble.new(data,keywords_overlap, exceptions)
|
25
|
+
comparator = Strategies::ContainsNotWithSubstringSearch.new(sample)
|
26
|
+
expect(comparator.success?).to eq(true)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::IsEqual do
|
6
|
+
let(:data) { %w{ a } }
|
7
|
+
let(:keywords_overlap) { %w{ a } }
|
8
|
+
let(:keywords_no_overlap) { %w{ d } }
|
9
|
+
|
10
|
+
it "fails if keywords are empty" do
|
11
|
+
sample = SampleDouble.new(data,[])
|
12
|
+
comparator = Strategies::IsEqual.new(sample)
|
13
|
+
expect(comparator.success?).to eq(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails if data is empty" do
|
17
|
+
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
+
comparator = Strategies::IsEqual.new(sample)
|
19
|
+
expect(comparator.success?).to eq(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is successfull if both keywords and data are empty" do
|
23
|
+
sample = SampleDouble.new([],[])
|
24
|
+
comparator = Strategies::IsEqual.new(sample)
|
25
|
+
expect(comparator.success?).to eq(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is successfull if data and keywords are equal" do
|
29
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
+
comparator = Strategies::IsEqual.new(sample)
|
31
|
+
expect(comparator.success?).to eq(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fails if data and keywords are different" do
|
35
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
+
comparator = Strategies::IsEqual.new(sample)
|
37
|
+
expect(comparator.success?).to eq(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
#tested at this point for all classes
|
41
|
+
it "displays a warning if an exception is defined (is not supported by this strategy)" do
|
42
|
+
needed_msg = "Exceptions are not supported by this strategy.\n"
|
43
|
+
sample = SampleDouble.new(data,keywords_no_overlap,%w{a})
|
44
|
+
|
45
|
+
msg = capture(:stderr) do
|
46
|
+
Strategies::IsEqual.new(sample)
|
47
|
+
end
|
48
|
+
|
49
|
+
expect(msg).to eq(needed_msg)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'strategies_helper'
|
4
|
+
|
5
|
+
describe Strategies::IsNotEqual do
|
6
|
+
let(:data) { %w{ a } }
|
7
|
+
let(:keywords_overlap) { %w{ a } }
|
8
|
+
let(:keywords_no_overlap) { %w{ d } }
|
9
|
+
|
10
|
+
it "is successfull if keywords are empty" do
|
11
|
+
sample = SampleDouble.new(data,[])
|
12
|
+
comparator = Strategies::IsNotEqual.new(sample)
|
13
|
+
expect(comparator.success?).to eq(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is successfull if data is empty" do
|
17
|
+
sample = SampleDouble.new([],keywords_no_overlap)
|
18
|
+
comparator = Strategies::IsNotEqual.new(sample)
|
19
|
+
expect(comparator.success?).to eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails if both keywords and data are empty" do
|
23
|
+
sample = SampleDouble.new([],[])
|
24
|
+
comparator = Strategies::IsNotEqual.new(sample)
|
25
|
+
expect(comparator.success?).to eq(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "fails if data and keywords are equal" do
|
29
|
+
sample = SampleDouble.new(data,keywords_overlap)
|
30
|
+
comparator = Strategies::IsNotEqual.new(sample)
|
31
|
+
expect(comparator.success?).to eq(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is successfull if data and keywords are different" do
|
35
|
+
sample = SampleDouble.new(data,keywords_no_overlap)
|
36
|
+
comparator = Strategies::IsNotEqual.new(sample)
|
37
|
+
expect(comparator.success?).to eq(true)
|
38
|
+
end
|
39
|
+
end
|
data/spec/result_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Result do
|
4
|
+
sample_klass = Class.new do
|
5
|
+
attr_accessor :data, :keywords, :exceptions, :tag
|
6
|
+
|
7
|
+
def initialize(data,keywords,exceptions,tag)
|
8
|
+
@data = data
|
9
|
+
@keywords = keywords
|
10
|
+
@exceptions = exceptions
|
11
|
+
@tag = tag
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns true if _no_ sample is defined" do
|
16
|
+
result = Result.new()
|
17
|
+
expect(result.of_checks).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false if sample is defined" do
|
21
|
+
data = %w{ data }
|
22
|
+
keywords = %w{ keywords }
|
23
|
+
exceptions = %w{ exceptions }
|
24
|
+
tag = 'this is a tag'
|
25
|
+
sample = sample_klass.new(data,keywords,exceptions,tag)
|
26
|
+
|
27
|
+
result = Result.new(sample)
|
28
|
+
expect(result.of_checks).to eq(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/sample_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Sample do
|
5
|
+
it "takes nothing by default" do
|
6
|
+
expect {
|
7
|
+
Sample.new()
|
8
|
+
}.to_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "takes data, keywords, exceptions, tags" do
|
12
|
+
data = %w{ data }
|
13
|
+
keywords = %w{ keywords }
|
14
|
+
exceptions = %w{ exceptions }
|
15
|
+
tag = 'this is a tag'
|
16
|
+
|
17
|
+
sample = Sample.new(data, keywords, exceptions, tag)
|
18
|
+
|
19
|
+
expect(sample.data).to eq(data)
|
20
|
+
expect(sample.keywords).to eq(keywords)
|
21
|
+
expect(sample.exceptions).to eq(exceptions)
|
22
|
+
expect(sample.tag).to eq(tag)
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path('../lib' , File.dirname(__FILE__))
|
4
|
+
|
5
|
+
unless ENV['TRAVIS_CI'] == 'true'
|
6
|
+
require 'pry'
|
7
|
+
require 'debugger'
|
8
|
+
require 'ap'
|
9
|
+
require 'ffaker'
|
10
|
+
require 'benchmark'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'stringio'
|
14
|
+
require 'tempfile'
|
15
|
+
|
16
|
+
require 'active_support/core_ext/object/blank'
|
17
|
+
require 'active_support/core_ext/numeric/time'
|
18
|
+
#require 'active_support/core_ext/kernel/reporting'
|
19
|
+
|
20
|
+
unless ENV['TRAVIS_CI'] == 'true'
|
21
|
+
require 'simplecov'
|
22
|
+
SimpleCov.start
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'the_array_comparator'
|
26
|
+
require 'the_array_comparator/testing_helper/data_set'
|
27
|
+
require 'the_array_comparator/testing_helper/test_data'
|
28
|
+
require 'the_array_comparator/testing_helper'
|
29
|
+
|
30
|
+
RSpec.configure do |c|
|
31
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
32
|
+
# c.filter_run_including :focus => true
|
33
|
+
end
|
34
|
+
|
35
|
+
include TheArrayComparator
|
36
|
+
include TheArrayComparator::TestingHelper
|
37
|
+
|
38
|
+
#ENV['PATH'] = '/bin'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#enconding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "#generate_testdata" do
|
5
|
+
|
6
|
+
it "spread the testdata when amount of data is lower than keywords" do
|
7
|
+
data = generate_testdata(keywords: %w{a b c d}, raw_data: %w{data1 data2})
|
8
|
+
expect(data[2]).to eq('a')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "spread the testdata when amount of data is equal to the amount of the keywords" do
|
12
|
+
data = generate_testdata(keywords: %w{a b c d}, raw_data: %w{data1 data2 data3 data4})
|
13
|
+
expect(data[1]).to eq('a')
|
14
|
+
expect(data[2]).to eq('data2')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "spread the testdata when amount of data is larger than keywords" do
|
18
|
+
data = generate_testdata(keywords: %w{a b c d}, raw_data: %w{data1 data2 data3 data4 data5})
|
19
|
+
expect(data[1]).to eq('a')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "spread the testdata when amount of data is not a multiply of keywords (it cares for the rest)" do
|
23
|
+
data = generate_testdata(keywords: %w{a b c d}, raw_data: [ 'data' ] * 99 )
|
24
|
+
expect(data[2]).to eq('data')
|
25
|
+
expect(data[24]).to eq('a')
|
26
|
+
end
|
27
|
+
end
|