Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active July 9, 2018 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/2dd8b504f990e8c3e65aa28740c954d6 to your computer and use it in GitHub Desktop.
Save JoshCheek/2dd8b504f990e8c3e65aa28740c954d6 to your computer and use it in GitHub Desktop.
Bringing back the oldschool RSpec style.
module MahAssertions
refine BasicObject do
def is(val)
return true if self == val
::Kernel.raise RSpec::Expectations::ExpectationNotMetError, "#{inspect} is not #{val.inspect}", caller
end
end
end
require 'rspec/autorun'
class << RSpec
alias old_describe describe
def describe(*args, &block)
block.binding.eval 'using MahAssertions'
old_describe(*args, &block)
end
end
RSpec.describe 'something' do
it('passes') { 1.is 1 }
it('fails') { 1.is 2 }
end
# >> .F
# >>
# >> Failures:
# >>
# >> 1) something fails
# >> Failure/Error: it('fails') { 1.is 2 }
# >> 1 is not 2
# >> # program.rb:21:in `block (2 levels) in <main>'
# >>
# >> Finished in 0.0032 seconds (files took 0.11636 seconds to load)
# >> 2 examples, 1 failure
# >>
# >> Failed examples:
# >>
# >> rspec program.rb:21 # something fails
# >>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment