Skip to content

Instantly share code, notes, and snippets.

@oreshinya
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save oreshinya/ce930c38d0221e5ea021 to your computer and use it in GitHub Desktop.

Select an option

Save oreshinya/ce930c38d0221e5ea021 to your computer and use it in GitHub Desktop.
power_assert extension for rspec sample.
require 'rspec/core'
require 'power_assert'
module PowerAssertExtension
def power_assert(&block)
::PowerAssert.start(block, assertion_method: __method__) do |pa|
return if pa.yield
message = "\n#{pa.message_proc.call}"
raise RSpec::Expectations::ExpectationNotMetError.new(message)
end
end
end
class RSpec::Core::ExampleGroup
include PowerAssertExtension
end
@oreshinya
Copy link
Author

Usage:

it do
  power_assert do
    @hoge == 1
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment