diff_matcher 2.3.1 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ coverage
2
+ pkg
3
+ Gemfile.lock
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ### v2.3.3
4
+
5
+ Allow HTML output using `:html_output=>true` option
6
+
7
+ ### v2.3.2
8
+
9
+ Summarize `Hash` and `Array` output in diff with `"..."`
10
+ ```
11
+ eg.
12
+ - [...]+ {...}
13
+ ```
14
+
15
+ ### v2.2.3
16
+
17
+ * set color_enabled/color_scheme on the class
18
+
19
+ (ie. so it can be used by default)
20
+
21
+ ### v2.2.2
22
+
23
+ * BUGFIX for `AllMatcher`
24
+
25
+ - return a diff instead of raising an exception
26
+ - (raising an exception was a bad idea as it blew up the entire match
27
+ when used in conjuction with an or-matcher, or embedded into other
28
+ matchers)
29
+
30
+ ### v2.2.1
31
+
32
+ * AllMatcher also accepts a size (`Fixnum` or `Range`)
33
+
34
+ ### v2.2.0
35
+
36
+ * Added Matcher and AllMatcher
37
+ - Matcher returns the *closest* diff.
38
+ * Added `:min`, `:max` args to `AllMatcher` and `:optional_keys` to `Matcher`
39
+ * Added range matcher
40
+
41
+ ### v2.0.0
42
+
43
+ * Remove `:verbose` option
44
+
45
+ More often than not users want this as the default.
46
+
3
47
  ### v1.0.1
4
48
 
5
49
  * BUGFIX for ruby 1.8.7
data/README.md CHANGED
@@ -214,6 +214,16 @@ puts DiffMatcher::difference([Fixnum, 2], [1], :quiet=>true)
214
214
  # => Where, - 1 missing
215
215
  ```
216
216
 
217
+ `:html_output=>true` will convert ansii escape codes to html spans
218
+
219
+ ``` ruby
220
+ puts DiffMatcher::difference(1, 2, :html_output=>true)
221
+ <pre>
222
+ <span style="color:red">- <b>1</b></span><span style="color:yellow">+ <b>2</b></span>
223
+ Where, <span style="color:red">- <b>1 missing</b></span>, <span style="color:yellow">+ <b>1 additional</b></span>
224
+ </pre>
225
+ ```
226
+
217
227
  #### Prefixes
218
228
 
219
229
  The items shown in a difference are prefixed as follows:
@@ -1,3 +1,5 @@
1
+ require 'diff_matcher/escape_to_html'
2
+
1
3
  module DiffMatcher
2
4
 
3
5
  def self.difference(expected, actual, opts={})
@@ -121,6 +123,8 @@ module DiffMatcher
121
123
  @optional_keys = opts.delete(:optional_keys) || []
122
124
  @dif_count = 0
123
125
  @difference = difference(expected, actual)
126
+ @html_output = opts[:html_output]
127
+ @color_enabled = true if @html_output
124
128
  end
125
129
 
126
130
  def matching?
@@ -144,7 +148,8 @@ module DiffMatcher
144
148
  }.compact.join(", ")
145
149
  msg << "\nWhere, #{where}" if where.size > 0
146
150
 
147
- @color_enabled ? msg : msg.gsub(/\e\[\d+m/, "")
151
+ msg.gsub!(/\e\[\d+m/, "") unless @color_enabled
152
+ @html_output ? "<pre>\n#{escape_to_html(msg)}\n</pre>" : msg
148
153
  end
149
154
  end
150
155
 
@@ -0,0 +1,32 @@
1
+ # from http://stackoverflow.com/questions/4894434/ansi-escape-code-with-html-tags-in-ruby
2
+ def escape_to_html(data)
3
+ { 1 => :nothing,
4
+ 2 => :nothing,
5
+ 4 => :nothing,
6
+ 5 => :nothing,
7
+ 7 => :nothing,
8
+ 30 => :black,
9
+ 31 => :red,
10
+ 32 => :green,
11
+ 33 => :yellow,
12
+ 34 => :blue,
13
+ 35 => :magenta,
14
+ 36 => :cyan,
15
+ 37 => :white,
16
+ 40 => :nothing,
17
+ 41 => :nothing,
18
+ 43 => :nothing,
19
+ 44 => :nothing,
20
+ 45 => :nothing,
21
+ 46 => :nothing,
22
+ 47 => :nothing,
23
+ }.each do |key, value|
24
+ if value != :nothing
25
+ data.gsub!(/\e\[#{key}m/,"<span style=\"color:#{value}\">")
26
+ else
27
+ data.gsub!(/\e\[#{key}m/,"<b>")
28
+ end
29
+ end
30
+ data.gsub!(/^\e\[0m/,'')
31
+ data.gsub!(/\e\[0m/,'</b></span>')
32
+ end
@@ -1,3 +1,3 @@
1
1
  module DiffMatcher
2
- VERSION = "2.3.1"
2
+ VERSION = "2.3.3"
3
3
  end
@@ -750,5 +750,22 @@ describe "DiffMatcher::difference(expected, actual, opts)" do
750
750
  EOF
751
751
  end
752
752
  end
753
+
754
+ describe "it shows matches in html" do
755
+ it_behaves_like "a diff matcher", expected, same, different,
756
+ <<-EOF , :color_scheme => :white_background, :html_output=>true
757
+ <pre>
758
+ [
759
+ <span style=\"color:red\">- <b>1</b></span><span style=\"color:magenta\">+ <b>0</b></span>,
760
+ 2,
761
+ <span style=\"color:green\">~ </b></span>\"<span style=\"color:green\">(<b>3</b></span><span style=\"color:green\">)</b></span>\"</b></span>,
762
+ <span style=\"color:blue\">: <b>4</b></span>,
763
+ <span style=\"color:cyan\">. <b>5</b></span>,
764
+ <span style=\"color:cyan\">{ <b>6</b></span>
765
+ ]
766
+ Where, <span style=\"color:red\">- <b>1 missing</b></span>, <span style=\"color:magenta\">+ <b>1 additional</b></span>, <span style=\"color:green\">~ <b>1 match_regexp</b></span>, <span style=\"color:blue\">: <b>1 match_class</b></span>, <span style=\"color:cyan\">. <b>1 match_range</b></span>, <span style=\"color:cyan\">{ <b>1 match_proc</b></span>
767
+ </pre>
768
+ EOF
769
+ end
753
770
  end
754
771
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.3
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: 2012-08-02 00:00:00.000000000 +10:00
12
+ date: 2012-08-03 00:00:00.000000000 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: ! "DiffMatcher performs recursive matches on values contained in hashes,
@@ -22,11 +22,11 @@ executables: []
22
22
  extensions: []
23
23
  extra_rdoc_files: []
24
24
  files:
25
+ - .gitignore
25
26
  - .rspec
26
27
  - .travis.yml
27
28
  - CHANGELOG.md
28
29
  - Gemfile
29
- - Gemfile.lock
30
30
  - License.txt
31
31
  - README.md
32
32
  - Rakefile
@@ -34,9 +34,9 @@ files:
34
34
  - diff_matcher.gemspec
35
35
  - doc/diff_matcher.gif
36
36
  - doc/example_output.png
37
- - examples/tennis_score.rb
38
37
  - lib/diff_matcher.rb
39
38
  - lib/diff_matcher/difference.rb
39
+ - lib/diff_matcher/escape_to_html.rb
40
40
  - lib/diff_matcher/version.rb
41
41
  - spec/diff_matcher/difference_spec.rb
42
42
  - spec/spec_helper.rb
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  segments:
57
57
  - 0
58
- hash: -173866385
58
+ hash: 1047575201
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  none: false
61
61
  requirements:
@@ -1,26 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.3)
5
- multi_json (1.0.4)
6
- rake (0.9.2.2)
7
- rspec (2.6.0)
8
- rspec-core (~> 2.6.0)
9
- rspec-expectations (~> 2.6.0)
10
- rspec-mocks (~> 2.6.0)
11
- rspec-core (2.6.4)
12
- rspec-expectations (2.6.0)
13
- diff-lcs (~> 1.1.2)
14
- rspec-mocks (2.6.0)
15
- simplecov (0.5.4)
16
- multi_json (~> 1.0.3)
17
- simplecov-html (~> 0.5.3)
18
- simplecov-html (0.5.3)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- rake (~> 0.9)
25
- rspec (~> 2.6.0)
26
- simplecov
@@ -1,15 +0,0 @@
1
- require 'diff_matcher'
2
-
3
- set_scores = [
4
- [[6,4], [6,4], [6,4]],
5
- [[8,4], [6,9], [6,4]],
6
- ]
7
-
8
- pat_set_scores = DiffMatcher::AllMatcher.new(
9
- [0..6, 0..6],
10
- :size => 2..3
11
- )
12
-
13
- invalid_scores = set_scores.map { |score| pat_set_scores.diff(score) }.compact
14
-
15
- puts invalid_scores