diff_matcher 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ rvm:
2
+ # - 1.8.6 # travis no longer supports this https://twitter.com/#!/travisci/status/114926454122364928
3
+ - 1.8.7
4
+ # - 1.9.1 # travis no longer supports this https://twitter.com/#!/travisci/status/114926454122364928
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - rbx
8
+ - rbx-2.0
9
+ - ree
10
+ - ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### v1.0.1
4
+
5
+ * BUGFIX for ruby 1.8.7
6
+
7
+ ### v1.0.0
8
+
9
+ * initial release (as a gem in the wild)
data/Gemfile CHANGED
@@ -1,9 +1,12 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gemspec
3
+ #gemspec
4
4
 
5
- group :test do
6
- gem "rake"
7
- gem "rspec" #, "~> 2.0.1"
8
- gem "simplecov"
5
+ gem "rake" , "~> 0.9"
6
+ gem "rspec", "~> 2.6.0"
7
+
8
+ group :development do
9
+ platforms :mri_19 do
10
+ gem "simplecov"
11
+ end
9
12
  end
data/README.md CHANGED
@@ -24,78 +24,100 @@ Installation
24
24
  Usage
25
25
  ---
26
26
 
27
- require 'diff_matcher'
28
-
29
- DiffMatcher::difference(actual, expected, opts={})
27
+ ``` ruby
28
+ require 'diff_matcher'
29
+
30
+ DiffMatcher::difference(actual, expected, opts={})
31
+ ```
30
32
 
31
33
  When `expected` != `actual`
32
34
 
33
- puts DiffMatcher::difference(1, 2)
34
- # => - 1+ 2
35
- # => Where, - 1 missing, + 1 additional
35
+ ``` ruby
36
+ puts DiffMatcher::difference(1, 2)
37
+ # => - 1+ 2
38
+ # => Where, - 1 missing, + 1 additional
39
+ ```
36
40
 
37
41
  When `expected` == `actual`
38
42
 
39
- p DiffMatcher::difference(1, 1)
40
- # => nil
43
+ ``` ruby
44
+ p DiffMatcher::difference(1, 1)
45
+ # => nil
46
+ ```
41
47
 
42
48
  When `actual` is an instance of the `expected`
43
49
 
44
- p DiffMatcher::difference(String, '1')
45
- # => nil
50
+ ``` ruby
51
+ p DiffMatcher::difference(String, '1')
52
+ # => nil
53
+ ```
46
54
 
47
55
  When `actual` is a string that matches the `expected` regex
48
56
 
49
- p DiffMatcher::difference(/[a-z]/, "a")
50
- # => nil
57
+ ``` ruby
58
+ p DiffMatcher::difference(/[a-z]/, "a")
59
+ # => nil
60
+ ```
51
61
 
52
62
  When `actual` is passed to an `expected` proc and it returns true
53
63
 
54
- is_boolean = lambda { |x| [FalseClass, TrueClass].include? x.class }
55
- p DiffMatcher::difference(is_boolean, true)
56
- # => nil
64
+ ``` ruby
65
+ is_boolean = lambda { |x| [FalseClass, TrueClass].include? x.class }
66
+ p DiffMatcher::difference(is_boolean, true)
67
+ # => nil
68
+ ```
57
69
 
58
70
  When `actual` is missing one of the `expected` values
59
71
 
60
- puts DiffMatcher::difference([1, 2], [1])
61
- # => [
62
- # => - 2
63
- # => ]
64
- # => Where, - 1 missing
72
+ ``` ruby
73
+ puts DiffMatcher::difference([1, 2], [1])
74
+ # => [
75
+ # => - 2
76
+ # => ]
77
+ # => Where, - 1 missing
78
+ ```
65
79
 
66
80
  When `actual` has additional values to the `expected`
67
81
 
68
- puts DiffMatcher::difference([1], [1, 2])
69
- # => [
70
- # => + 2
71
- # => ]
72
- # => Where, - 1 additional
82
+ ``` ruby
83
+ puts DiffMatcher::difference([1], [1, 2])
84
+ # => [
85
+ # => + 2
86
+ # => ]
87
+ # => Where, - 1 additional
88
+ ```
73
89
 
74
90
  ### Options
75
91
 
76
92
  `:ignore_additional=>true` will match even if `actual` has additional items
77
93
 
78
- p DiffMatcher::difference([1], [1, 2], :ignore_additional=>true)
79
- # => nil
94
+ ``` ruby
95
+ p DiffMatcher::difference([1], [1, 2], :ignore_additional=>true)
96
+ # => nil
97
+ ```
80
98
 
81
99
  `:verbose=>true` shows only missing and additional items in the output
82
100
 
83
- puts DiffMatcher::difference([Fixnum, 2], [1], :quiet=>true)
84
- # => [
85
- # => - 2
86
- # => ]
87
- # => Where, - 1 missing
101
+ ``` ruby
102
+ puts DiffMatcher::difference([Fixnum, 2], [1], :quiet=>true)
103
+ # => [
104
+ # => - 2
105
+ # => ]
106
+ # => Where, - 1 missing
107
+ ```
88
108
 
89
109
  `:verbose=>true` shows all matched items in the output
90
110
 
91
- puts DiffMatcher::difference([Fixnum, 2], [1], :verbose=>true)
92
- # => [
93
- # = > : 1,
94
- # => - 2
95
- # => ]
96
- # => Where, - 1 missing, : 1 match_class
111
+ ``` ruby
112
+ puts DiffMatcher::difference([Fixnum, 2], [1], :verbose=>true)
113
+ # => [
114
+ # = > : 1,
115
+ # => - 2
116
+ # => ]
117
+ # => Where, - 1 missing, : 1 match_class
118
+ ```
97
119
 
98
- #### prefixes
120
+ #### Prefixes
99
121
 
100
122
  NB. The `: 1` from above includes a `:` prefix that shows the `1` was matched against a class (ie. `Fixnum`)
101
123
 
@@ -108,7 +130,7 @@ The items shown in a difference are prefixed as follows:
108
130
  match class => ": "
109
131
  match proc => "{ "
110
132
 
111
- #### colours
133
+ #### Colours
112
134
 
113
135
  Colours (defined in colour schemes) can also appear in the difference.
114
136
 
@@ -122,11 +144,15 @@ Using the `:default` colour scheme items shown in a difference are coloured as f
122
144
  match proc => cyan
123
145
 
124
146
 
147
+ `:color_scheme=>:white_background` shows difference as follows
148
+
149
+ ``` ruby
125
150
  puts DiffMatcher::difference(
126
151
  { :a=>{ :a1=>11 }, :b=>[ 21, 22 ], :c=>/\d/, :d=>Fixnum, :e=>lambda { |x| (4..6).includes? x },
127
152
  { :a=>{ :a1=>10, :a2=>12 }, :b=>[ 21 ], :c=>'3' , :d=>4 , :e=>5 },
128
153
  :verbose=>true, :color_scheme=>:white_background
129
154
  )
155
+ ```
130
156
 
131
157
  ![example output](https://raw.github.com/playup/diff_matcher/master/doc/example_output.png)
132
158
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'bundler'
2
-
2
+ Bundler.setup
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
5
  require "rspec/core/rake_task"
@@ -49,7 +49,7 @@ module DiffMatcher
49
49
  def matching?
50
50
  @match ||= @difference ? item_types.map { |item_type|
51
51
  @color_scheme[item_type]
52
- }.reduce(0) { |count, (color, prefix)|
52
+ }.inject(0) { |count, (color, prefix)|
53
53
  count + @difference.scan("#{color}#{prefix}").size
54
54
  } == 0 : true
55
55
  end
@@ -101,7 +101,7 @@ module DiffMatcher
101
101
  right = diff(actual, expected)
102
102
  items_to_s(
103
103
  expected,
104
- (item_types_shown).reduce([]) { |a, method|
104
+ (item_types_shown).inject([]) { |a, method|
105
105
  a + send(method, left, right, expected.class).compact.map { |item| markup(method, item) }
106
106
  }
107
107
  )
@@ -112,11 +112,11 @@ module DiffMatcher
112
112
 
113
113
  def diff(expected, actual, reverse=false)
114
114
  if expected.is_a?(Hash)
115
- expected.keys.reduce({}) { |h, k|
115
+ expected.keys.inject({}) { |h, k|
116
116
  h.update(k => actual.has_key?(k) ? difference(actual[k], expected[k], reverse) : expected[k])
117
117
  }
118
118
  elsif expected.is_a?(Array)
119
- expected, actual = [expected, actual].map { |x| x.each_with_index.reduce({}) { |h, (v, i)| h.update(i=>v) } }
119
+ expected, actual = [expected, actual].map { |x| x.each_with_index.inject({}) { |h, (v, i)| h.update(i=>v) } }
120
120
  #diff(expected, actual, reverse) # XXX - is there a test case for this?
121
121
  diff(expected, actual)
122
122
  else
@@ -1,3 +1,3 @@
1
1
  module DiffMatcher
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,7 +1,5 @@
1
1
  require "spec_helper"
2
2
 
3
- RUBY_1_9 = (RUBY_VERSION =~ /^1\.9/)
4
-
5
3
  def opts_to_s(opts)
6
4
  opts_strs = opts.map { |k,v| ":#{k}=>#{v}" if v }.compact
7
5
  opts_strs.size > 0 ? ", " + opts_strs * ", " : ""
@@ -17,7 +15,8 @@ end
17
15
  describe DiffMatcher do
18
16
  subject { DiffMatcher::difference(expected, actual, opts) }
19
17
 
20
- shared_examples_for "a differ" do |expected, same, different, difference="", opts={}|
18
+ shared_examples_for "a differ" do |expected, same, different, difference, opts|
19
+ opts ||= {}
21
20
  context "with #{opts.size > 0 ? opts_to_s(opts) : "no opts"}" do
22
21
  describe "difference(#{expected.inspect}, #{same.inspect}#{opts_to_s(opts)})" do
23
22
  let(:expected) { expected }
@@ -50,7 +49,7 @@ describe DiffMatcher do
50
49
  2
51
50
 
52
51
  it_behaves_like "a differ", expected, same, different,
53
- <<-EOF
52
+ <<-EOF, {}
54
53
  - 1+ 2
55
54
  Where, - 1 missing, + 1 additional
56
55
  EOF
@@ -63,7 +62,7 @@ describe DiffMatcher do
63
62
  "b"
64
63
 
65
64
  it_behaves_like "a differ", expected, same, different,
66
- <<-EOF
65
+ <<-EOF, {}
67
66
  - "a"+ "b"
68
67
  Where, - 1 missing, + 1 additional
69
68
  EOF
@@ -72,7 +71,7 @@ describe DiffMatcher do
72
71
  different = 0
73
72
 
74
73
  it_behaves_like "a differ", expected, same, different,
75
- <<-EOF
74
+ <<-EOF, {}
76
75
  - "a"+ 0
77
76
  Where, - 1 missing, + 1 additional
78
77
  EOF
@@ -82,7 +81,7 @@ describe DiffMatcher do
82
81
  different = nil
83
82
 
84
83
  it_behaves_like "a differ", expected, same, different,
85
- <<-EOF
84
+ <<-EOF, {}
86
85
  - "a"+ nil
87
86
  Where, - 1 missing, + 1 additional
88
87
  EOF
@@ -96,7 +95,7 @@ describe DiffMatcher do
96
95
  false
97
96
 
98
97
  it_behaves_like "a differ", expected, same, different,
99
- <<-EOF
98
+ <<-EOF, {}
100
99
  - nil+ false
101
100
  Where, - 1 missing, + 1 additional
102
101
  EOF
@@ -109,7 +108,7 @@ describe DiffMatcher do
109
108
  [ 2 ]
110
109
 
111
110
  it_behaves_like "a differ", expected, same, different,
112
- <<-EOF
111
+ <<-EOF, {}
113
112
  [
114
113
  - 1+ 2
115
114
  ]
@@ -157,7 +156,7 @@ describe DiffMatcher do
157
156
  [ 1, 2 ]
158
157
 
159
158
  it_behaves_like "a differ", expected, same, different,
160
- <<-EOF
159
+ <<-EOF, {}
161
160
  [
162
161
  - 3
163
162
  ]
@@ -183,7 +182,7 @@ describe DiffMatcher do
183
182
  { "a"=>2 }
184
183
 
185
184
  it_behaves_like "a differ", expected, same, different,
186
- <<-EOF
185
+ <<-EOF, {}
187
186
  {
188
187
  "a"=>- 1+ 2
189
188
  }
@@ -197,7 +196,7 @@ describe DiffMatcher do
197
196
  { "a"=>[ "b", 1 ] }
198
197
 
199
198
  it_behaves_like "a differ", expected, same, different,
200
- <<-EOF
199
+ <<-EOF, {}
201
200
  {
202
201
  "a"=>- {"b"=>1}+ ["b", 1]
203
202
  }
@@ -213,7 +212,7 @@ describe DiffMatcher do
213
212
 
214
213
  describe "it won't match the descendents" do
215
214
  it_behaves_like "a differ", expected, same, different,
216
- <<-EOF
215
+ <<-EOF, {}
217
216
  {
218
217
  - "a"=>{"b"=>{"c"=>1}},
219
218
  + "b"=>{"c"=>1}
@@ -233,7 +232,7 @@ describe DiffMatcher do
233
232
  1
234
233
 
235
234
  it_behaves_like "a differ", expected, same, different,
236
- <<-EOF
235
+ <<-EOF, {}
237
236
  - String+ 1
238
237
  Where, - 1 missing, + 1 additional
239
238
  EOF
@@ -248,7 +247,7 @@ describe DiffMatcher do
248
247
  "A"
249
248
 
250
249
  it_behaves_like "a differ", expected, same, different,
251
- <<-EOF
250
+ <<-EOF, {}
252
251
  - /[a-z]/+ "A"
253
252
  Where, - 1 missing, + 1 additional
254
253
  EOF
@@ -257,7 +256,7 @@ describe DiffMatcher do
257
256
  different = :a
258
257
 
259
258
  it_behaves_like "a differ", expected, same, different,
260
- <<-EOF
259
+ <<-EOF, {}
261
260
  - /[a-z]/+ :a
262
261
  Where, - 1 missing, + 1 additional
263
262
  EOF
@@ -285,7 +284,7 @@ describe DiffMatcher do
285
284
 
286
285
  describe "it shows regex, class, proc matches and" do
287
286
  it_behaves_like "a differ", expected, same, different,
288
- <<-EOF
287
+ <<-EOF, {}
289
288
  [
290
289
  - 1+ 0,
291
290
  ~ (3),
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
- require 'simplecov'
2
- SimpleCov.start
1
+ RUBY_1_9 = (RUBY_VERSION =~ /^1\.9/)
2
+ if RUBY_1_9
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ end
3
6
  require "diff_matcher"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: diff_matcher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Playup
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-17 00:00:00 +10:00
13
+ date: 2011-09-21 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -32,6 +32,8 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
 
34
34
  files:
35
+ - .travis.yml
36
+ - CHANGELOG.md
35
37
  - Gemfile
36
38
  - License.txt
37
39
  - README.md
@@ -57,6 +59,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
59
  requirements:
58
60
  - - ">="
59
61
  - !ruby/object:Gem::Version
62
+ hash: 245833137
63
+ segments:
64
+ - 0
60
65
  version: "0"
61
66
  required_rubygems_version: !ruby/object:Gem::Requirement
62
67
  none: false