Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Introspective Block Assertions

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 tasks
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 COPYING
Octocat-spinner-32 COPYING.LESSER
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 iba.gemspec
Octocat-spinner-32 iba.watchr
README.rdoc

Iba

by Matijs van Zuijlen

Description

Introspective Block Assertions

Features/Problems

  • Write assertions as a (one-expression) block

  • Assertion message deconstructs the block's expression.

  • Not done yet.

Synopsis

# In your test helper:
require 'iba'
class Test::Unit::TestCase
  include Iba::BlockAssertion
end

# In your test:
foo = 24
assert { foo == 23 } # => "(foo == 23) is false
                     #     foo is 24."

Details

Iba provides an assert method that takes a block. If the block returns false, it will try to construct an insightful error message based on the contents of the block.

Iba's functionality is inspired by Wrong[1], but doesn't use an external Ruby parser. This means it will work in contexts where Wrong does not (generated code, on the command line). It also means there are more limits to the contents of the block.

Current limits:

  • Only single-expression blocks are supported.

  • The expression must start with a method-like identifier or an instance variable (like 'foo' or '@foo', but not 'Foo' or '23'). In practice, this produces quite natural results.

  • Local and instance variables whose names start with an underscore should not be used inside the block.

Iba's implementation is inspired by Arlo[2], a generic combinator library for Python.

Install

gem install iba

Links

1

github.com/sconover/wrong

2

withoutane.com/rants/2008/12/arlo-generic-combinators-for-python

Licence

See the LICENSE file.

Something went wrong with that request. Please try again.