Class: EqualUtf16Matcher
- Defined in:
- lib/extensions/mspec/mspec/matchers/equal_utf16.rb
Instance Method Summary collapse
- #expected_swapped ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected) ⇒ EqualUtf16Matcher
constructor
A new instance of EqualUtf16Matcher.
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected) ⇒ EqualUtf16Matcher
Returns a new instance of EqualUtf16Matcher.
4 5 6 |
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 4 def initialize(expected) @expected = Array(expected).map { |x| encode x, "binary" } end |
Instance Method Details
#expected_swapped ⇒ Object
13 14 15 |
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 13 def expected_swapped @expected_swapped ||= @expected.map { |x| x.to_str.gsub(/(.)(.)/, '\2\1') } end |
#failure_message ⇒ Object
17 18 19 20 |
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 17 def ["Expected #{@actual.pretty_inspect}", "to equal #{@expected.pretty_inspect} or #{expected_swapped.pretty_inspect}"] end |
#matches?(actual) ⇒ Boolean
8 9 10 11 |
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 8 def matches?(actual) @actual = Array(actual).map { |x| encode x, "binary" } @actual == @expected || @actual == expected_swapped end |
#negative_failure_message ⇒ Object
22 23 24 25 |
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 22 def ["Expected #{@actual.pretty_inspect}", "not to equal #{@expected.pretty_inspect} nor #{expected_swapped.pretty_inspect}"] end |