the_array_comparator 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +97 -5
- data/RELEASE_NOTES.md +3 -0
- data/lib/the_array_comparator/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/maxmeyer/the_array_comparator)
|
4
4
|
[![Build Status](https://travis-ci.org/maxmeyer/the_array_comparator.png?branch=master)](https://travis-ci.org/maxmeyer/the_array_comparator)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
The Array Comparator can be used to compare to arrays with a consistent api: It
|
7
|
+
lets you write more concise tests and makes error detection in a commandline
|
8
|
+
environment easier - see [Use Cases](#use_cases).
|
9
|
+
|
10
|
+
It also supports caching of previous comparism runs to reduce the amount of
|
11
|
+
time for each subsequent run - if no further check was added.
|
9
12
|
|
10
13
|
## Installation
|
11
14
|
|
@@ -106,6 +109,55 @@ result = comparator.success?
|
|
106
109
|
puts result #should be false
|
107
110
|
```
|
108
111
|
|
112
|
+
### Example with multiple checks
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
require 'the_array_comparator'
|
116
|
+
comparator = TheArrayComparator::Comparator.new
|
117
|
+
|
118
|
+
data = %w{ acd b }
|
119
|
+
keyword_overlap = %w{ a b }
|
120
|
+
comparator.add_check data , :contains_all_as_substring, keyword_overlap
|
121
|
+
|
122
|
+
data = %w{1 2 3 4}
|
123
|
+
keywords = %w{ a b }
|
124
|
+
comparator.add_check data , :not_contains, keywords
|
125
|
+
|
126
|
+
result = comparator.success?
|
127
|
+
puts result #should be true
|
128
|
+
```
|
129
|
+
|
130
|
+
### Example with tag
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
require 'the_array_comparator'
|
134
|
+
comparator = TheArrayComparator::Comparator.new
|
135
|
+
data = %w{ a b c d }
|
136
|
+
keyword_successfull = %w{ a b }
|
137
|
+
keyword_failed = %w{ e }
|
138
|
+
|
139
|
+
comparator.add_check data , :contains_all , keyword_successfull
|
140
|
+
comparator.add_check data , :contains_all , keyword_failed, tag: 'this is a failed sample'
|
141
|
+
|
142
|
+
comparator.success?
|
143
|
+
puts comparator.result.failed_sample
|
144
|
+
```
|
145
|
+
|
146
|
+
### Example with access to result
|
147
|
+
```ruby
|
148
|
+
require 'the_array_comparator'
|
149
|
+
comparator = TheArrayComparator::Comparator.new
|
150
|
+
|
151
|
+
data = %w{ a c d b }
|
152
|
+
keyword_overlap = %w{ a b }
|
153
|
+
comparator.add_check data , :not_contains, keyword_overlap
|
154
|
+
|
155
|
+
p comparator.success?
|
156
|
+
p comparator.result.of_checks
|
157
|
+
p comparator.result.failed_sample
|
158
|
+
```
|
159
|
+
|
160
|
+
|
109
161
|
### Extend the library
|
110
162
|
|
111
163
|
If you wish to write your own comparators you can do so. Just register those classes with a keyword.
|
@@ -115,10 +167,50 @@ c = TheArrayComparator::Comparator.new
|
|
115
167
|
c.register :my_contains, SearchingStrategies::MyContains
|
116
168
|
```
|
117
169
|
|
170
|
+
##<a name=use_cases>Use Cases</a>
|
171
|
+
|
172
|
+
### Testing
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
require 'the_array_comparator'
|
176
|
+
describe TheArrayComparator
|
177
|
+
it "tells you the result of the check" do
|
178
|
+
comparator = TheArrayComparator::Comparator.new
|
179
|
+
data = %w{ a b c d }
|
180
|
+
keyword_overlap = %w{ a b }
|
181
|
+
keyword_no_overlap = %w{ e }
|
182
|
+
|
183
|
+
comparator.add_check data , :contains_all , keyword_overlap
|
184
|
+
comparator.add_check data , :not_contains , keyword_no_overlap
|
185
|
+
|
186
|
+
expect(comparator.success?).to eq(true)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
### Error checking
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
#!/usr/bin/env ruby
|
195
|
+
|
196
|
+
require 'open3'
|
197
|
+
require 'the_array_comparator'
|
198
|
+
|
199
|
+
stdout_str, stderr_str, status = Open3.capture3("/usr/bin/env echo error")
|
200
|
+
|
201
|
+
comparator = TheArrayComparator::Comparator.new
|
202
|
+
comparator.add_check stdout_str.split("\n") , :contains_all , %w[ error ]
|
203
|
+
comparator.add_check [ status.exitstatus ] , :contains_all , [ 0 ]
|
204
|
+
|
205
|
+
p comparator.success? #should be true
|
206
|
+
```
|
207
|
+
|
118
208
|
## Further reading
|
119
209
|
|
120
|
-
Please
|
121
|
-
|
210
|
+
Please see the full api-documentation on [rdoc
|
211
|
+
info](http://rdoc.info/github/maxmeyer/the_array_comparator/frames) for further
|
212
|
+
reading. There's also a brief [guide](API-GUIDE.md) about howto discover the
|
213
|
+
API.
|
122
214
|
|
123
215
|
## Contributing
|
124
216
|
|
data/RELEASE_NOTES.md
CHANGED