Skip to content

@txus /Readme.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
codebrawl entry - ruby testing libraries

a

a is a testing framework written in 6 lines of code (or 472 characters) which tries to be performant, with eye-catchy reports and easy to use.

Heavily inspired by Konstantin Haase's almost-sinatra, its long-term purpose is to become the fastest testing framework available.

The idea is to stay under 7 lines with less than 80 chars per line. There is room for optimization!

Features

  • Setup / Teardown
  • Assertions (using the a method)
  • Report tests/assertions/failures
  • Keep track of lines where failures happened

Usage

Just clone this gist and run:

ruby example.rb

And voilà:

a

Copyright

Copyright (c) 2011 Josep M. Bach. Released under the MIT license.

$n=Time.now;$f=[];$c=[];$a=0;class A;def a c;$a+=1;print c ?"\e[32m.\e[0m":($f\
<<caller[0];"\e[31mF\e[0m");end;def self.inherited(b);$c<<b;end;end;at_exit{$c\
.map{|t|i=t.new;i.setup rescue nil;$t=t.instance_methods(false).map{|m|i.send\
m if !%w(setup teardown).include? m};i.teardown rescue nil};print "\n#{Time.\
now-$n} s.\n#{$t.size} tests, #{$a} assertions, #{$f.size} failures\n\n"+$f.\
map{|f|"\e[31mFailure\e[0m \e[97m@\e[33m #{f}"}.join("\n");exit -1 if $f[0]}
require 'a'
class MyTestCase < A
def setup
@user = { :some => :object }
end
def test_user_has_property
a @user[:some] == :object
a !@user[:other]
end
def test_user_not_nil
a !@user.nil?
end
end
class MyOtherTestCase < A
def setup
@foo = [1,2,3]
end
def test_user_has_property
a @foo.length == 3
a @foo[2] > 934 # Should fail at line 27
@foo[1] = 99
a @foo[1] != 2
end
def teardown
@user = nil
end
end
@masylum

That's a win!

@jamesu

Looks great! :)

@bltavares

Shouldn't the $t be an array? Like it https://gist.github.com/1088066

@txus
Owner

thanks, you're totally right! if you want you can do a pull request in the 'a' repo? (http://github.com/txus/a)

@bltavares

Sure . I've sent it already (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.