Skip to content

Instantly share code, notes, and snippets.

@ukstudio
Last active August 29, 2015 14: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 ukstudio/1b0694b3fa8eafe0f4b3 to your computer and use it in GitHub Desktop.
Save ukstudio/1b0694b3fa8eafe0f4b3 to your computer and use it in GitHub Desktop.
power assert in rspec
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