From 681f81799274777dd07d680b7210b877255f9386 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Tue, 23 Feb 2016 22:18:16 +0100 Subject: [PATCH 1/2] enable cmp matcher to catch the case where expected is a number string, and actual is a number --- lib/matchers/matchers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matchers/matchers.rb b/lib/matchers/matchers.rb index b9caa264d..59ec020a4 100644 --- a/lib/matchers/matchers.rb +++ b/lib/matchers/matchers.rb @@ -248,6 +248,8 @@ RSpec::Matchers.define :cmp do |expected| # if actual and expected are strings if expected.is_a?(String) && actual.is_a?(String) actual.casecmp(expected) == 0 + elsif expected.is_a?(String) && integer?(expected) && actual.is_a?(Integer) + expected.to_i == actual elsif expected.is_a?(Integer) && integer?(actual) expected == actual.to_i elsif expected.is_a?(Float) && float?(actual) From 2fc0994f4cccb190e9f87d4f05f0bbfbcc1d7cc4 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Tue, 23 Feb 2016 22:31:10 +0100 Subject: [PATCH 2/2] add cmp int->string tests --- .../test/integration/default/compare_matcher_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/integration/test/integration/default/compare_matcher_spec.rb b/test/integration/test/integration/default/compare_matcher_spec.rb index 178345fca..f215de203 100644 --- a/test/integration/test/integration/default/compare_matcher_spec.rb +++ b/test/integration/test/integration/default/compare_matcher_spec.rb @@ -29,4 +29,9 @@ if os.linux? it { should include 'root' } it { should_not cmp 'root' } end + + len = passwd.passwords.length + describe len do + it { should cmp len.to_s } + end end