Last active
August 29, 2015 14:06
-
-
Save ukstudio/1b0694b3fa8eafe0f4b3 to your computer and use it in GitHub Desktop.
power assert in rspec
This file contains hidden or 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
require 'power_assert' | |
module RSpec | |
module PowerAssert | |
def power_assert(&block) | |
::PowerAssert.start(block) do |pa| | |
ret = pa.yield | |
unless ret | |
raise RSpec::Expectations::ExpectationNotMetError, "\nPowerAssert:\n#{pa.message_proc.call}" | |
end | |
end | |
end | |
end | |
end | |
class RSpec::Core::ExampleGroup | |
include RSpec::PowerAssert | |
end | |
describe 'test' do | |
it 'test' do | |
power_assert { | |
[1,2,3,4].include?(1) == false | |
} | |
end | |
end | |
#Failures: | |
# | |
# 1) test test | |
# Failure/Error: raise RSpec::Expectations::ExpectationNotMetError, "\nPowerAssert:\n#{pa.message_proc.call}" | |
# | |
# PowerAssert: | |
# [1,2,3,4].include?(1) == false | |
# | | |
# true | |
# # ./test.rb:9:in `block in power_assert' | |
# # ./test.rb:6:in `power_assert' | |
# # ./test.rb:24:in `block (2 levels) in <top (required)>' | |
# | |
#Finished in 0.00101 seconds (files took 0.13324 seconds to load) | |
#1 example, 1 failure | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment