diff_matcher 2.2.2 → 2.2.3

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.
@@ -90,19 +90,34 @@ module DiffMatcher
90
90
  :match_proc => [CYAN , "{"]
91
91
  }
92
92
 
93
- COLOR_SCHEMES = {
94
- :default => DEFAULT_COLOR_SCHEME,
95
- :white_background => DEFAULT_COLOR_SCHEME.merge(
96
- :additional => [MAGENTA, "+"]
97
- )
98
- }
93
+ class << self
94
+ attr_reader :color_scheme
95
+ attr_writer :color_enabled, :color_schemes
96
+
97
+ def color_schemes
98
+ @color_schemes ||= {
99
+ :default => DEFAULT_COLOR_SCHEME,
100
+ :white_background => DEFAULT_COLOR_SCHEME.merge(
101
+ :additional => [MAGENTA, "+"]
102
+ )
103
+ }
104
+ end
105
+
106
+ def color_scheme=(value)
107
+ @color_scheme = color_schemes[value]
108
+ end
109
+
110
+ def color_enabled
111
+ @color_enabled.nil? ? !!@color_scheme : @color_enabled
112
+ end
113
+ end
99
114
 
100
115
  def initialize(expected, actual, opts={})
101
116
  @opts = opts
102
117
  @ignore_additional = opts[:ignore_additional]
103
118
  @quiet = opts[:quiet]
104
- @color_enabled = opts[:color_enabled] || !!opts[:color_scheme]
105
- @color_scheme = COLOR_SCHEMES[opts[:color_scheme] || :default]
119
+ @color_scheme = self.class.color_schemes[opts[:color_scheme]] || self.class.color_scheme || self.class.color_schemes[:default]
120
+ @color_enabled = (opts[:color_enabled].nil? && opts[:color_scheme].nil?) ? self.class.color_enabled : !!opts[:color_scheme] || opts[:color_enabled]
106
121
  @optional_keys = opts.delete(:optional_keys) || []
107
122
  @dif_count = 0
108
123
  @difference = difference(expected, actual)
@@ -1,3 +1,3 @@
1
1
  module DiffMatcher
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
@@ -668,6 +668,40 @@ describe "DiffMatcher::difference(expected, actual, opts)" do
668
668
  Where, \e[31m- \e[1m1 missing\e[0m, \e[35m+ \e[1m1 additional\e[0m, \e[32m~ \e[1m1 match_regexp\e[0m, \e[34m: \e[1m1 match_class\e[0m, \e[36m. \e[1m1 match_range\e[0m, \e[36m{ \e[1m1 match_proc\e[0m
669
669
  EOF
670
670
  end
671
+
672
+ context "color_enabled can be set on the class" do
673
+ before { DiffMatcher::Difference::color_enabled = true }
674
+
675
+ it_behaves_like "a diff matcher", expected, same, different,
676
+ <<-EOF
677
+ \e[0m[
678
+ \e[0m \e[31m- \e[1m1\e[0m\e[33m+ \e[1m0\e[0m,
679
+ \e[0m 2,
680
+ \e[0m \e[32m~ \e[0m"\e[32m(\e[1m3\e[0m\e[32m)\e[0m"\e[0m,
681
+ \e[0m \e[34m: \e[1m4\e[0m,
682
+ \e[0m \e[36m. \e[1m5\e[0m,
683
+ \e[0m \e[36m{ \e[1m6\e[0m
684
+ \e[0m]
685
+ Where, \e[31m- \e[1m1 missing\e[0m, \e[33m+ \e[1m1 additional\e[0m, \e[32m~ \e[1m1 match_regexp\e[0m, \e[34m: \e[1m1 match_class\e[0m, \e[36m. \e[1m1 match_range\e[0m, \e[36m{ \e[1m1 match_proc\e[0m
686
+ EOF
687
+ end
688
+
689
+ context "color_scheme can be set on the class" do
690
+ before { DiffMatcher::Difference::color_scheme = :white_background }
691
+
692
+ it_behaves_like "a diff matcher", expected, same, different,
693
+ <<-EOF
694
+ \e[0m[
695
+ \e[0m \e[31m- \e[1m1\e[0m\e[35m+ \e[1m0\e[0m,
696
+ \e[0m 2,
697
+ \e[0m \e[32m~ \e[0m"\e[32m(\e[1m3\e[0m\e[32m)\e[0m"\e[0m,
698
+ \e[0m \e[34m: \e[1m4\e[0m,
699
+ \e[0m \e[36m. \e[1m5\e[0m,
700
+ \e[0m \e[36m{ \e[1m6\e[0m
701
+ \e[0m]
702
+ Where, \e[31m- \e[1m1 missing\e[0m, \e[35m+ \e[1m1 additional\e[0m, \e[32m~ \e[1m1 match_regexp\e[0m, \e[34m: \e[1m1 match_class\e[0m, \e[36m. \e[1m1 match_range\e[0m, \e[36m{ \e[1m1 match_proc\e[0m
703
+ EOF
704
+ end
671
705
  end
672
706
  end
673
707
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: diff_matcher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.2.2
5
+ version: 2.2.3
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: 2012-06-14 00:00:00 Z
13
+ date: 2012-07-08 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: |
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- hash: -2103074240095197051
63
+ hash: 2610392382067707608
64
64
  segments:
65
65
  - 0
66
66
  version: "0"