No release in over a year
"ruby/power_assert" integration for RSpec. No monkey patching exists.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 1.4.0, < 2.0
>= 2.0.3, < 4.0
>= 3.13.0, < 4.0
 Project Readme

rspec-matchers-power_assert_matchers

Build Status Gem Version

Overview

screenshot1 screenshot2

ruby/power_assert integration for RSpec.

No monkey patching exists.
Just using RSpec's Custom matchers way.
I hope this might be a choice to integrate PowerAssert in RSpec.

Usage

Require following dependencies

See gemspec for detail of the version restriction.

Add below code into your library's gemspec

Gem::Specification.new do |gem|
  gem.add_development_dependency 'rspec-matchers-power_assert_matchers', '~> 0.4.0'
end

Or add below into your application's Gemfile

group :test do
  gem 'rspec-matchers-power_assert_matchers', '~> 0.4.0'
end

So adding this into your spec_helper.rb or rails_helper.rb

require 'rspec/matchers/power_assert_matchers'

Then you can use power_assert with a simple custom matcher in rspec.

Use expect with block, and use be_assert matcher.

RSpec.describe RSpec::Matchers::PowerAssertMatchers do
  context 'when the given block returns falsy' do
    it 'shows power_assert inspection' do
      expect {
        '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
      }.to be_assert
    end
  end
end
  1) RSpec::Matchers::PowerAssertMatchers when the given block returns falsy shows power_assert inspection
     Failure/Error:
       expect {
         '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
       }.to be_assert

               '0'.class == '3'.to_i.times.map {|i| i + 1 }.class
                   |     |      |    |     |                |
                   |     |      |    |     |                Array
                   |     |      |    |     [1, 2, 3]
                   |     |      |    #<Enumerator: ...>
                   |     |      3
                   |     false
                   String
    # ./examples/spec/example_spec.rb:6:in `block (3 levels) in <top (required)>'

If you want to easy to check the behavior, this repository has example specs.

$ git clone git@github.com:kachick/rspec-matchers-power_assert_matchers.git
$ cd rspec-matchers-power_assert_matchers
$ bundle install
$ bundle exec rake look_at_examples
Rough examples will be shown!
$ bundle exec rake run_examples
Some results will be shown!

NOTE

  • Currently the matcher is named be_assert. I don't have confident it is good or not.
  • Extending built-in be_truthy sounds good for considering the role, but I would not like to add monkey patching for built-in features...

References