Last active
July 9, 2018 03:06
-
-
Save JoshCheek/2dd8b504f990e8c3e65aa28740c954d6 to your computer and use it in GitHub Desktop.
Bringing back the oldschool RSpec style.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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