lemon 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ module Lemon::Test
2
+
3
+ # Test Concerns are used to organize unit tests
4
+ # in groups, so as to address specific quality
5
+ # assurance objectives.
6
+ class Concern
7
+
8
+ # The test case to which this concern belongs.
9
+ attr :testcase
10
+
11
+ # The description of this concern. Make this
12
+ # as detailed as you wish.
13
+ attr :description
14
+
15
+ # Unit tests that belong to this concern.
16
+ attr :testunits
17
+
18
+ # New concern.
19
+ def initialize(testcase, description)
20
+ @testcase = testcase
21
+ @description = description.join("\n")
22
+ @testunits = []
23
+ end
24
+
25
+ # Assign a unit test to this concern.
26
+ def assign(testunit)
27
+ raise ArgumentError unless Unit === testunit
28
+ @testunits << testunit
29
+ end
30
+
31
+ # Iterate through each test unit.
32
+ def each(&block)
33
+ @testunits.each(&block)
34
+ end
35
+
36
+ # Returns the description with newlines removed.
37
+ def to_s
38
+ description.gsub(/\n/, ' ')
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,126 @@
1
+ module Lemon
2
+ module Test
3
+
4
+ require 'lemon/test/case'
5
+
6
+ # Test Suites encapsulate a set of test cases.
7
+ #
8
+ class Suite
9
+
10
+ # Test cases in this suite.
11
+ attr :testcases
12
+
13
+ # List of concern procedures that apply suite-wide.
14
+ attr :when_clauses
15
+
16
+ # List of pre-test procedures that apply suite-wide.
17
+ attr :before_clauses
18
+
19
+ # List of post-test procedures that apply suite-wide.
20
+ attr :after_clauses
21
+
22
+ # List of concern procedures that apply suite-wide.
23
+ attr :when_clauses
24
+
25
+ #
26
+ def initialize(*tests)
27
+ @testcases = []
28
+ @before_clauses = {}
29
+ @after_clauses = {}
30
+ @when_clauses = {}
31
+
32
+ # directories glob *.rb files
33
+ tests = tests.flatten.map do |file|
34
+ if File.directory?(file)
35
+ Dir[File.join(file, '**', '*.rb')]
36
+ else
37
+ file
38
+ end
39
+ end.flatten.uniq
40
+
41
+ @test_files = tests
42
+
43
+ tests.each do |file|
44
+ #file = File.expand_path(file)
45
+ instance_eval(File.read(file), file)
46
+ end
47
+ end
48
+
49
+ # Load a helper. This method must be used when loading local
50
+ # suite support. The usual #require or #load can only be used
51
+ # for extenal support libraries (such as a test mock framework).
52
+ # This is so because suite code is not evaluated at the toplevel.
53
+ def helper(file)
54
+ instance_eval(File.read(file), file)
55
+ end
56
+
57
+ #
58
+ #def load(file)
59
+ # instance_eval(File.read(file), file)
60
+ #end
61
+
62
+ # Includes at the suite level are routed to the toplevel.
63
+ def include(*mods)
64
+ TOPLEVEL_BINDING.eval('self').instance_eval do
65
+ include(*mods)
66
+ end
67
+ end
68
+
69
+ # Define a test case belonging to this suite.
70
+ def Case(target_class, &block)
71
+ testcases << Case.new(self, target_class, &block)
72
+ end
73
+
74
+ #
75
+ alias_method :TestCase, :Case
76
+
77
+ #
78
+ alias_method :testcase, :Case
79
+
80
+ # Define a pre-test procedure to apply suite-wide.
81
+ def Before(match=nil, &block)
82
+ @before_clauses[match] = block #<< Advice.new(match, &block)
83
+ end
84
+
85
+ alias_method :before, :Before
86
+
87
+ # Define a post-test procedure to apply suite-wide.
88
+ def After(match=nil, &block)
89
+ @after_clauses[match] = block #<< Advice.new(match, &block)
90
+ end
91
+
92
+ alias_method :after, :After
93
+
94
+ # Define a concern procedure to apply suite-wide.
95
+ def When(match=nil, &block)
96
+ @when_clauses[match] = block #<< Advice.new(match, &block)
97
+ end
98
+
99
+ # Iterate through this suite's test cases.
100
+ def each(&block)
101
+ @testcases.each(&block)
102
+ end
103
+
104
+ # FIXME: This is a BIG FAT HACK! For the life of me I cannot find
105
+ # a way to resolve module constants included in the test cases.
106
+ # Becuase of closure, the constant lookup goes through here, and not
107
+ # the Case singleton class. So to work around wemust note each test
108
+ # before it is run, and reroute the missing constants.
109
+ #
110
+ # This sucks and it is not thread safe. If anyone know how to fix,
111
+ # please let me know. See Unit#call for the other end of this hack.
112
+
113
+ def self.const_missing(name)
114
+ (class << @@test_stack.last.testcase; self; end).const_get(name)
115
+ end
116
+
117
+ # Get current running test. Used for the BIG FAT HACK.
118
+ def test_stack
119
+ @@test_stack ||= []
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+ end
126
+
@@ -0,0 +1,56 @@
1
+ module Lemon::Test
2
+
3
+ #
4
+ class Unit
5
+
6
+ # The test case to which this unit test belongs.
7
+ attr :testcase
8
+
9
+ # The concern which this test helps ensure.
10
+ attr :concern
11
+
12
+ # A test unit +target+ is a method.
13
+ attr :target
14
+
15
+ # The aspect of the concern this test fulfills.
16
+ attr :aspect
17
+
18
+ # Test procedure, in which test assertions should be made.
19
+ attr :procedure
20
+
21
+ # New unit test.
22
+ def initialize(concern, target, aspect=nil, &procedure)
23
+ concern.assign(self)
24
+
25
+ @concern = concern
26
+ @testcase = concern.testcase
27
+
28
+ @target = target
29
+ @aspect = aspect
30
+ @procedure = procedure
31
+ end
32
+
33
+ # This method has the other end of the BIG FAT HACK. See Suite#const_missing.
34
+ def call
35
+ suite.test_stack << self # hack
36
+ procedure.call
37
+ ensure
38
+ suite.test_stack.pop
39
+ end
40
+
41
+ # The suite to which this unit test belongs.
42
+ def suite
43
+ testcase.suite
44
+ end
45
+
46
+ #
47
+ def to_s
48
+ "#{testcase}##{target} #{aspect}"
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+
56
+
data/meta/author ADDED
@@ -0,0 +1 @@
1
+ Thomas Sawyer
data/meta/contact ADDED
@@ -0,0 +1 @@
1
+ proutils@librelist.com
data/meta/copyright ADDED
@@ -0,0 +1 @@
1
+ Copyright 2009 Thomas Sawyer
data/meta/description ADDED
@@ -0,0 +1,2 @@
1
+ Lemon is a unit testing framework that tightly correlates
2
+ class to test case and method to test unit.
data/meta/homepage ADDED
@@ -0,0 +1 @@
1
+ http://proutils.github.com/lemon
data/meta/license ADDED
@@ -0,0 +1 @@
1
+ LGPL
data/meta/name ADDED
@@ -0,0 +1 @@
1
+ lemon
data/meta/repository ADDED
@@ -0,0 +1 @@
1
+ git://github.com/proutils/lemon.git
data/meta/suite ADDED
@@ -0,0 +1 @@
1
+ proutils
data/meta/summary ADDED
@@ -0,0 +1 @@
1
+ Pucker-tight Unit Testing
data/meta/title ADDED
@@ -0,0 +1 @@
1
+ Lemon
data/meta/version ADDED
@@ -0,0 +1 @@
1
+ 0.5
@@ -0,0 +1,26 @@
1
+ #
2
+
3
+ testcase Lemon::Coverage do
4
+
5
+ #Before /returns/ do |unit|
6
+ # puts "returns something"
7
+ #end
8
+
9
+ unit :coverage => 'returns a chart of coverage' do
10
+ #X.new.a.assert.is_a?(String)
11
+ end
12
+
13
+ unit :cover => 'returns a pre-checked chart of potential coverage' do
14
+ #X.new.a.assert =~ /^[a-z]*$/
15
+ end
16
+
17
+ unit :system => 'returns a list of classes/modules currently in the Ruby proccess' do
18
+ #1.assert == 4
19
+ end
20
+
21
+ #unit :snapshot => 'can be broken' do
22
+ # #1.assert == 4
23
+ #end
24
+
25
+ end
26
+
@@ -0,0 +1,58 @@
1
+ # Some fixture code for testing #include.
2
+ module M
3
+ def m1; "m1"; end
4
+ module N
5
+ def self.n1; "n1"; end
6
+ end
7
+ end
8
+
9
+ Case(Lemon::Test::Case) do
10
+
11
+ Concern "Modules included in a test case are accessible by the unit tests."
12
+
13
+ include M
14
+ #N = M::N
15
+
16
+ Unit :include => "allows access to module methods" do
17
+ m1.assert == "m1"
18
+ end
19
+
20
+ Unit :include => "allows access to nested modules" do
21
+ N::n1.assert == "n1"
22
+ end
23
+
24
+
25
+ Concern "Unit tests are augmented by before and after procedures."
26
+
27
+ Before /pre-test/ do |unit|
28
+ @check_before = :before
29
+ end
30
+
31
+ After /pre-test/ do |unit|
32
+ @check_after = :after
33
+ end
34
+
35
+ Unit :Before => "sets up a pre-test procedure" do
36
+ @check_before.assert == :before
37
+ end
38
+
39
+ Unit :After => "sets up a post-test procedure" do
40
+ @check_after.assert == :after
41
+ end
42
+
43
+
44
+ #Concern "Unit tests are augmented by when procedures.",
45
+ # "(NOTE: we have to repeat this concern in order to test it.)"
46
+
47
+ When /augmented\ by\ when\ procedures/ do
48
+ @check_concern = :concern
49
+ end
50
+
51
+ Concern "Unit tests are augmented by when procedures."
52
+
53
+ Unit :Concern => "sets up a concern procedure" do
54
+ @check_concern.assert == :concern
55
+ end
56
+
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lemon
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.5"
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Sawyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-31 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ Lemon is a unit testing framework that tightly correlates
18
+ class to test case and method to test unit.
19
+ email: proutils@librelist.com
20
+ executables:
21
+ - lemon
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - MANIFEST
26
+ - README.rdoc
27
+ - HISTORY
28
+ - COPYING.LESSER
29
+ - Syckfile
30
+ - COPYING
31
+ files:
32
+ - COPYING
33
+ - COPYING.LESSER
34
+ - HISTORY
35
+ - README.rdoc
36
+ - bin/lemon
37
+ - lib/lemon.rb
38
+ - lib/lemon/command.rb
39
+ - lib/lemon/coverage.rb
40
+ - lib/lemon/kernel.rb
41
+ - lib/lemon/reporter.rb
42
+ - lib/lemon/reporters.rb
43
+ - lib/lemon/reporters/dotprogress.rb
44
+ - lib/lemon/reporters/verbose.rb
45
+ - lib/lemon/runner.rb
46
+ - lib/lemon/test/case.rb
47
+ - lib/lemon/test/concern.rb
48
+ - lib/lemon/test/suite.rb
49
+ - lib/lemon/test/unit.rb
50
+ - meta/author
51
+ - meta/contact
52
+ - meta/copyright
53
+ - meta/description
54
+ - meta/homepage
55
+ - meta/license
56
+ - meta/name
57
+ - meta/repository
58
+ - meta/suite
59
+ - meta/summary
60
+ - meta/title
61
+ - meta/version
62
+ - test/cases/coverage_case.rb
63
+ - test/cases/testcase_case.rb
64
+ - MANIFEST
65
+ - Syckfile
66
+ has_rdoc: true
67
+ homepage: http://proutils.github.com/lemon
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --title
73
+ - Lemon API
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: lemon
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Pucker-tight Unit Testing
95
+ test_files:
96
+ - test/cases/testcase_case.rb