Skip to content

Commit

Permalink
Merge pull request #991 from jeremymv2/cmp_treat_0_as_integer
Browse files Browse the repository at this point in the history
cmp not treating 0 as integer only as string
  • Loading branch information
chris-rock committed Aug 30, 2016
2 parents efec631 + 3822b8e commit 4673dfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/matchers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
RSpec::Matchers.define :cmp do |first_expected|

def integer?(value)
!(value =~ /\A[1-9]\d*\Z/).nil?
!(value =~ /\A0+\Z|\A[1-9]\d*\Z/).nil?
end

def float?(value)
Expand Down
10 changes: 10 additions & 0 deletions test/integration/default/cmp_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,14 @@
it { should cmp 'False' }
it { should cmp false }
end

describe 0 do
it { should cmp 0 }
it { should cmp 00 }
it { should cmp '0' }
it { should cmp '00' }
it { should_not cmp 1 }
it { should_not cmp '01' }
end

end

0 comments on commit 4673dfd

Please sign in to comment.