the_array_comparator 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -27,4 +27,5 @@ group :development do
27
27
  gem 'activesupport'
28
28
  gem 'fuubar'
29
29
  gem 'churn'
30
+ gem 'fedux_org-stdlib'
30
31
  end
data/Gemfile.lock CHANGED
@@ -1,14 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- the_array_comparator (0.2.0)
5
- active_support
4
+ the_array_comparator (0.4.0)
5
+ activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- active_support (3.0.0)
11
- activesupport (= 3.0.0)
12
10
  activesupport (3.0.0)
13
11
  arrayfields (4.7.4)
14
12
  aruba (0.5.1)
@@ -43,6 +41,8 @@ GEM
43
41
  debugger-ruby_core_source (1.1.8)
44
42
  diff-lcs (1.1.3)
45
43
  fattr (2.2.1)
44
+ fedux_org-stdlib (0.1.0)
45
+ activesupport
46
46
  ffaker (1.15.0)
47
47
  ffi (1.4.0)
48
48
  fuubar (1.1.0)
@@ -107,6 +107,7 @@ DEPENDENCIES
107
107
  awesome_print
108
108
  churn
109
109
  debugger
110
+ fedux_org-stdlib
110
111
  ffaker
111
112
  fuubar
112
113
  github-markup
data/README.md CHANGED
@@ -3,9 +3,14 @@
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
- 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).
6
+
7
+ The Array Comparator lets you add multiple checks comparing two arrays each.
8
+ This way it lets you write more concise tests and makes error detection in a
9
+ commandline environment a lot easier -- [Use Cases](#use_cases). If you're
10
+ interested, please have a look at the <a
11
+ href="http://www.github.com/maxmeyer/the_array_comparator">git repository</a>.
12
+
13
+
9
14
 
10
15
  It also supports caching of previous comparism runs to reduce the amount of
11
16
  time for each subsequent run - if no further check was added.
@@ -28,6 +33,7 @@ Or install it yourself as:
28
33
 
29
34
  Currently the following strategies are supported
30
35
  <table>
36
+ <caption>Supported search strategies for checks</caption>
31
37
  <tr>
32
38
  <th>Strategy</th>
33
39
  <th>Description</th>
@@ -66,6 +72,45 @@ Currently the following strategies are supported
66
72
  </tr>
67
73
  </table>
68
74
 
75
+ To add a check you need to use `#add_check`-method. It accepts four arguments
76
+ * `data`: The data which should be searched
77
+ * `strategy`: The kind of check which should be added (see the table above for supported strategies)
78
+ * `keywords`: The keywords which should be looked up in data
79
+ * `options` (optional): Options for the check to be added (see the table below for valid options)
80
+
81
+ ```ruby
82
+ comparator.add_check data , operation, keywords, options
83
+ ```
84
+
85
+ <table>
86
+ <caption>Supported options for check</caption>
87
+ <tr>
88
+ <th>Option</th>
89
+ <th>Description</th>
90
+ </tr>
91
+ <tr>
92
+ <td>:tag</td>
93
+ <td>If you need to know which check caused the test suite to fail, add a
94
+ tag to the check. The array comparator records the sample which fails the
95
+ whole test suite. You can use *whatever* you want/can imagine as a tag:
96
+ e.g. `String`, `Symbol`. Personally I prefer to use `Symbol`s.</td>
97
+ </tr>
98
+ <tr>
99
+ <td>:exceptions</td>
100
+ <td>Some times you have a quite generic check which matches to many lines
101
+ in the sample. To help you with that, you can add an exception to a
102
+ check.</td>
103
+ </tr>
104
+ </table>
105
+
106
+ ```ruby
107
+ comparator.add_check data , operation, keywords, tag: :test_tag, exceptions: [ 'lala' ]
108
+ ```
109
+
110
+ If you ask the comparator for success before a check was added, it will return
111
+ `true`. If you ask it for the `#failed_sample` it will return an empty result
112
+ to you.
113
+
69
114
  ### Simple example
70
115
 
71
116
  ```ruby
@@ -103,7 +148,7 @@ data = %w{ acd b }
103
148
  keyword_overlap = %w{ a b }
104
149
  exceptions = %w{ cd }
105
150
 
106
- comparator.add_check data , :contains_all_as_substring, keyword_overlap, exceptions
151
+ comparator.add_check data , :contains_all_as_substring, keyword_overlap, exceptions: exceptions
107
152
 
108
153
  result = comparator.success?
109
154
  puts result #should be false
@@ -130,6 +175,7 @@ puts result #should be true
130
175
  ### Example with tag
131
176
 
132
177
  ```ruby
178
+ #simple, isn't it?
133
179
  require 'the_array_comparator'
134
180
  comparator = TheArrayComparator::Comparator.new
135
181
  data = %w{ a b c d }
@@ -137,10 +183,25 @@ keyword_successfull = %w{ a b }
137
183
  keyword_failed = %w{ e }
138
184
 
139
185
  comparator.add_check data , :contains_all , keyword_successfull
186
+ #comparator.add_check data , :contains_all , keyword_failed, tag: :this_is_another_tag
140
187
  comparator.add_check data , :contains_all , keyword_failed, tag: 'this is a failed sample'
141
188
 
142
189
  comparator.success?
143
- puts comparator.result.failed_sample
190
+ puts comparator.result.failed_sample.tag
191
+
192
+ #use WHATEVER you want!
193
+ require 'the_array_comparator'
194
+ require 'ostruct'
195
+ comparator = TheArrayComparator::Comparator.new
196
+ data = %w{ a b c d }
197
+ keyword_successfull = %w{ a b }
198
+ keyword_failed = %w{ e }
199
+
200
+ comparator.add_check data , :contains_all , keyword_successfull
201
+ comparator.add_check data , :contains_all , keyword_failed, tag: OpenStruct.new( id: 1, text: 'this is another tag as well' )
202
+
203
+ comparator.success?
204
+ puts comparator.result.failed_sample.tag.text
144
205
  ```
145
206
 
146
207
  ### Example with access to result
data/Rakefile CHANGED
@@ -1,93 +1 @@
1
- #!/usr/bin/env rake
2
-
3
- unless ENV['TRAVIS_CI'] == 'true'
4
- namespace :gem do
5
- require 'bundler/gem_tasks'
6
- end
7
-
8
- require 'yard'
9
- require 'rubygems/package_task'
10
- require 'active_support/core_ext/string/strip'
11
- end
12
-
13
- YARD::Rake::YardocTask.new() do |y|
14
- # y.options << '--verbose'
15
- end
16
-
17
- desc 'start tmux'
18
- task :terminal do
19
- sh "script/terminal"
20
- end
21
-
22
- task :term => :terminal
23
- task :t => :terminal
24
-
25
- namespace :version do
26
- version_file = Dir.glob('lib/**/version.rb').first
27
-
28
- desc 'bump version of library to new version'
29
- task :bump do
30
-
31
- new_version = ENV['VERSION'] || ENV['version']
32
-
33
- raw_module_name = File.open(version_file, "r").readlines.grep(/module/).first
34
- module_name = raw_module_name.chomp.match(/module\s+(\S+)/) {$1}
35
-
36
- version_string = %Q{#main #{module_name}
37
- module #{module_name}
38
- VERSION = '#{new_version}'
39
- end}
40
-
41
- File.open(version_file, "w") do |f|
42
- f.write version_string.strip_heredoc
43
- end
44
-
45
- sh "git add #{version_file}"
46
- sh "git commit -m 'version bump to #{new_version}'"
47
- project = 'the_array_comparator'
48
- sh "git tag #{project}-v#{new_version}"
49
- end
50
-
51
- desc 'show version of library'
52
- task :show do
53
- raw_version = File.open(version_file, "r").readlines.grep(/VERSION/).first
54
-
55
- if raw_version
56
- version = raw_version.chomp.match(/VERSION\s+=\s+["']([^'"]+)["']/) { $1 }
57
- puts version
58
- else
59
- warn "Could not parse version file \"#{version_file}\""
60
- end
61
-
62
- end
63
-
64
- desc 'Restore version file from git repository'
65
- task :restore do
66
- sh "git checkout #{version_file}"
67
- end
68
-
69
- end
70
-
71
- namespace :travis do
72
- desc 'Runs travis-lint to check .travis.yml'
73
- task :check do
74
- sh 'travis-lint'
75
- end
76
- end
77
-
78
- namespace :test do
79
- desc 'Run specs'
80
- task :specs do
81
- sh 'bundle exec rspec spec'
82
- end
83
-
84
- desc 'Run tests in "travis mode"'
85
- task :travis_specs do
86
- ENV['TRAVIS_CI'] = 'true'
87
- sh 'rspec spec'
88
- end
89
- end
90
-
91
- task :console do
92
- sh 'script/console'
93
- end
1
+ require 'fedux_org/stdlib/rake'
@@ -27,4 +27,5 @@ group :development do
27
27
  gem 'activesupport'
28
28
  gem 'fuubar'
29
29
  gem 'churn'
30
+ gem 'fedux_org-stdlib'
30
31
  end
@@ -90,7 +90,7 @@ module TheArrayComparator
90
90
  def result
91
91
  if @cache[:checks].new_objects?
92
92
  @cache[:checks].stored_objects.each do |c|
93
- @result = Result.new(c.sample) unless c.success?
93
+ @result = Result.new( c.sample ) unless c.success?
94
94
  end
95
95
  end
96
96
 
@@ -14,7 +14,13 @@ module TheArrayComparator
14
14
  end
15
15
 
16
16
  def failed_sample
17
- @sample
17
+ @sample || null_sample
18
+ end
19
+
20
+ private
21
+
22
+ def null_sample
23
+ Sample.new
18
24
  end
19
25
 
20
26
  end
@@ -37,5 +37,11 @@ module TheArrayComparator
37
37
  @tag = tag
38
38
  end
39
39
 
40
+ # Check if sample is blank: no values for keywords, data, exceptions, tag
41
+ #
42
+ # @return [true,false] the result of check
43
+ def blank?
44
+ @keywords.blank? and @data.blank? and @exceptions.blank? and @tag.blank?
45
+ end
40
46
  end
41
47
  end
@@ -1,4 +1,4 @@
1
1
  #main TheArrayComparator
2
2
  module TheArrayComparator
3
- VERSION = '0.4.0'
4
- end
3
+ VERSION = '0.5.0'
4
+ end
@@ -165,4 +165,19 @@ describe Comparator do
165
165
  result = comparator.result
166
166
  expect(result.failed_sample).to eq(c.sample)
167
167
  end
168
+
169
+ it "tells you the result of the check although no checks were added" do
170
+ comparator = Comparator.new
171
+ comparator.success?
172
+ result = comparator.result
173
+ expect( comparator.success? ).to eq(true)
174
+ end
175
+
176
+ it "returns an empty result if no checks were added but it is asked for a result" do
177
+ comparator = Comparator.new
178
+ comparator.success?
179
+
180
+ result = comparator.result
181
+ expect(result.failed_sample).to be_blank
182
+ end
168
183
  end
data/spec/sample_spec.rb CHANGED
@@ -34,5 +34,10 @@ describe Sample do
34
34
  expect(sample.exceptions).to eq(Set.new( [ exceptions ] ) )
35
35
  end
36
36
 
37
+ context '#blank' do
38
+ it "checks if all values are blank" do
39
+ expect( Sample.new.blank? ).to be_true
40
+ end
41
+ end
37
42
 
38
43
  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.0
4
+ version: 0.5.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-04-12 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport