inline_testing

I’ve begun work on a new testing library called inline_testing, which allows yo to use your comments as tests! The gem is very young and barely works but I will be making a ton of progress on it in the coming weeks.

Example:

require 'inline_testing'
InlineTesting.init(__FILE__)

class User
  attr_accessor :name, :email
  def initialize(name, email)
    @name, @email = name, email
  end
end

InlineTesting.start(__LINE__)

 my_user = User.new("Ryan", "c00lryguy@gmail.com")
# some ignored comment
my_user.name # => "Ryan"
my_user.email # => "c00lryguy@gmail.com"

InlineTesting.stop(__LINE__)
InlineTesting.test(binding)

Don’t get it? Well these lines:

my_user.name # => "Ryan"
my_user.email # => "c00lryguy@gmail.com"

…are actually tests! we’re checking to see if my_user.name == "Ryan".

What it does is when you call InlineTesting.start(__LINE__), You’re telling my gem which line the tests are going to start, same with InlineTesting.stop(__LINE__). Then when you call InlineTesting.test(binding), my gem will process these lines and look for comments like # => which tells the gem what you expect the output of the line to be.

Like it said, it’s very immature but a ton of features are planned.

Gem

GitHub

  1. ilovemetaprogramming posted this