Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rspec/expectations'
- RSpec::Matchers.define :include_one do |expected|
- function_passed = expected.is_a?(Proc)
- match do |actual|
- if function_passed
- actual.select {|el| expected.call(el) }.size == 1
- else
- actual.select {|el| el.eql?(expected) }.size == 1
- end
- end
- failure_message do |actual|
- "expected #{actual.inspect} to have only one #{expected}"
- end
- end
- RSpec::Matchers.alias_matcher :include_exactly_one, :include_one
- RSpec::Matchers.alias_matcher :contain_one, :include_one
Add Comment
Please, Sign In to add comment