Skip to content

Instantly share code, notes, and snippets.

@paulsonkoly
Created March 16, 2020 20:56
Show Gist options
  • Save paulsonkoly/50e7777af8078599c38a2f99fdd10312 to your computer and use it in GitHub Desktop.
Save paulsonkoly/50e7777af8078599c38a2f99fdd10312 to your computer and use it in GitHub Desktop.
rspec
require 'rspec/autorun'
RSpec::Matchers.define :be_one_of do |expected|
match do |actual|
expected.include? actual
end
end
RSpec.describe 13 do
it 'is in the list of allowed values' do
expect([1,2,3]).to include 13
end
it 'is really in the list of allowed values' do
expect(13).to be_one_of [1,2,3]
end
end
# >> FF
# >>
# >> Failures:
# >>
# >> 1) 13 is in the list of allowed values
# >> Failure/Error: expect([1,2,3]).to include 13
# >> expected [1, 2, 3] to include 13
# >> # /tmp/seeing_is_believing_temp_dir20200316-2154923-1o5c992/program.rb:11:in `block (2 levels) in <main>'
# >>
# >> 2) 13 is really in the list of allowed values
# >> Failure/Error: expect(13).to be_one_of [1,2,3]
# >> expected 13 to be one of 1, 2, and 3
# >> # /tmp/seeing_is_believing_temp_dir20200316-2154923-1o5c992/program.rb:15:in `block (2 levels) in <main>'
# >>
# >> Finished in 0.02524 seconds (files took 0.21963 seconds to load)
# >> 2 examples, 2 failures
# >>
# >> Failed examples:
# >>
# >> rspec /tmp/seeing_is_believing_temp_dir20200316-2154923-1o5c992/program.rb:10 # 13 is in the list of allowed values
# >> rspec /tmp/seeing_is_believing_temp_dir20200316-2154923-1o5c992/program.rb:14 # 13 is really in the list of allowed values
# >>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment