giraffesoft-zebra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = Zebra
2
+
3
+ Zebra is another tool for testing your rubies.
4
+
5
+ = The problem
6
+
7
+ context "A blog post" do
8
+ setup do
9
+ @author = create_person
10
+ @post = create_post :author => @author
11
+ end
12
+
13
+ should "be editable by its author" do
14
+ assert @post.editable_by?(@author)
15
+ end
16
+ end
17
+
18
+ == Don't see the problem?
19
+
20
+ Why bother writing self-documenting test code if you always have to explain it to the reader? {Test names are essentially glorified comments}[http://blog.jayfields.com/2008/05/testing-value-of-test-names.html] and {comments are frequently code smells}[http://memeagora.blogspot.com/2008/11/comments-code-smell.html]. Furthermore, all the extra code required to create a test (should "" do ... end) almost certainly discourages one assertion per test. If the assertion is one line and the code can explain itself, why bother with all the other crap?
21
+
22
+ == The Solution
23
+
24
+ context "With a blog post" do
25
+ setup do
26
+ @author = create_person
27
+ @somebody_else = create_person
28
+ @post = create_post :author => @author
29
+ end
30
+
31
+ expect { @post.to be_editable_by(@author) }
32
+ expect { @post.not_to be_editable_by(@somebody_else) }
33
+ end
34
+
35
+ == But, what about the test name?
36
+
37
+ I'm glad you asked. This is where zebra gets really cool. The above test will create tests with the following names:
38
+
39
+ test: With a blog post expect @post.to(be_editable_by(@author))
40
+ test: With a blog post expect @post.not_to(be_editable_by(@author))
41
+
42
+ Now, *that* is self documenting code.
43
+
44
+ == The right tool for the job
45
+
46
+ The cool thing about zebra is that it's an extension to test/unit. If you have a test that belongs in a should block, with a big, old-fashioned test name, you can have it. Just use should or it. When you have a short, self-documenting test, use expect. Best of both worlds.
47
+
48
+ == Dependencies
49
+
50
+ - jeremymcanally-context
51
+ - jeremymcanally-matchy
52
+ - parse_tree
53
+ - ruby2ruby
54
+
55
+ == Inspiration
56
+
57
+ {Jay Fields' Expectations}[http://blog.jayfields.com/2007/12/ruby-expectation-gem.html]
58
+
59
+ == COPYRIGHT
60
+
61
+ Copyright (c) 2008 {James Golick}[http://jamesgolick.com]. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
data/lib/zebra.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'test/unit'
2
+ require 'context'
3
+ require 'matchy'
4
+ require 'parse_tree'
5
+ require 'parse_tree_extensions'
6
+ require 'ruby2ruby'
7
+
8
+ module Zebra
9
+ def expect(&block)
10
+ block_translation = block.to_ruby.gsub /proc \{ (.+?) \}/, '\1'
11
+ test_name = ["test:", context_name, "expect", block_translation]
12
+ test_name.reject! { |s| s == "" }
13
+
14
+ define_method(test_name.join(' '), &block)
15
+ end
16
+ end
17
+
18
+ Test::Unit::TestCase.send(:extend, Zebra)
19
+ Object.send(:alias_method, :to, :should)
20
+ Object.send(:alias_method, :not_to, :should_not)
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'context'
3
+
4
+ class ContextTest < Test::Unit::TestCase
5
+ it "should create a test" do
6
+ self.class.expect { 2.to == 1 }
7
+ assert self.respond_to?("test: expect (2.to == 1)")
8
+ end
9
+
10
+ context "in a context" do
11
+ it "should grab the name of the context" do
12
+ self.class.expect { 2.to == 1 }
13
+ assert self.respond_to?("test: in a context expect (2.to == 1)"), self.class.instance_methods.grep(/test/).inspect
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class MatchyTest < Test::Unit::TestCase
4
+ it "should alias should to .to" do
5
+ assert_equal Object.method(:should), Object.method(:to)
6
+ end
7
+
8
+ it "should alias should_not to .not_to" do
9
+ assert_equal Object.method(:should_not), Object.method(:not_to)
10
+ end
11
+ end
12
+
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/zebra'
4
+
5
+ class Test::Unit::TestCase
6
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: giraffesoft-zebra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - James Golick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-16 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jeremymcanally-context
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.5.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: jeremymcanally-matchy
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.0.1
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: ParseTree
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.2
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: ruby2ruby
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.2.1
50
+ version:
51
+ description: TODO
52
+ email: james@giraffesoft.ca
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - README.rdoc
61
+ - VERSION.yml
62
+ - lib/zebra.rb
63
+ - test/context_test.rb
64
+ - test/matchy_test.rb
65
+ - test/test_helper.rb
66
+ has_rdoc: false
67
+ homepage: http://github.com/giraffesoft/zebra
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.2.0
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: TODO
92
+ test_files: []
93
+