lemon 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.ruby +23 -14
  2. data/.yardopts +6 -0
  3. data/Config.rb +14 -0
  4. data/{HISTORY.rdoc → HISTORY.md} +26 -11
  5. data/LICENSE.txt +27 -0
  6. data/README.md +42 -28
  7. data/SPECSHEET.md +314 -0
  8. data/bin/{lemonade → lemons} +0 -0
  9. data/lib/lemon.yml +23 -14
  10. data/lib/lemon/cli.rb +19 -8
  11. data/lib/lemon/cli/base.rb +50 -20
  12. data/lib/lemon/cli/generate.rb +51 -16
  13. data/lib/lemon/cli/lemon.ascii +84 -0
  14. data/lib/lemon/cli/obrother.rb +35 -0
  15. data/lib/lemon/cli/scaffold.rb +116 -0
  16. data/lib/lemon/core_ext.rb +2 -2
  17. data/lib/lemon/core_ext/module.rb +9 -0
  18. data/lib/lemon/coverage/analyzer.rb +76 -5
  19. data/lib/lemon/coverage/cover_unit.rb +38 -14
  20. data/lib/lemon/coverage/formats/verbose.rb +1 -1
  21. data/lib/lemon/coverage/generator.rb +196 -0
  22. data/lib/lemon/coverage/snapshot.rb +16 -16
  23. data/lib/lemon/coverage/source_parser.rb +103 -37
  24. data/lib/lemon/ignore_callers.rb +19 -0
  25. data/lib/lemon/test_case.rb +135 -26
  26. data/lib/lemon/test_class.rb +16 -3
  27. data/lib/lemon/test_class_method.rb +58 -0
  28. data/lib/lemon/test_method.rb +57 -68
  29. data/lib/lemon/test_module.rb +47 -44
  30. data/lib/lemon/test_proc.rb +28 -2
  31. data/lib/lemon/test_scope.rb +14 -0
  32. data/lib/lemon/test_setup.rb +1 -1
  33. data/lib/lemon/test_world.rb +7 -0
  34. data/{work/deprecated/features/support → spec/applique}/ae.rb +0 -0
  35. data/spec/coverage/{01_complete.rdoc → 01_complete.md} +3 -3
  36. data/spec/coverage/{02_incomplete.rdoc → 02_incomplete.md} +2 -2
  37. data/spec/coverage/{03_extensions.rdoc → 03_extensions.md} +2 -2
  38. data/try/case_scope.rb +19 -0
  39. metadata +50 -102
  40. data/.gemspec +0 -152
  41. data/.gitignore +0 -8
  42. data/.reap/digest +0 -678
  43. data/.reap/test.reap +0 -7
  44. data/Assembly +0 -37
  45. data/COPYING.rdoc +0 -33
  46. data/MANIFEST +0 -55
  47. data/PROFILE +0 -30
  48. data/Rakefile +0 -23
  49. data/VERSION +0 -1
  50. data/lib/lemon/core_ext/omission.rb +0 -18
  51. data/lib/lemon/generator.rb +0 -149
  52. data/notes/2010-05-05-coverage.rdoc +0 -47
  53. data/notes/2010-05-06-files-not-classes.rdoc +0 -19
  54. data/notes/2010-07-11-acid-testing.rdoc +0 -52
  55. data/notes/2010-08-02-enforcing-the-unit.md +0 -68
  56. data/notes/2010-08-03-new-api.md +0 -37
  57. data/notes/2011-07-07-nailing-down-the-nomenclature.md +0 -6
  58. data/site/.rsync-filter +0 -8
  59. data/site/assets/images/cut-lemon.png +0 -0
  60. data/site/assets/images/forkme.png +0 -0
  61. data/site/assets/images/github-logo.png +0 -0
  62. data/site/assets/images/lemon.jpg +0 -0
  63. data/site/assets/images/lemon.svg +0 -39
  64. data/site/assets/images/lemons-are-good.png +0 -0
  65. data/site/assets/images/opensource.png +0 -0
  66. data/site/assets/images/ruby-logo.png +0 -0
  67. data/site/assets/images/skin.jpg +0 -0
  68. data/site/assets/images/skin1.jpg +0 -0
  69. data/site/assets/images/tap.png +0 -0
  70. data/site/assets/images/title.png +0 -0
  71. data/site/assets/styles/class.css +0 -6
  72. data/site/assets/styles/reset.css +0 -17
  73. data/site/assets/styles/site.css +0 -33
  74. data/site/index.html +0 -218
  75. data/work/deprecated/command/abstract.rb +0 -29
  76. data/work/deprecated/command/coverage.rb +0 -115
  77. data/work/deprecated/command/generate.rb +0 -124
  78. data/work/deprecated/command/test.rb +0 -112
  79. data/work/deprecated/cucumber.yml +0 -3
  80. data/work/deprecated/features/coverage.feature +0 -65
  81. data/work/deprecated/features/generate.feature +0 -66
  82. data/work/deprecated/features/step_definitions/coverage_steps.rb +0 -1
  83. data/work/deprecated/features/support/aruba.rb +0 -1
  84. data/work/deprecated/features/test.feature +0 -67
  85. data/work/deprecated/model/dsl/advice.rb +0 -78
  86. data/work/deprecated/model/dsl/subject.rb +0 -40
  87. data/work/deprecated/model/main.rb +0 -87
  88. data/work/deprecated/model/test.rb +0 -54
  89. data/work/deprecated/model/test_base_dsl.rb +0 -88
  90. data/work/deprecated/model/test_clause.rb +0 -112
  91. data/work/deprecated/model/test_context.rb +0 -90
  92. data/work/deprecated/model/test_feature.rb +0 -128
  93. data/work/deprecated/model/test_scenario.rb +0 -137
  94. data/work/deprecated/model/test_suite.rb +0 -297
  95. data/work/deprecated/rake.rb +0 -103
  96. data/work/deprecated/test/case_coverage_analyzer.rb +0 -25
  97. data/work/deprecated/test/case_test_case_dsl.rb +0 -46
  98. data/work/deprecated/test/fixtures/case_complete.rb +0 -25
  99. data/work/deprecated/test/fixtures/case_inclusion.rb +0 -18
  100. data/work/deprecated/test/fixtures/case_incomplete.rb +0 -12
  101. data/work/deprecated/test/fixtures/example.rb +0 -13
  102. data/work/deprecated/test/fixtures/helper.rb +0 -13
  103. data/work/deprecated/test/runner +0 -2
  104. data/work/old-tests/case_example.rb +0 -15
  105. data/work/old-tests/feature_example.rb +0 -40
  106. data/work/reference/dsl2.rb +0 -140
  107. data/work/reference/dynamic_constant_lookup.rb +0 -76
data/.ruby CHANGED
@@ -1,15 +1,16 @@
1
1
  ---
2
+ source:
3
+ - meta
4
+ - VERSION
2
5
  authors:
3
6
  - name: Thomas Sawyer
4
7
  email: transfire@gmail.com
5
8
  copyrights:
6
- - holder: Thomas Sawyer
9
+ - holder: Rubyworks
7
10
  year: '2009'
8
11
  license: BSD-2-Clause
9
- replacements: []
10
- conflicts: []
11
12
  requirements:
12
- - name: test
13
+ - name: rubytest
13
14
  - name: ae
14
15
  - name: ansi
15
16
  version: 1.3+
@@ -25,25 +26,33 @@ requirements:
25
26
  groups:
26
27
  - test
27
28
  development: true
29
+ - name: ripper
30
+ optional: true
31
+ engines:
32
+ - name: ruby
33
+ version: 1.8~
28
34
  dependencies: []
35
+ alternatives: []
36
+ conflicts: []
29
37
  repositories:
30
38
  - uri: git://github.com/proutils/lemon.git
31
39
  scm: git
32
- name: origin
40
+ name: upstream
33
41
  resources:
34
42
  home: http://rubyworks.github.com/lemon
35
43
  code: http://github.com/rubyworks/lemon
44
+ bugs: http://github.com/rubyworks/lemon/issues
45
+ extra: {}
36
46
  load_path:
37
47
  - lib
38
- extra:
39
- manifest: MANIFEST
40
- alternatives: []
41
48
  revision: 0
49
+ created: '2009-10-25'
50
+ summary: Pucker-strength Unit Testing
42
51
  title: Lemon
43
- summary: Pucker-tight Unit Testing
44
- description: Lemon is a unit testing framework that tightly correlates class to test
45
- case and method to test unit.
46
- organization: RubyWorks
47
- version: 0.9.0
48
52
  name: lemon
49
- date: '2011-08-11'
53
+ description: ! 'Lemon is a unit testing framework that tightly correlates
54
+
55
+ class to test case and method to test unit.'
56
+ organization: rubyworks
57
+ version: 0.9.1
58
+ date: '2012-03-09'
@@ -0,0 +1,6 @@
1
+ --output-dir doc
2
+ --private
3
+ --protected
4
+ lib/
5
+ -
6
+ [A-Z][A-Z]*.*
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ profile :coverage do
4
+
5
+ config :qed do
6
+ require 'simplecov'
7
+ SimpleCov.start do
8
+ coverage_dir 'log/coverage'
9
+ #add_group "Label", "lib/qed/directory"
10
+ end
11
+ end
12
+
13
+ end
14
+
@@ -1,6 +1,21 @@
1
- = RELEASE HISTORY
1
+ # RELEASE HISTORY
2
2
 
3
- == 0.9.0 / 2011-08-11
3
+ ## 0.9.1 / 2012-03-17
4
+
5
+ Thie release fixes some evaluation scope issues, improves how omit and skip
6
+ methods work, makes test generation usable and generally cleans-up internals.
7
+ All in all, this release should be a fair bit more robust than previous releases
8
+ and ready for the big 1.0 after one more good coding session.
9
+
10
+ Changes:
11
+
12
+ * Fix test scope so it's properly isolated.
13
+ * Improve skip and omit methods w/ non-block forms.
14
+ * Use Ripper instead of RubyParse for scaffolding.
15
+ * Greatly improve usability of code generation tool.
16
+
17
+
18
+ ## 0.9.0 / 2011-08-11
4
19
 
5
20
  Version 0.9 is a huge release for Lemon. This release finally makes the transition
6
21
  to the new unit subcase syntax --a bit more verbose than the old style but a more
@@ -31,7 +46,7 @@ Changes:
31
46
  * Implemented new unit block syntax.
32
47
 
33
48
 
34
- == 0.8.5 / 2011-07-15
49
+ ## 0.8.5 / 2011-07-15
35
50
 
36
51
  This release fixes exit code status, which should be -1 if there
37
52
  are errors or failures.
@@ -41,7 +56,7 @@ Changes:
41
56
  * Fix exit code status.
42
57
 
43
58
 
44
- == 0.8.4 / 2011-07-11
59
+ ## 0.8.4 / 2011-07-11
45
60
 
46
61
  Fix reported issue #6 to get lemon passing it own tests. (Note: the
47
62
  tests need to be run with `test/fixtures` in the loadpath). There was
@@ -57,7 +72,7 @@ Changes:
57
72
  * Lemon can test itself (albeit test are not complete).
58
73
 
59
74
 
60
- == 0.8.3 / 2011-05-19
75
+ ## 0.8.3 / 2011-05-19
61
76
 
62
77
  Looks like Lemon is pretty damn near 1.0 status. She probably won't get
63
78
  any major changes for a good while. This release simply adds TAP-Y/J reporters.
@@ -69,7 +84,7 @@ Changes:
69
84
  * Configuration directory can be `.lemon/`.
70
85
 
71
86
 
72
- == 0.8.2 / 2010-09-05
87
+ ## 0.8.2 / 2010-09-05
73
88
 
74
89
  This release overhauls how coverage is performed so it does not need to
75
90
  take a system snapshot after requiring each covered file. This greatly
@@ -84,7 +99,7 @@ Changes:
84
99
  * Improved output formats.
85
100
 
86
101
 
87
- == 0.8.1 / 2010-07-11
102
+ ## 0.8.1 / 2010-07-11
88
103
 
89
104
  This release adds a timer to the verbose output, which help isolate unit tests
90
105
  that are slow. It also fixed bug in Before and After advice that prevented them
@@ -95,7 +110,7 @@ Changes:
95
110
  * Add times to verbose reporter.
96
111
 
97
112
 
98
- == 0.8.0 / 2010-06-21
113
+ ## 0.8.0 / 2010-06-21
99
114
 
100
115
  This release removes coverage information from testing. Coverage can be time
101
116
  consuming, but running test should be as fast as possbile. For this reason
@@ -108,7 +123,7 @@ Changes:
108
123
  * Test generator defaults to public methods only.
109
124
 
110
125
 
111
- == 0.7.0 / 2010-05-04
126
+ ## 0.7.0 / 2010-05-04
112
127
 
113
128
  This release fixes issue with coverage reports. To do this we have interoduced
114
129
  the +Covers+ method. This allows Lemon to distingush between code that is
@@ -125,7 +140,7 @@ Changes:
125
140
  * New Snapshot class improves encapsulation to coverage state.
126
141
 
127
142
 
128
- == 0.6.0 / 2010-03-06
143
+ ## 0.6.0 / 2010-03-06
129
144
 
130
145
  This release adds coverage reporting to testing and improves the generator.
131
146
 
@@ -136,7 +151,7 @@ Changes:
136
151
  * Suite class has Coverage instance.
137
152
 
138
153
 
139
- == 0.5.0 / 2009-12-31
154
+ ## 0.5.0 / 2009-12-31
140
155
 
141
156
  This is the initial public release of Lemon. Lemon is still under development
142
157
  and should be considered betaware, but it's API is stable and the system usable
@@ -0,0 +1,27 @@
1
+ Lemon - Pucker-Strength Unit Testing
2
+
3
+ Copyright (c) 2009 Rubyworks. All rights reserved
4
+
5
+ Licensed (spdx) BSD-2-Clause
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are
8
+ permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this list of
11
+ conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ of conditions and the following disclaimer in the documentation and/or other materials
15
+ provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
18
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ (http://rubyworks.github.com/lemon)
data/README.md CHANGED
@@ -10,15 +10,15 @@
10
10
 
11
11
  Lemon is a Unit Testing Framework that enforces a strict test structure mirroring the class/module and method structure of the target code. Arguably this promotes the proper technique for low-level unit testing and helps ensure good test coverage.
12
12
 
13
- The difference between unit testing and functional testing, and all other forms of testing for that matter, is simply a matter of where the testing *concern* lies. The concerns of unit testing are the concerns of unit tests --the individual methods.
13
+ The difference between unit testing and functional testing, and all other forms of testing for that matter, is simply a matter of where the testing *concern* lies. The concerns of unit testing are the concerns of unit tests, which, in object-oriented design, drills down to individual methods.
14
14
 
15
- IMPORTANT! As of v0.9+ the API has changed. The `unit :name => "description"` notation is no longer supported.
15
+ **IMPORTANT!** As of v0.9+ the API has changed. The `unit :name => "description"` notation is no longer supported.
16
16
 
17
17
 
18
18
  ## EXAMPLE
19
19
 
20
20
  Lemon tests are broken down into target class or module and target methods.
21
- Withn these lie the acutal tests.
21
+ Within these lie the actual tests.
22
22
 
23
23
  Let's say we have a script 'mylib.rb' consisting of the class X:
24
24
 
@@ -31,20 +31,20 @@ end
31
31
  An test case for the class would be written:
32
32
 
33
33
  ``` ruby
34
- Covers 'mylib'
34
+ covers 'mylib'
35
35
 
36
- TestCase X do
36
+ testcase X do
37
37
 
38
- Setup "Description of setup." do
38
+ setup "Description of setup." do
39
39
  @x = X.new
40
40
  end
41
41
 
42
- Unit :a do
43
- Test "method #a does something expected" do
42
+ method :a do
43
+ test "method #a does something expected" do
44
44
  @x.a.assert.is_a? String
45
45
  end
46
46
 
47
- Test "method #a does something else expected" do
47
+ test "method #a does something else expected" do
48
48
  @x.a.assert == "x"
49
49
  end
50
50
  end
@@ -56,46 +56,60 @@ The `covers` method works just like `require` with the exception that it records
56
56
 
57
57
  The setup (also called the *concern*) is run for every subsequent test until a new setup is defined.
58
58
 
59
- In conjunction with the `#setup` method, there is a `#teardown` method which can be used "tidy-up" after each test if need be.
59
+ In conjunction with the `#setup` method, there is a `#teardown` method which can be used "tidy-up" after each test.
60
60
 
61
- You might have also notice by the documentation that the test methods do not have to be capitalized.
61
+ The `#unit` method is also aliased as `#methed` which is actually a bit more readable. Along with that there is `class_unit` and it's alias `class_method` for testing class-level methods. Also note that the test methods may be capitalized (e.g. `#TestCase'), if you prefer that style.
62
62
 
63
- That is the bulk of the matter for writing Lemon tests. To learn about additonal features not mentioned here, check-out the [User Guide](http://wiki.github.com/rubyworks/lemon).
63
+ That is the bulk of the matter for writing Lemon tests. To learn about additional features not mentioned here, check-out the [User Guide](http://wiki.github.com/rubyworks/lemon).
64
64
 
65
65
 
66
66
  ## USAGE
67
67
 
68
68
  ### Running Tests
69
69
 
70
- Tests can be run using the `lemonade` command line tool.
70
+ Tests can be run using the `lemons` command line tool.
71
71
 
72
- $ lemonade test test/cases/name_case.rb
72
+ $ lemons test test/cases/name_case.rb
73
73
 
74
- Lemon utilizes the Ruby Test system to run tests, the `lemonade test` command simply passes off the running of tests to `ruby-test`. So the `ruby-test` command-line utility can also be used directly:
74
+ Lemon utilizes the RubyTest universal test harness to run tests, the `lemons test` command simply passes off control to `rubytest` command. So the `rubytest` command-line utility can also be used directly:
75
75
 
76
- $ ruby-test -r lemon test/cases/name_case.rb
76
+ $ rubytest -r lemon test/cases/name_case.rb
77
77
 
78
- Normal output is typical _dot-progress_. Other output types can be specified by the `--format` or `-f` option.
78
+ Normal output is typically a _dot progression_. Other output types can be specified by the `--format` or `-f` option.
79
79
 
80
- $ ruby-test -r lemon -f tap test/cases/name_case.rb
80
+ $ rubytest -r lemon -f tapy test/cases/name_case.rb
81
81
 
82
- See [Ruby Test](http://rubyworks.github.com/test) for more information.
82
+ See [RubyTest](http://rubyworks.github.com/rubytest) for more information.
83
83
 
84
84
  ### Checking Test Coverage
85
85
 
86
- Lemon can check test coverage by loading your target system and comparing it to your tests. To do this use the <code>lemonade coverage</code> command the utility.
86
+ Lemon can check per-unit test coverage by loading your target system and comparing it to your tests. To do this use the `lemons coverage` command.
87
87
 
88
- $ lemonade coverage -Ilib test/cases/*.rb
88
+ $ lemons coverage -Ilib test/cases/*.rb
89
89
 
90
- The coverage tool provides class/module and method coverage and is meant to as a "guidance system" for developers working toward complete test coverage. It is not an lines-of-code coverage tool and should not be considered a substitute for one.
90
+ The coverage tool provides class/module and method coverage and is meant as a "guidance system" for developers working toward complete test coverage. It is not a LOC (lines of code) coverage tool and should not be considered a substitute for one.
91
91
 
92
92
  ### Generating Test Skeletons
93
93
 
94
- Because of the one to one correspondence of test case and unit test to class/module and method, Lemon can also generate test scaffolding for previously written code. To do this, use the <code>lemonade generate</code> command line utility and provide the lib location or files of the scripts for which to generate test scaffolding, and the output location for the test scripts.
94
+ Because of the one-to-one correspondence of test case and unit test to class/module and method, Lemon can also generate test scaffolding for previously written code. To do this, use the `lemons generate` or `lemons scaffold` command line utilities.
95
95
 
96
- $ lemonade generate -Ilib test/cases/*.rb
96
+ The `generate` command outputs test skeletons to the console. You can use this output as a simple reference or redirect the output to a file and then copy and paste portions into separate files as desired. The `scaffold` command will create actual files in your test directory. Other than that, and the options that go with it (e.g. `--output`), the two commands are the same.
97
97
 
98
- Generating test case scaffolding from code will undoubtedly strike test-driven developers as a case of putting the cart before the horse. However, it is not unreasonable to argue that high-level, behavior-driven, functional testing frameworks, such as Q.E.D. and Cucumber are better suited to test-first methodologies. While test-driven development can obviously be done with Lemon, unit-testing is more appropriate for testing specific, critical portions of code, or for achieving full test coverage for mission critical applications.
98
+ To get a set of test skeletons simply provide the files to be covered.
99
+
100
+ $ lemons generate lib/**/*.rb
101
+
102
+ The generator can take into account tests already written, so as not to include units that already have tests. To do this provide a list of test files after a dash (`-`).
103
+
104
+ $ lemons generate -Ilib lib/**/*.rb - test/**/*.rb
105
+
106
+ Test skeletons can be generated on a per-file or per-case bases. By case is the default. Use the `-f`/`--file` option to do otherwise.
107
+
108
+ $ lemon scaffold -f lib/foo.rb
109
+
110
+ The default output location is `test/`. You can change this with the `-o/--output` option.
111
+
112
+ Generating test case scaffolding from code will undoubtedly strike test-driven developers as a case of putting the cart before the horse. However, it is not unreasonable to argue that high-level, behavior-driven, functional testing frameworks, such as Q.E.D. and Cucumber, are better suited to test-first methodologies. While test-driven development can obviously be done with Lemon, unit-testing best suited to testing specific, critical portions of code, or for achieving full test coverage for mission critical applications.
99
113
 
100
114
  ### Test Directory
101
115
 
@@ -106,8 +120,8 @@ There is no special directory for Lemon tests. Since they are unit tests, `test/
106
120
 
107
121
  Lemon Unit Testing Framework
108
122
 
109
- Copyright (c) 2009 Thomas Sawyer
123
+ Copyright (c) 2009 Thomas Sawyer, Rubyworks
110
124
 
111
- Lemon is distributed according to the terms of the **FreeBSD** License.
125
+ Lemon is distributable in accordance with the **FreeBSD** license.
112
126
 
113
- See the COPYING.rdoc file for details.
127
+ See the LICENSE.txt for details.
@@ -0,0 +1,314 @@
1
+ == Complete Coverage
2
+
3
+ === Complete Coverage of Public Interface
4
+
5
+ Given an example script in 'lib/complete_example.rb' as follows:
6
+
7
+ class C1
8
+ def f1; "f1"; end
9
+ def f2; "f2"; end
10
+ def f3; "f3"; end
11
+ end
12
+
13
+ class C2
14
+ def g1; "g1"; end
15
+ protected
16
+ def g2; "g2"; end
17
+ private
18
+ def g3; "g3"; end
19
+ end
20
+
21
+ And given a test case in 'test/complete_example_case.rb' as follows:
22
+
23
+ Covers 'complete_example.rb'
24
+
25
+ TestCase C1 do
26
+ method :f1 do
27
+ test "Returns a String"
28
+ end
29
+ method :f2 do
30
+ test "Returns a String"
31
+ end
32
+ method :f3 do
33
+ test "Returns a String"
34
+ end
35
+ end
36
+
37
+ TestCase C2 do
38
+ method :g1 do
39
+ test "Returns a String"
40
+ end
41
+ end
42
+
43
+ And we get the coverage information via CoverageAnalyer.
44
+
45
+ require 'lemon'
46
+
47
+ tests = ['test/complete_example_case.rb']
48
+
49
+ coverage = Lemon::CoverageAnalyzer.new(tests, :loadpath=>'lib')
50
+
51
+ Then we should see that there are no uncovered units.
52
+
53
+ coverage.uncovered_units.assert == []
54
+
55
+ And there should be 4 covered units,
56
+
57
+ coverage.covered_units.size.assert == 4
58
+
59
+ one for each public class and method.
60
+
61
+ units = coverage.covered_units.map{ |u| u.to_s }
62
+
63
+ units.assert.include?('C1#f1')
64
+ units.assert.include?('C1#f2')
65
+ units.assert.include?('C1#f3')
66
+
67
+ units.assert.include?('C2#g1')
68
+
69
+ There should not be any coverage for private and protected methods.
70
+
71
+ units.refute.include?('C2#g2')
72
+ units.refute.include?('C2#g3')
73
+
74
+ In addition there should be no uncovered_cases or undefined_units.
75
+
76
+ coverage.undefined_units.assert = []
77
+ coverage.uncovered_cases.assert = []
78
+
79
+ === Including Private and Protected Methods
80
+
81
+ We will use the same example classes as above, but in this case we will
82
+ add coverage for private and protected methods as well, given a test case
83
+ in 'test/complete_example_case.rb' as follows:
84
+
85
+ Covers 'complete_example.rb'
86
+
87
+ TestCase C1 do
88
+ method :f1 do
89
+ test "Returns a String"
90
+ end
91
+ method :f2 do
92
+ test "Returns a String"
93
+ end
94
+ method :f3 do
95
+ test "Returns a String"
96
+ end
97
+ end
98
+
99
+ TestCase C2 do
100
+ method :g1 do
101
+ test "Returns a String"
102
+ end
103
+ method :g2 do
104
+ test "Returns a String"
105
+ end
106
+ method :g3 do
107
+ test "Returns a String"
108
+ end
109
+ end
110
+
111
+ And we get the coverage information via CoverageAnalyer.
112
+
113
+ require 'lemon'
114
+
115
+ tests = ['test/complete_example_case.rb']
116
+
117
+ coverage = Lemon::CoverageAnalyzer.new(tests, :loadpath=>'lib', :private=>true)
118
+
119
+ Notice the use of the +private+ option. This will add private and protected
120
+ methods to the coverage analysis.
121
+
122
+ Then we should see that there are no uncovered units.
123
+
124
+ coverage.uncovered_units.assert == []
125
+
126
+ And there should be 6 covered units,
127
+
128
+ coverage.covered_units.size.assert == 6
129
+
130
+ one for each class and method.
131
+
132
+ units = coverage.covered_units.map{ |u| u.to_s }
133
+
134
+ units.assert.include?('C1#f1')
135
+ units.assert.include?('C1#f2')
136
+ units.assert.include?('C1#f3')
137
+
138
+ units.assert.include?('C2#g1')
139
+ units.assert.include?('C2#g2')
140
+ units.assert.include?('C2#g3')
141
+
142
+ In addition there should be no uncovered cases or undefined units.
143
+
144
+ coverage.undefined_units.assert = []
145
+ coverage.uncovered_cases.assert = []
146
+
147
+
148
+ == Incomplete Coverage
149
+
150
+ === Incomplete Coverage of Public Interface
151
+
152
+ Given an example script in 'lib/incomplete_example.rb' as follows:
153
+
154
+ class I1
155
+ def f1; "f1"; end
156
+ def f2; "f2"; end
157
+ def f3; "f3"; end
158
+ end
159
+
160
+ class I2
161
+ def g1; "g1"; end
162
+ protected
163
+ def g2; "g2"; end
164
+ private
165
+ def g3; "g3"; end
166
+ end
167
+
168
+ class I3
169
+ def h1; "h1"; end
170
+ end
171
+
172
+ And given a test case in 'test/incomplete_example_case.rb' as follows:
173
+
174
+ Covers 'incomplete_example.rb'
175
+
176
+ TestCase I1 do
177
+ method :f1 do
178
+ test "Returns a String"
179
+ end
180
+ method :f2 do
181
+ test "Returns a String"
182
+ end
183
+ end
184
+
185
+ TestCase I2 do
186
+ method :x1 do
187
+ test "Does not exist"
188
+ end
189
+ end
190
+
191
+ And we get the coverage information via CoverageAnalyer.
192
+
193
+ require 'lemon'
194
+
195
+ tests = ['test/incomplete_example_case.rb']
196
+
197
+ coverage = Lemon::CoverageAnalyzer.new(tests, :loadpath=>'lib')
198
+
199
+ Then we should see that there are 2 unconvered units, I1#f3 and I2#g1
200
+ because no testcase unit was defined for them and they are both public methods.
201
+
202
+ units = coverage.uncovered_units.map{ |u| u.to_s }
203
+
204
+ units.assert.include?('I1#f3')
205
+ units.assert.include?('I2#g1')
206
+
207
+ units.size.assert == 2
208
+
209
+ You might expect that 'I3#h1' would be in the uncovered units list as well,
210
+ since it is a public method and no test unit covers it. However, there is
211
+ no test case for I3 at all, so Lemon takes that to mean that I3 is of
212
+ no interest.
213
+
214
+ units.refute.include?('I3#h1')
215
+
216
+ But I3 will be listed in the uncovered cases list.
217
+
218
+ coverage.uncovered_cases == [I3]
219
+
220
+ Note that uncovered case methods can be included in the uncovered units list
221
+ by setting the +zealous+ option, which we will demonstrated later.
222
+
223
+ There should still be 3 covered units, I1#f1, I1#f2 and I2#x1.
224
+
225
+ coverage.covered_units.size.assert == 3
226
+
227
+ units = coverage.covered_units.map{ |u| u.to_s }
228
+
229
+ units.assert.include?('I1#f1')
230
+ units.assert.include?('I1#f2')
231
+ units.assert.include?('I2#x1')
232
+
233
+ But we will not find any covered units for class I2.
234
+
235
+ units.refute.include?('I2#g1')
236
+ units.refute.include?('I2#g2')
237
+ units.refute.include?('I2#g3')
238
+
239
+ Notice also that we defined a unit for I2#x1, a method that does not exist.
240
+ So it should be listed in the undefined units list.
241
+
242
+ coverage.undefined_units.size.assert == 1
243
+
244
+ units = coverage.undefined_units.map{ |u| u.to_s }
245
+
246
+ units.assert.include?('I2#x1')
247
+
248
+
249
+ == Core Extension Coverage
250
+
251
+ === Kernel Extensions
252
+
253
+ Given an example script in 'lib/extensions_example.rb' as follows:
254
+
255
+ module Kernel
256
+ def f1; "f1"; end
257
+ def f2; "f2"; end
258
+ def f3; "f3"; end
259
+ end
260
+
261
+ And given a test case in 'test/extensions_example_case.rb' as follows:
262
+
263
+ Covers 'extensions_example.rb'
264
+
265
+ TestCase Kernel do
266
+ method :f1 do
267
+ test do
268
+ fl.assert == "f1"
269
+ end
270
+ end
271
+ method :f2 do
272
+ test do
273
+ f2.assert == "f2"
274
+ end
275
+ end
276
+ end
277
+
278
+ And we get the coverage information via CoverageAnalyer.
279
+
280
+ require 'lemon'
281
+
282
+ tests = ['test/extensions_example_case.rb']
283
+
284
+ coverage = Lemon::CoverageAnalyzer.new(tests, :loadpath=>'lib')
285
+
286
+ Then we should see that there are two covered units, #f1 and #f2.
287
+
288
+ coverage.covered_units.size.assert == 2
289
+
290
+ units = coverage.covered_units.map{ |u| u.to_s }
291
+
292
+ units.assert.include?('Kernel#f1')
293
+ units.assert.include?('Kernel#f2')
294
+
295
+ units.refute.include?('Kernel#f3')
296
+
297
+ And we should see one unconvered unit, #f3.
298
+
299
+ coverage.uncovered_units.size.assert == 1
300
+
301
+ units = coverage.uncovered_units.map{ |u| u.to_s }
302
+
303
+ units.assert.include?('Kernel#f3')
304
+
305
+ There should be zero uncovered cases.
306
+
307
+ coverage.uncovered_cases == []
308
+
309
+ And zero undefined unit.
310
+
311
+ coverage.undefined_units == []
312
+
313
+
314
+