github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ahoward / testy

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 109
    • 3
  • Source
  • Commits
  • Network (3)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

a BDD testing framework for ruby that's mad at the world and plans to kick it's ass in 78 freakin lines of code — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Deal with more "it's". 
agrimm (author)
Wed Apr 29 18:59:34 -0700 2009
commit  c58ed72d2de00ea33fc5605bd574c3605b42ca39
tree    a607b8c6792e177aa7d7fe324037f301016e36f5
parent  b8e91fc2b60577b6b57d70b107855715695d0d98
testy /
name age
history
message
file README Wed Apr 29 18:58:36 -0700 2009 Replace "it's" with its. It's is not a genitive. [agrimm]
file README.tmpl Wed Apr 29 18:59:34 -0700 2009 Deal with more "it's". [agrimm]
file TODO Sun Mar 29 21:02:13 -0700 2009 adding contexts, setup, and teardown plus updat... [ahoward]
file gemspec.rb Sat Mar 28 16:03:41 -0700 2009 add orderedhash dep to gemspec [ahoward]
file gen_readme.rb Sat Mar 28 15:28:18 -0700 2009 import [ahoward]
directory lib/ Sun Mar 29 21:02:13 -0700 2009 adding contexts, setup, and teardown plus updat... [ahoward]
directory samples/ Sun Mar 29 21:02:13 -0700 2009 adding contexts, setup, and teardown plus updat... [ahoward]
file testy-0.5.0.gem Sun Mar 29 21:02:13 -0700 2009 adding contexts, setup, and teardown plus updat... [ahoward]
README
NAME
  testy.rb

DESCRIPTION
  a minimalist BDD testing framework for ruby that's mad at the world and
  plans to kick its ass by ruthlessly removing lines of testing framework
  code

SYNOPSIS
  Testy.testing 'your code' do
    test 'some behaviour' do |t|
      ultimate = Ultimate.new
      t.check :name, :expect => 42, :actual => ultimate.answer
    end
  end

GIT
  open http://github.com/ahoward/testy/tree/master
  git clone git://github.com/ahoward/testy.git

PRINCIPLES AND GOALS
  . it.should.not.merely.be.a.unit.testing.with.a.clever.dsl

  . testing should not require learning a framework.  ruby is a great
  framework so testy uses it instead, requiring programmers learn exactly 2
  new method calls

  . testing loc should not dwarf those of the application

  . testing framework loc should not dwarf those of the application

  . testing frameworks should *never* alter ruby built-ins nor add methods to
  Object, Kernel, .et al

  . the output of tests should be machine parsable for reporting and ci tools
  to easily integrate with

  . the output of tests should be beautiful so that humans can read it

  . the shape of the test file should not insult the programmer so that tests
  can double as sample code

  . the testing framework should never alter exception semantics

  . hi-jacking at_exit sucks ass

  . the exit status of running a test suite should indicate the degree of its
  failure state (testy returns the percent of failed tests using a non-zero
  exit status)

  . sample code should easily be able to double as a test suite, including
  its output

  . testing should improve your code and help your users, not make you want to
  kill yourself

  . using a format that aligns in terminal is sanity saving when comparing
  output

  . testing frameworks should provide as few shortcuts for making brittle
  tightly coupled tests as possible

  . test suites should be able to be created, manipulated, have their output
  streamed to different ports, and even tested themselves - they should be
  plain ol objects under the hood
  
SAMPLES

  <========< samples/a.rb >========>

  ~ > cat samples/a.rb

    # simple use of testy involves simply writing code, and recording the result
    # you expect against the actual result
    #
    # notice that the output is very pretty and that the exitstatus is 0 when all
    # tests pass
    #
      require 'testy'
    
      Testy.testing 'the kick-ass-ed-ness of testy' do
    
        test 'the ultimate answer to life' do |result|
          list = []
    
          list << 42
          result.check :a, :expect => 42, :actual => list.first
    
          list << 42.0
          result.check :b, 42.0, list.last
        end
    
      end

  ~ > ruby samples/a.rb #=> exitstatus=0

    --- 
    the kick-ass-ed-ness of testy: 
      the ultimate answer to life: 
        success: 
          a: 42
          b: 42.0


  <========< samples/b.rb >========>

  ~ > cat samples/b.rb

    # testy will handle unexpected results and exceptions thrown in your code in
    # exactly the same way - by reporting on them in a beautiful fashion and
    # continuing to run other tests.  notice, however, that an unexpected result
    # or raised exception will cause a non-zero exitstatus (the percent of tests
    # that failed) for the suite as a whole.  also note that previously
    # accumulated expect/actual pairs are still reported on in the error report.
    #
      require 'testy'
    
      Testy.testing 'the exception handling of testy' do
    
        test 'raising an exception' do |result|
          list = []
    
          list << 42
          result.check :a, :expect => 42, :actual => list.first
    
          list.method_that_does_not_exist
        end
    
        test 'returning unexpected results' do |result|
          result.check 'a', 42, 42
          result.check :b, :expect => 'forty-two', :actual => 42.0
        end
    
      end

  ~ > ruby samples/b.rb #=> exitstatus=100

    --- 
    the exception handling of testy: 
      raising an exception: 
        failure: 
          error: 
            class: NoMethodError
            message: undefined method `method_that_does_not_exist' for [42]:Array
            backtrace: 
            - samples/b.rb:18:in `call'
            - ./lib/testy.rb:130:in `run'
            - ./lib/testy.rb:113:in `instance_eval'
            - ./lib/testy.rb:113:in `run'
            - /opt/local/lib/ruby/site_ruby/1.8/orderedhash.rb:65:in `each'
            - /opt/local/lib/ruby/site_ruby/1.8/orderedhash.rb:65:in `each'
            - ./lib/testy.rb:108:in `run'
            - ./lib/testy.rb:78:in `call'
            - ./lib/testy.rb:78:in `context'
            - ./lib/testy.rb:102:in `run'
            - ./lib/testy.rb:167:in `testing'
            - samples/b.rb:10
          expect: 
            a: 42
          actual: 
            a: 42
      returning unexpected results: 
        failure: 
          expect: 
            a: 42
            b: forty-two
          actual: 
            a: 42
            b: 42.0


  <========< samples/c.rb >========>

  ~ > cat samples/c.rb

    # in some cases you may not even want to make test assertions and simply
    # provide example code which should run without error, with testy it's not
    # only easy to do this but the commanline supports --list to see which samples
    # can be run and running a single or multiple tests based on name or pattern.
    # notice that, when no assertions are made using 'result.check' the output of
    # the test becomes the expected *and* actual and is therefore shown in the
    # output as yaml.  of course, if your samples have errors they are reported in
    # the normal fashion and the tests will fail.
    #
    #
      require 'testy'
    
      Testy.testing 'some samplz for you' do
        test 'foo sample' do
          list = 1,2
          list.last + list.first
        end
    
        test 'bar sample' do
          list = 1,2
          list.shift * list.pop
        end
    
        test 'foobar sample' do
          list = 1,2
          eval(list.reverse.join) * 2
        end
      end
    
    # here are some examples of using the command line arguments on the above test
    #
    # cfp:~/src/git/testy > ruby samples/c.rb --list
    # --- 
    # - foo sample
    # - bar sample
    # - foobar sample
    #
    # cfp:~/src/git/testy > ruby samples/c.rb foobar
    # --- 
    # some samplz for you: 
    #   foobar sample: 
    #     success: 42
    #
    # cfp:~/src/git/testy > ruby samples/c.rb foo
    # --- 
    # some samplz for you: 
    #   foo sample: 
    #     success: 3
    #   foobar sample: 
    #     success: 42
    #
    # cfp:~/src/git/testy > ruby samples/c.rb bar
    # --- 
    # some samplz for you: 
    #   bar sample: 
    #     success: 2

  ~ > ruby samples/c.rb #=> exitstatus=0

    --- 
    some samplz for you: 
      foo sample: 
        success: 3
      bar sample: 
        success: 2
      foobar sample: 
        success: 42


  <========< samples/d.rb >========>

  ~ > cat samples/d.rb

    # of course testy includes smartly inherited contexts and context sensitive
    # setup and teardown methods which stack as well.
    #
      require 'testy'
    
      Testy.testing 'your bitchin lib' do
        context 'A' do
          setup{ @list = [40] }
    
          test 'foo' do
            @list << 2
            @list.first + @list.last
          end
    
          test 'bar' do |t|
            t.check :list, @list, [40]
          end
    
          context 'B' do
            setup{ @list << 2 }
            test(:bar){ @list.join.delete('0') }
          end
        end
      end
    
    
    # the context name is applied to the test name, so you can selectively run
    # groups of tests from the command line
    #
    # cfp:~/src/git/testy > ruby -I lib samples/d.rb 'A - B'
    # --- 
    # your bitchin lib: 
    #   A - B - bar: 
    #       success: "42"

  ~ > ruby samples/d.rb #=> exitstatus=0

    --- 
    your bitchin lib: 
      A - foo: 
        success: 42
      A - bar: 
        success: 
          list: 
          - 40
      A - B - bar: 
        success: "42"

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server