Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. require 'rspec/expectations'
  2.  
  3. RSpec::Matchers.define :include_one do |expected|
  4.   function_passed = expected.is_a?(Proc)
  5.  
  6.   match do |actual|
  7.     if function_passed
  8.       actual.select {|el| expected.call(el) }.size == 1
  9.     else
  10.       actual.select {|el| el.eql?(expected) }.size == 1
  11.     end
  12.   end
  13.  
  14.   failure_message do |actual|
  15.     "expected #{actual.inspect} to have only one #{expected}"
  16.   end
  17. end
  18.  
  19. RSpec::Matchers.alias_matcher :include_exactly_one, :include_one
  20. RSpec::Matchers.alias_matcher :contain_one, :include_one
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top