Freeman
A simple (experimental) test gem for Ruby.
Installation
Add this line to your application's Gemfile:
gem 'freeman'
And then execute:
$ bundle
Or install it yourself as:
$ gem install freeman
Usage
require "freeman"
require "./core_exts"
test "A string is indeed a string" do
'This is a string'.class.is String
end
test "Numbers can be divisible by" do
10.divisible_by(5).is true
end
# Example of a failing test
test "True is false" do
true.is false
end
# Example of the 'isnt' on the same test
test "True isn't false" do
true.isnt false
end
# ./core_exts.rb
class Fixnum
def divisible_by(num)
self % num == 0
end
end
Returns:
A string is indeed a string: true
Numbers can be divisible by: true
True is false: false
from test.rb: 12
True isn't false: true
Tests return true or false, and can be assigned to variables:
please_work = test "it's true!" do
true.is true
end
puts "YAY" if please_work
Misc
I've been reading Metaprogramming Ruby and thought it'd be fun to try this. Turns out it only took a couple minutes to write, and it's fast, to boot! Normally I would just drop the single library file into a project to avoid running through Bundler as a dependency, but it only adds .1ms to my run-time as a gem. I can live with that.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Run
rake
to make sure (simple) tests still pass - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request