No commit activity in last 3 years
No release in over 3 years
Allows add errors messages for `bacon` custom matchers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
~> 12.3
~> 0.65.0
 Project Readme

Bacon::CustomMatchersMessages

Errors messages for bacon custom matchers.

Installation

Add this line to your application's Gemfile:

gem 'bacon-custom_matchers_messages'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bacon-custom_matchers_messages

Usage

require 'bacon/custom_matchers_messages'

## Old style, without message:

def shorter_than(max_size)
  ->(obj) { obj.size < max_size }
end

# Bacon::Error:


## Old style, with error message:

def shorter_than(max_size)
  lambda do |obj|
    obj.size < max_size ||
      "#{obj.inspect} doesn't shorter than #{max_size}"
  end
end

# Bacon::Error: "foo bar baz" doesn't shorter than 2


## New style, with generated error message:

custom_matcher :shorter_than do |obj, max_size|
  obj.size < max_size
end

# Bacon::Error: "foo bar baz" doesn't shorter than 2


## Old style, with custom arguments in message:

def include_words(*words)
  lambda do |obj|
    words.all? { |word| obj.split.include? word } ||
      "#{obj.inspect} doesn't include words" \
      " #{(words - obj.split).map!(&:inspect).join(',')}"
  end
end

# Bacon::Error: "foo bar baz" doesn't include words "hello"


## New style, with custom arguments for generated error message:

custom_matcher :include_words do |obj, *words|
  words.all? { |word| obj.split.include? word } ||
    (words - obj.split)
end

# Bacon::Error: "foo bar baz" doesn't include words "hello"

Development

After checking out the repo, run bundle to install dependencies. Then, run rake spec to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at AlexWayfer/bacon-custom_matchers_messages.

License

The gem is available as open source under the terms of the MIT License.