README.md in rspec-block_is_expected-1.0.2 vs README.md in rspec-block_is_expected-1.0.3

- old
+ new

@@ -18,20 +18,20 @@ | test coverage | [![Test Coverage](https://api.codeclimate.com/v1/badges/ca0a12604ecc19f5e76d/test_coverage)](https://codeclimate.com/github/pboling/rspec-block_is_expected/test_coverage) | | maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/ca0a12604ecc19f5e76d/maintainability)](https://codeclimate.com/github/pboling/rspec-block_is_expected/maintainability) | | code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/rspec-block_is_expected/badges/users.svg)](https://www.codetriage.com/pboling/rspec-block_is_expected) | | homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] | | documentation | [on RDoc.info][documentation] | -| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏][peterboling], [🍚][refugees], [➕][gplus], [👼][angellist], [🐛][topcoder], [:shipit:][coderwall], [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)][twitter] | +| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌏](https://about.me/peter.boling), [👼](https://angel.co/peter-boling), [:shipit:](http://coderwall.com/pboling), [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)](http://twitter.com/galtzo)| If you only ever want to test subjects wrapped in blocks, and are comfortable with **losing** the standard `is_expected` behavior, see an alternative to this gem [here](https://github.com/christopheraue/ruby-rspec-is_expected_block/). ## Installation Add this line to your application's Gemfile: ```ruby -gem 'rspec-block_is_expected', group: :test +gem 'rspec-block_is_expected', :group => :test ``` And then execute: $ bundle @@ -47,10 +47,70 @@ Otherwise, you may load it manually near the top of your `spec_helper.rb`, and it will self configure. ```ruby require 'rspec/block_is_expected' ``` +### RSpec Matchers + +`block_is_expected` can be used to chain expectations related to the block, +but `to_not` doesn't work with multiple expectations. +So negated matchers are required. A basic set of them are included with this gem, and can be loaded with: + +```ruby +require 'rspec/block_is_expected/matchers/not' +``` + +This gives you the following matchers: +```ruby +RSpec::Matchers.define_negated_matcher :not_change, :change +RSpec::Matchers.define_negated_matcher :not_include, :include +RSpec::Matchers.define_negated_matcher :not_eq, :eq +RSpec::Matchers.define_negated_matcher :not_raise_error, :raise_error +``` + +#### Example + +You have a module like this: + +```ruby +module MyTasks + module_function def my_rakelib + Rake.add_rakelib('bananas') + end +end +``` + +You have a spec like this: + +```ruby +require 'rake' + +RSpec.describe(MyTasks) do + describe 'my_rakelib' do + subject(:my_rakelib) { described_class.my_rakelib } + it 'updates rakelib' do + block_is_expected.to not_raise_error & + change { Rake.application.options.rakelib }.from(['rakelib']).to(%w[rakelib bananas]) + end + end +end +``` + +### Integration with RuboCop + +You'll likely get the following linting error from `rubocop-rspec` if you use `block_is_expected.to ...`: +``` +RSpec/NoExpectationExample: No expectation found in this example. +``` + +To fix it properly you need to register `block_is_expected` as an "expectation". In your `.rubocop.yml` + +```yml +inherit_gem: + rspec-block_is_expected: rspec/block_is_expected/rubocop.yml +``` + ## Usage The spec suite for this gem has some examples of usage, lightly edited here. ```ruby @@ -135,10 +195,10 @@ spec.add_development_dependency 'rspec-block_is_expected', '~> 1.0' ## Legal -* MIT License - See [LICENSE][license] file in this project [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) +* MIT License - See [LICENSE][license] file in this project [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) * Copyright (c) 2018 [Peter H. Boling][peterboling] of [Rails Bling][railsbling] [semver]: http://semver.org/ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint