quarry 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +40 -3
- data/MANIFEST +290 -78
- data/README +51 -37
- data/RELEASE +12 -0
- data/VERSION +1 -1
- data/bin/quarry +117 -0
- data/bin/quarry-doc +26 -0
- data/bin/ruby-break +10 -0
- data/bin/{xact-ruby → ruby-xacto} +0 -0
- data/doc/assets/images/clipboard.jpg +0 -0
- data/doc/assets/images/clipboard2.png +0 -0
- data/doc/assets/images/darksilver.png +0 -0
- data/doc/assets/images/icon/book.jpg +0 -0
- data/doc/assets/images/icon/download.gif +0 -0
- data/doc/assets/images/icon/letter_r.png +0 -0
- data/doc/assets/images/icon/license.png +0 -0
- data/doc/assets/images/icon/software.png +0 -0
- data/doc/assets/images/icon/source.png +0 -0
- data/doc/assets/images/miner.jpg +0 -0
- data/doc/assets/images/rbrylmtrx.png +0 -0
- data/doc/assets/images/ruby.gif +0 -0
- data/doc/assets/images/runneth.png +0 -0
- data/doc/assets/images/silver.gif +0 -0
- data/doc/assets/images/test.jpg +0 -0
- data/doc/assets/jquery/jquery.js +1 -0
- data/doc/assets/jquery/jquery.tabs.js +1 -0
- data/doc/assets/rdoc_ad.html +12 -0
- data/doc/assets/styles/index.css +138 -0
- data/doc/guide/stubs.md +125 -0
- data/doc/index.html +285 -0
- data/doc/log/bstats/stats.html +39 -0
- data/doc/log/notes.xml +32 -0
- data/doc/log/stats.html +25 -0
- data/doc/log/stats.log +14 -0
- data/doc/log/syntax.log +0 -0
- data/doc/rdoc/classes/Assertion/False.html +151 -106
- data/doc/rdoc/classes/Assertion/True.html +128 -113
- data/doc/rdoc/classes/Assertion.html +147 -77
- data/doc/rdoc/classes/Kernel.html +84 -65
- data/doc/rdoc/classes/Method.html +123 -92
- data/doc/rdoc/classes/Object.html +468 -115
- data/doc/rdoc/classes/Quarry/Break.html +231 -0
- data/doc/rdoc/classes/Quarry/Command.html +443 -0
- data/doc/rdoc/classes/Quarry/Extract.html +215 -0
- data/doc/rdoc/classes/Quarry/MethodProbe.html +203 -145
- data/doc/rdoc/classes/Quarry/Mock/Delegator.html +179 -0
- data/doc/rdoc/classes/Quarry/Mock/Setter.html +175 -0
- data/doc/rdoc/classes/Quarry/Mock.html +211 -67
- data/doc/rdoc/classes/Quarry/Spec/Comment.html +237 -0
- data/doc/rdoc/classes/Quarry/Spec/Config.html +257 -0
- data/doc/rdoc/classes/Quarry/Spec/Context.html +154 -0
- data/doc/rdoc/classes/Quarry/Spec/Document.html +382 -0
- data/doc/rdoc/classes/Quarry/Spec/Header.html +195 -0
- data/doc/rdoc/classes/Quarry/Spec/Macro.html +166 -0
- data/doc/rdoc/classes/Quarry/Spec/Markup.html +279 -0
- data/doc/rdoc/classes/Quarry/Spec/Reporter/DotProgress.html +234 -0
- data/doc/rdoc/classes/Quarry/Spec/Reporter/Summary.html +294 -0
- data/doc/rdoc/classes/Quarry/Spec/Reporter/Verbatim.html +311 -0
- data/doc/rdoc/classes/Quarry/Spec/Runner.html +352 -0
- data/doc/rdoc/classes/Quarry/Spec/Step.html +190 -0
- data/doc/rdoc/classes/Quarry/Spec/Template.html +205 -0
- data/doc/rdoc/classes/Quarry/Stub/Delegator.html +179 -0
- data/doc/rdoc/classes/Quarry/Stub/Setter.html +175 -0
- data/doc/rdoc/classes/Quarry/Stub.html +224 -0
- data/doc/rdoc/classes/Quarry.html +153 -154
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +126 -76
- data/doc/rdoc/files/COPYING.html +84 -73
- data/doc/rdoc/files/README.html +135 -111
- data/doc/rdoc/files/RELEASE.html +122 -0
- data/doc/rdoc/files/VERSION.html +85 -74
- data/doc/rdoc/files/bin/quarry-doc.html +109 -0
- data/doc/rdoc/files/bin/quarry.html +109 -0
- data/doc/rdoc/files/bin/ruby-break.html +108 -0
- data/doc/rdoc/files/bin/ruby-xacto.html +101 -0
- data/doc/rdoc/files/lib/quarry/assert_rb.html +155 -0
- data/doc/rdoc/files/lib/quarry/break_rb.html +101 -0
- data/doc/rdoc/files/lib/quarry/extract_rb.html +108 -0
- data/doc/rdoc/files/lib/quarry/loadmonitor_rb.html +80 -71
- data/doc/rdoc/files/lib/quarry/spec/config_rb.html +101 -0
- data/doc/rdoc/files/lib/quarry/spec/context_rb.html +101 -0
- data/doc/rdoc/files/lib/quarry/spec/document_rb.html +111 -0
- data/doc/rdoc/files/lib/quarry/spec/markup_rb.html +108 -0
- data/doc/rdoc/files/lib/quarry/spec/reporter/dotprogress_rb.html +108 -0
- data/doc/rdoc/files/lib/quarry/spec/reporter/summary_rb.html +108 -0
- data/doc/rdoc/files/lib/quarry/spec/reporter/verbatim_rb.html +108 -0
- data/doc/rdoc/files/lib/quarry/spec/reporter_rb.html +109 -0
- data/doc/rdoc/files/lib/quarry/spec/runner_rb.html +109 -0
- data/doc/rdoc/files/lib/quarry/spec/step_rb.html +101 -0
- data/doc/rdoc/files/lib/quarry/spec/template_rhtml.html +228 -0
- data/doc/rdoc/files/lib/quarry/spec_rb.html +113 -0
- data/doc/rdoc/files/lib/quarry/stub/mock_rb.html +101 -0
- data/doc/rdoc/files/lib/quarry/stub/probe_rb.html +122 -0
- data/doc/rdoc/files/lib/quarry/stub/spec_txt.html +118 -0
- data/doc/rdoc/files/lib/quarry/stub/stub_rb.html +101 -0
- data/doc/rdoc/fr_class_index.html +48 -52
- data/doc/rdoc/fr_file_index.html +47 -57
- data/doc/rdoc/fr_method_index.html +109 -69
- data/doc/rdoc/index.html +12 -14
- data/doc/rdoc/rdoc-style.css +154 -121
- data/doc/ri/Assertion/False/cdesc-False.yaml +5 -3
- data/doc/ri/Assertion/True/cdesc-True.yaml +4 -2
- data/doc/ri/Assertion/True/message-c.yaml +2 -2
- data/doc/ri/Assertion/True/message-i.yaml +1 -1
- data/doc/ri/Assertion/True/method_missing-i.yaml +4 -3
- data/doc/ri/Assertion/cdesc-Assertion.yaml +24 -1
- data/doc/ri/Object/assert%21-i.yaml +7 -4
- data/doc/ri/Object/assert-i.yaml +3 -2
- data/doc/ri/Object/assert_raises%21-i.yaml +12 -0
- data/doc/ri/Object/assert_raises-i.yaml +15 -0
- data/doc/ri/Object/cdesc-Object.yaml +24 -2
- data/doc/ri/{Quarry/Design/Specification/outline-i.yaml → Object/mock-i.yaml} +4 -4
- data/doc/ri/Object/refute-i.yaml +13 -0
- data/doc/ri/Object/refute_raises-i.yaml +17 -0
- data/doc/ri/Object/remove-i.yaml +12 -0
- data/doc/ri/{Quarry/Design/check-c.yaml → Object/should-i.yaml} +4 -4
- data/doc/ri/Object/should_not-i.yaml +12 -0
- data/doc/ri/Object/should_not_raise-i.yaml +12 -0
- data/doc/ri/Object/should_raise-i.yaml +12 -0
- data/doc/ri/{Quarry/Mock/Object/mock-c.yaml → Object/stub-i.yaml} +5 -5
- data/doc/ri/{Module/cdesc-Module.yaml → Quarry/Break/cdesc-Break.yaml} +10 -8
- data/doc/ri/Quarry/Break/edit-i.yaml +11 -0
- data/doc/ri/Quarry/Break/new-c.yaml +11 -0
- data/doc/ri/Quarry/Extract/cdesc-Extract.yaml +26 -0
- data/doc/ri/Quarry/Extract/create_test-i.yaml +12 -0
- data/doc/ri/Quarry/Extract/extract_test_from_file-i.yaml +12 -0
- data/doc/ri/Quarry/Extract/test_extract-i.yaml +18 -0
- data/doc/ri/Quarry/Mock/Delegator/cdesc-Delegator.yaml +20 -0
- data/doc/ri/Quarry/{Design/Specification/Context → Mock/Delegator}/method_missing-i.yaml +2 -2
- data/doc/ri/Quarry/{Design/specification-c.yaml → Mock/Delegator/new-c.yaml} +3 -3
- data/doc/ri/{Module/method_added-i.yaml → Quarry/Mock/Setter/%3d%3d-i.yaml} +3 -3
- data/doc/ri/Quarry/Mock/Setter/cdesc-Setter.yaml +18 -0
- data/doc/ri/Quarry/Mock/Setter/new-c.yaml +10 -0
- data/doc/ri/Quarry/Mock/__table__-i.yaml +11 -0
- data/doc/ri/Quarry/Mock/cdesc-Mock.yaml +17 -7
- data/doc/ri/Quarry/Mock/method_missing-i.yaml +12 -0
- data/doc/ri/Quarry/{Design/outline-c.yaml → Mock/new-c.yaml} +2 -2
- data/doc/ri/Quarry/Spec/Comment/cdesc-Comment.yaml +33 -0
- data/doc/ri/Quarry/Spec/Comment/macro%3f-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Comment/new-c.yaml +10 -0
- data/doc/ri/Quarry/Spec/Comment/type-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Config/after-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Config/after_spec-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Config/before-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Config/before_spec-i.yaml +12 -0
- data/doc/ri/Quarry/{Design/Specification/Context/cdesc-Context.yaml → Spec/Config/cdesc-Config.yaml} +11 -9
- data/doc/ri/Quarry/{Mock/Object/mocks-c.yaml → Spec/Config/new-c.yaml} +2 -2
- data/doc/ri/Quarry/Spec/Context/cdesc-Context.yaml +21 -0
- data/doc/ri/Quarry/{Design/specifications-c.yaml → Spec/Context/new-c.yaml} +2 -2
- data/doc/ri/Quarry/Spec/Document/cdesc-Document.yaml +76 -0
- data/doc/ri/Quarry/Spec/Document/generate-i.yaml +12 -0
- data/doc/ri/Quarry/{Mock/Object/echo-c.yaml → Spec/Document/new-c.yaml} +4 -4
- data/doc/ri/Quarry/Spec/Document/quiet%3f-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Document/require_rdoc-i.yaml +11 -0
- data/doc/ri/Quarry/Spec/Document/save-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Document/template-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Header/cdesc-Header.yaml +30 -0
- data/doc/ri/Quarry/Spec/Header/new-c.yaml +10 -0
- data/doc/ri/Quarry/Spec/Macro/cdesc-Macro.yaml +22 -0
- data/doc/ri/Quarry/Spec/Macro/new-c.yaml +10 -0
- data/doc/ri/Quarry/Spec/Markup/cdesc-Markup.yaml +31 -0
- data/doc/ri/Quarry/Spec/Markup/description-i.yaml +11 -0
- data/doc/ri/Quarry/Spec/Markup/new-c.yaml +11 -0
- data/doc/ri/Quarry/Spec/Markup/parse-i.yaml +11 -0
- data/doc/ri/Quarry/Spec/Markup/parse_section-i.yaml +11 -0
- data/doc/ri/Quarry/Spec/Reporter/DotProgress/cdesc-DotProgress.yaml +21 -0
- data/doc/ri/Quarry/{Design/Specification/Context/specifications-i.yaml → Spec/Reporter/DotProgress/report_intro-i.yaml} +2 -2
- data/doc/ri/Quarry/Spec/Reporter/DotProgress/report_step-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/DotProgress/report_summary-i.yaml +16 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/cdesc-Summary.yaml +31 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/report_comment-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/report_error-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/report_fail-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/report_header-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Summary/report_macro-i.yaml +10 -0
- data/doc/ri/Quarry/{Design/Specification/Context/before-i.yaml → Spec/Reporter/Summary/report_pass-i.yaml} +3 -3
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/cdesc-Verbatim.yaml +29 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_comment-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_error-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_fail-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_header-i.yaml +16 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_macro-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/Verbatim/report_pass-i.yaml +10 -0
- data/doc/ri/Quarry/Spec/Reporter/cdesc-Reporter.yaml +20 -0
- data/doc/ri/Quarry/Spec/Runner/cdesc-Runner.yaml +47 -0
- data/doc/ri/Quarry/{Design/Specification → Spec/Runner}/check-i.yaml +3 -3
- data/doc/ri/Quarry/Spec/Runner/check_spec-i.yaml +12 -0
- data/doc/ri/Quarry/{Design/Specification → Spec/Runner}/new-c.yaml +2 -2
- data/doc/ri/Quarry/Spec/Runner/run_step-i.yaml +12 -0
- data/doc/ri/Quarry/Spec/Step/cdesc-Step.yaml +30 -0
- data/doc/ri/Quarry/Spec/Step/new-c.yaml +10 -0
- data/doc/ri/Quarry/Spec/Template/cdesc-Template.yaml +31 -0
- data/doc/ri/Quarry/Spec/Template/new-c.yaml +11 -0
- data/doc/ri/Quarry/{Design/Specification/Context/after-i.yaml → Spec/Template/parse_template-i.yaml} +3 -3
- data/doc/ri/Quarry/Spec/cdesc-Spec.yaml +15 -0
- data/doc/ri/Quarry/Stub/Delegator/cdesc-Delegator.yaml +20 -0
- data/doc/ri/Quarry/Stub/Delegator/method_missing-i.yaml +10 -0
- data/doc/ri/Quarry/Stub/Delegator/new-c.yaml +10 -0
- data/doc/ri/Quarry/Stub/Setter/%3d%3d-i.yaml +10 -0
- data/doc/ri/Quarry/Stub/Setter/cdesc-Setter.yaml +18 -0
- data/doc/ri/Quarry/Stub/Setter/new-c.yaml +10 -0
- data/doc/ri/Quarry/Stub/__table__-i.yaml +11 -0
- data/doc/ri/Quarry/Stub/cdesc-Stub.yaml +23 -0
- data/doc/ri/Quarry/Stub/method_missing-i.yaml +11 -0
- data/doc/ri/Quarry/Stub/new-c.yaml +10 -0
- data/doc/ri/Quarry/cdesc-Quarry.yaml +2 -3
- data/doc/ri/created.rid +1 -1
- data/doc/spec/stub.html +394 -0
- data/lib/quarry/assert.rb +198 -0
- data/lib/quarry/break.rb +51 -0
- data/lib/quarry/extract.rb +135 -0
- data/lib/quarry/loadmonitor.rb +6 -1
- data/lib/quarry/spec/config.rb +32 -0
- data/lib/quarry/spec/context.rb +19 -0
- data/lib/quarry/spec/document.rb +130 -0
- data/lib/quarry/spec/markup.rb +85 -0
- data/lib/quarry/spec/reporter/dotprogress.rb +66 -0
- data/lib/quarry/spec/reporter/summary.rb +74 -0
- data/lib/quarry/spec/reporter/verbatim.rb +87 -0
- data/lib/quarry/spec/reporter.rb +74 -0
- data/lib/quarry/spec/runner.rb +127 -0
- data/lib/quarry/spec/step.rb +78 -0
- data/lib/quarry/spec/template.rhtml +116 -0
- data/lib/quarry/spec.rb +7 -0
- data/lib/quarry/stub/mock.rb +94 -0
- data/lib/quarry/{methodprobe.rb → stub/probe.rb} +0 -0
- data/lib/quarry/stub/spec.txt +113 -0
- data/lib/quarry/stub/stub.rb +93 -0
- data/meta/abstract +5 -0
- data/meta/authors +1 -0
- data/meta/created +1 -0
- data/meta/homepage +1 -0
- data/meta/requires +1 -0
- data/meta/summary +1 -0
- data/spec/basic.rd +20 -0
- data/spec/complex.rd +50 -0
- data/spec/mock.rd +53 -0
- data/spec/stub.rd +61 -0
- data/{lib/quarry → work/consider}/document.rb +0 -0
- data/work/consider/fixture.rb +153 -0
- data/{lib/quarry → work/deprecated}/assert/must.rb +1 -0
- data/{lib/quarry → work/deprecated}/assert/should.rb +0 -0
- data/work/deprecated/build.rb +82 -0
- data/work/deprecated/mock/file.rb +11 -0
- data/work/deprecated/mock/mock.0.rb +77 -0
- data/work/deprecated/overlay.rb +64 -0
- data/work/deprecated/spec.rb +195 -0
- data/work/deprecated/stub/stub.0.rb +180 -0
- data/work/deprecated/stub/stub.1.rb +114 -0
- data/work/deprecated/stub/test_stub.rb +66 -0
- data/work/deprecated/test/case.rb +141 -0
- data/work/sandbox/assert.rb +100 -0
- data/work/sandbox/bug.rb +49 -0
- data/work/sandbox/build/announce.rb +213 -0
- data/work/sandbox/build/check.rb +109 -0
- data/work/sandbox/build/gem.rb +235 -0
- data/work/sandbox/build/make.rb +118 -0
- data/work/sandbox/build/manpage.rb +201 -0
- data/work/sandbox/build/notes.rb +214 -0
- data/work/sandbox/build/pack.rb +228 -0
- data/work/sandbox/build/rdoc.rb +289 -0
- data/work/sandbox/build/rubyforge.rb +91 -0
- data/work/sandbox/build/sign.rb +241 -0
- data/work/sandbox/build/stamp.rb +37 -0
- data/work/sandbox/build/stats.rb +154 -0
- data/work/sandbox/build/svn.rb +193 -0
- data/work/sandbox/build/test.rb +521 -0
- data/work/sandbox/design.rb +200 -0
- data/work/sandbox/iface_scanner.rb +102 -0
- data/work/sandbox/testunit/assertions/assert_has_keys.rb +38 -0
- data/work/sandbox/testunit/assertions/assert_has_only_keys.rb +38 -0
- data/work/sandbox/testunit/unit.rb +104 -0
- data/work/sandbox/unitspec.rb +54 -0
- data/work/sandbox/x_isotest.rb +532 -0
- metadata +318 -93
- data/METADATA +0 -22
- data/NEWS +0 -8
- data/bin/rubybreak +0 -3
- data/demo/spec/demo_check.rb +0 -21
- data/demo/spec/demo_outline.rb +0 -25
- data/demo/test/demo_run.rb +0 -21
- data/doc/manual.html2 +0 -1416
- data/doc/rdoc/classes/Module.html +0 -165
- data/doc/rdoc/classes/Quarry/Design/Specification/Context.html +0 -174
- data/doc/rdoc/classes/Quarry/Design/Specification.html +0 -265
- data/doc/rdoc/classes/Quarry/Design.html +0 -170
- data/doc/rdoc/classes/Quarry/Mock/Object.html +0 -276
- data/doc/rdoc/files/MANIFEST.html +0 -630
- data/doc/rdoc/files/METADATA.html +0 -92
- data/doc/rdoc/files/NEWS.html +0 -99
- data/doc/rdoc/files/bin/rubybreak.html +0 -96
- data/doc/rdoc/files/bin/xact-ruby.html +0 -92
- data/doc/rdoc/files/lib/quarry/assert/must_rb.html +0 -96
- data/doc/rdoc/files/lib/quarry/assert/should_rb.html +0 -96
- data/doc/rdoc/files/lib/quarry/assertion_rb.html +0 -96
- data/doc/rdoc/files/lib/quarry/breakout_rb.html +0 -144
- data/doc/rdoc/files/lib/quarry/design/spec_rb.html +0 -100
- data/doc/rdoc/files/lib/quarry/document_rb.html +0 -92
- data/doc/rdoc/files/lib/quarry/methodprobe_rb.html +0 -111
- data/doc/rdoc/files/lib/quarry/mock/object_rb.html +0 -123
- data/doc/rdoc/files/lib/quarry/mockery_rb.html +0 -115
- data/doc/ri/Module/doc-i.yaml +0 -16
- data/doc/ri/Quarry/Design/Specification/cdesc-Specification.yaml +0 -44
- data/doc/ri/Quarry/Design/cdesc-Design.yaml +0 -22
- data/doc/ri/Quarry/Mock/Object/cdesc-Object.yaml +0 -52
- data/doc/ri/Quarry/Mock/Object/keys-c.yaml +0 -12
- data/doc/ri/Quarry/Mock/Object/spin-c.yaml +0 -12
- data/doc/ri/Quarry/Mockery-i.yaml +0 -12
- data/lib/quarry/assertion.rb +0 -95
- data/lib/quarry/breakout.rb +0 -45
- data/lib/quarry/design/spec.rb +0 -197
- data/lib/quarry/mock/object.rb +0 -169
- data/lib/quarry/mockery.rb +0 -85
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'clio/facets/string'
|
|
2
|
+
require 'clio/ansicode'
|
|
3
|
+
|
|
4
|
+
module Quarry
|
|
5
|
+
|
|
6
|
+
module Spec
|
|
7
|
+
|
|
8
|
+
# = Reporter
|
|
9
|
+
#
|
|
10
|
+
# Serves as the base class for all other specification
|
|
11
|
+
# output formats.
|
|
12
|
+
#
|
|
13
|
+
class Reporter
|
|
14
|
+
ANSICode = Clio::ANSICode
|
|
15
|
+
|
|
16
|
+
attr :steps
|
|
17
|
+
attr :pass
|
|
18
|
+
attr :fail
|
|
19
|
+
attr :error
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@specs = 0
|
|
23
|
+
@steps = 0
|
|
24
|
+
@pass = []
|
|
25
|
+
@fail = []
|
|
26
|
+
@error = []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def report_intro
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def report_start(spec)
|
|
33
|
+
@specs += 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def report_header(step)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def report_comment(step)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def report_mode(step)
|
|
43
|
+
report_literal(step)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def report_step(step)
|
|
47
|
+
@steps += 1
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def report_pass(step)
|
|
51
|
+
@pass << step
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def report_fail(step, assertion)
|
|
55
|
+
@fail << [step, assertion]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def report_error(step, exception)
|
|
59
|
+
raise exception if $DEBUG
|
|
60
|
+
@error << [step, exception]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def report_end(spec)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def report_summary
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'quarry/assert'
|
|
2
|
+
require 'quarry/spec/context'
|
|
3
|
+
|
|
4
|
+
module Quarry
|
|
5
|
+
|
|
6
|
+
module Spec
|
|
7
|
+
|
|
8
|
+
# = Specificaton Runner
|
|
9
|
+
#
|
|
10
|
+
# The Runner class loops through a set of specifications
|
|
11
|
+
# and executes each one in turn.
|
|
12
|
+
#
|
|
13
|
+
# The current working directory is changed to that of the
|
|
14
|
+
# specification script's. So any relative file references
|
|
15
|
+
# within a spec must take that into account.
|
|
16
|
+
#
|
|
17
|
+
class Runner
|
|
18
|
+
|
|
19
|
+
# Quarry::Spec::Runner.configure do
|
|
20
|
+
# def setup(spec)
|
|
21
|
+
# ...
|
|
22
|
+
# end
|
|
23
|
+
# def teardown(spec)
|
|
24
|
+
# ...
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
#def self.configure(plugin=nil, &block)
|
|
28
|
+
# if block_given?
|
|
29
|
+
# m = Module.new(&block)
|
|
30
|
+
# m.extend m
|
|
31
|
+
# @config << m
|
|
32
|
+
# end
|
|
33
|
+
# if plugin
|
|
34
|
+
# @config << plugin
|
|
35
|
+
# end
|
|
36
|
+
#end
|
|
37
|
+
|
|
38
|
+
attr :specs
|
|
39
|
+
attr :output
|
|
40
|
+
|
|
41
|
+
attr :context
|
|
42
|
+
#attr :count
|
|
43
|
+
|
|
44
|
+
# New Specification
|
|
45
|
+
def initialize(specs, output=nil)
|
|
46
|
+
@specs = [specs].flatten
|
|
47
|
+
@output = output || Spec::Reporter::DotProgress.new #(self)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Each spec gets it's own context.
|
|
51
|
+
def check
|
|
52
|
+
output.report_intro
|
|
53
|
+
# loop through each specification and run it
|
|
54
|
+
specs.each do |spec|
|
|
55
|
+
# create a run context for the spec
|
|
56
|
+
@context = Context.new
|
|
57
|
+
# run the specification
|
|
58
|
+
check_spec(spec)
|
|
59
|
+
end
|
|
60
|
+
output.report_summary
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Run a specification.
|
|
64
|
+
#
|
|
65
|
+
def check_spec(spec)
|
|
66
|
+
#report(spec.description)
|
|
67
|
+
|
|
68
|
+
# pretty sure this is the thing to do
|
|
69
|
+
Dir.chdir(File.dirname(spec.file)) do
|
|
70
|
+
|
|
71
|
+
output.report_start(spec)
|
|
72
|
+
|
|
73
|
+
# TODO <-- plugin in here start (how to set?)
|
|
74
|
+
#context.instance_eval(&spec.given) if spec.given
|
|
75
|
+
|
|
76
|
+
spec.steps.each do |step|
|
|
77
|
+
case step
|
|
78
|
+
when Header
|
|
79
|
+
output.report_header(step)
|
|
80
|
+
when Macro
|
|
81
|
+
case step.type
|
|
82
|
+
when :before
|
|
83
|
+
@before = step.code
|
|
84
|
+
when :after
|
|
85
|
+
@after = step.code
|
|
86
|
+
else
|
|
87
|
+
context.instance_eval(step.code, spec.file, step.lineno)
|
|
88
|
+
end
|
|
89
|
+
output.report_macro(step)
|
|
90
|
+
when Comment
|
|
91
|
+
output.report_comment(step)
|
|
92
|
+
else
|
|
93
|
+
run_step(spec, step) if step.code
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# TODO <-- plugin in here end
|
|
98
|
+
#context.instance_eval(&spec.complete) if spec.complete
|
|
99
|
+
|
|
100
|
+
output.report_end(spec)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Run a specification step.
|
|
105
|
+
#
|
|
106
|
+
def run_step(spec, step)
|
|
107
|
+
output.report_step(step)
|
|
108
|
+
# TODO: Would spec.before + spec.code be better?
|
|
109
|
+
context.instance_eval(@before, spec.file) if @before
|
|
110
|
+
begin
|
|
111
|
+
context.instance_eval(step.code, spec.file, step.lineno)
|
|
112
|
+
output.report_pass(step)
|
|
113
|
+
rescue Assertion => error
|
|
114
|
+
output.report_fail(step, error)
|
|
115
|
+
rescue Exception => error
|
|
116
|
+
output.report_error(step, error)
|
|
117
|
+
ensure
|
|
118
|
+
context.instance_eval(@after, spec.file) if @after
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end#class Runner
|
|
123
|
+
|
|
124
|
+
end#module Spec
|
|
125
|
+
|
|
126
|
+
end#module Quarry
|
|
127
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Quarry
|
|
2
|
+
|
|
3
|
+
module Spec
|
|
4
|
+
|
|
5
|
+
# = Step
|
|
6
|
+
#
|
|
7
|
+
class Step
|
|
8
|
+
attr :parent
|
|
9
|
+
attr :code
|
|
10
|
+
attr :lineno
|
|
11
|
+
|
|
12
|
+
def initialize(parent, code, lineno)
|
|
13
|
+
@parent = parent
|
|
14
|
+
@code = code.rstrip
|
|
15
|
+
@lineno = lineno
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
alias_method :spec, :parent
|
|
19
|
+
|
|
20
|
+
#def description
|
|
21
|
+
# alias_method :description, :text
|
|
22
|
+
#end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# = Macro
|
|
26
|
+
#
|
|
27
|
+
class Macro < Step
|
|
28
|
+
attr :type
|
|
29
|
+
def initialize(parent, code, lineno, type)
|
|
30
|
+
super(parent, code, lineno)
|
|
31
|
+
@type = type
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# = Header
|
|
36
|
+
#
|
|
37
|
+
class Header
|
|
38
|
+
attr :parent
|
|
39
|
+
attr :text
|
|
40
|
+
attr :lineno
|
|
41
|
+
|
|
42
|
+
def initialize(parent, text, lineno)
|
|
43
|
+
@parent = parent
|
|
44
|
+
@text = text.strip
|
|
45
|
+
@lineno = lineno
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
alias_method :spec, :parent
|
|
49
|
+
alias_method :description, :text
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# = Comment
|
|
53
|
+
#
|
|
54
|
+
class Comment
|
|
55
|
+
attr :parent
|
|
56
|
+
attr :text
|
|
57
|
+
attr :lineno
|
|
58
|
+
|
|
59
|
+
def initialize(parent, text, lineno)
|
|
60
|
+
@parent = parent
|
|
61
|
+
@text = text.strip
|
|
62
|
+
@lineno = lineno
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
alias_method :spec, :parent
|
|
66
|
+
alias_method :description, :text
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
def type
|
|
70
|
+
/^(\w{1,9})[:]/i =~ text
|
|
71
|
+
$1.downcase.to_sym if $1
|
|
72
|
+
end
|
|
73
|
+
alias_method :macro?, :type
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end#module Spec
|
|
77
|
+
|
|
78
|
+
end#module Quarry
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title><%= title %></title>
|
|
4
|
+
|
|
5
|
+
<link rel="StyleSheet" href="<%= css %>" type="text/css">
|
|
6
|
+
|
|
7
|
+
<script language="javascript" src="../assets/scripts/jquery.js"></script>
|
|
8
|
+
|
|
9
|
+
<script type="text/javascript">
|
|
10
|
+
/*****************************************************************
|
|
11
|
+
* $.toc()
|
|
12
|
+
* by rebecca murphey
|
|
13
|
+
* rmurphey gmail com
|
|
14
|
+
*
|
|
15
|
+
* This function is called on its own and takes as an argument
|
|
16
|
+
* a list of selectors with which it will build a table of
|
|
17
|
+
* contents.
|
|
18
|
+
*
|
|
19
|
+
* The first selector will make up the top level of the TOC;
|
|
20
|
+
* the second selector will make up the second level of the TOC;
|
|
21
|
+
* etc.
|
|
22
|
+
*
|
|
23
|
+
* This function returns a div containing nested unordered lists;
|
|
24
|
+
* each list item is linked to an anchor tag added before the item
|
|
25
|
+
* on the page.
|
|
26
|
+
*
|
|
27
|
+
* usage: $.toc('h1,h2,h3').prependTo('body');
|
|
28
|
+
************************************************************************/
|
|
29
|
+
(function($) {
|
|
30
|
+
$.toc = function(tocList) {
|
|
31
|
+
$(tocList).addClass('jquery-toc');
|
|
32
|
+
var tocListArray = tocList.split(',');
|
|
33
|
+
$.each(tocListArray, function(i,v) { tocListArray[i] = $.trim(v); });
|
|
34
|
+
var $elements = $('.jquery-toc');
|
|
35
|
+
$('body').append('<div></div>');
|
|
36
|
+
var $toc = $('body div:last');
|
|
37
|
+
var lastLevel = 1;
|
|
38
|
+
$toc.append('<ul class="jquery-toc-1"></ul>');
|
|
39
|
+
$elements.each(function() {
|
|
40
|
+
var $e = $(this);
|
|
41
|
+
var text = $e.text();
|
|
42
|
+
var anchor = text.replace(/ /g,'-');
|
|
43
|
+
$e.before('<a name="' + anchor + '"></a>');
|
|
44
|
+
var level;
|
|
45
|
+
$.each(tocListArray, function(i,v) {
|
|
46
|
+
if (v.match(' ')) {
|
|
47
|
+
var vArray = v.split(' ');
|
|
48
|
+
var e = vArray[vArray.length - 1];
|
|
49
|
+
} else { e = v; }
|
|
50
|
+
if ($e.is(e)) { level = i+1; }
|
|
51
|
+
});
|
|
52
|
+
var className = 'jquery-toc-' + level;
|
|
53
|
+
var li = '<li><a href="#' + anchor + '">' + text + '</a></li>';
|
|
54
|
+
if (level == lastLevel) {
|
|
55
|
+
$('ul.' + className + ':last',$toc).append(li);
|
|
56
|
+
} else if (level > lastLevel) {
|
|
57
|
+
var parentLevel = level - 1;
|
|
58
|
+
var parentClassName = 'jquery-toc-' + parentLevel;
|
|
59
|
+
$('ul.' + parentClassName + ':last',$toc).
|
|
60
|
+
append('<ul class="' + className + '"></ul>');
|
|
61
|
+
$('ul.' + className + ':last',$toc).append(li);
|
|
62
|
+
} else if (level < lastLevel) {
|
|
63
|
+
$('ul.' + className + ':last',$toc).append(li);
|
|
64
|
+
}
|
|
65
|
+
lastLevel = level;
|
|
66
|
+
});
|
|
67
|
+
var $toc_ul = $('ul.jquery-toc-1',$toc);
|
|
68
|
+
$toc.remove();
|
|
69
|
+
return($toc_ul);
|
|
70
|
+
}
|
|
71
|
+
})(jQuery);
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<script>
|
|
75
|
+
$(document).ready(function(){
|
|
76
|
+
$.toc('#content h1,h2,h3,h4').appendTo('.toc');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function toc_toggle() {
|
|
80
|
+
$('#toc_side').toggle();
|
|
81
|
+
};
|
|
82
|
+
</script>
|
|
83
|
+
</head>
|
|
84
|
+
|
|
85
|
+
<body>
|
|
86
|
+
|
|
87
|
+
<!-- Side Table of Contents -->
|
|
88
|
+
<div id="sidebar" style="position: fixed; top: 10; right: 10; background: white;">
|
|
89
|
+
<a href="javascript: toc_toggle();">
|
|
90
|
+
<img src="img/icon/book.jpg" height="30px;" style="border: none;" alt="TOC" align="right"/>
|
|
91
|
+
</a>
|
|
92
|
+
|
|
93
|
+
<div id="toc_side" class="toc">
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div id="container">
|
|
98
|
+
<div id="header">
|
|
99
|
+
<img src="img/icon/book.jpg" align="left" style="padding-right: 10px;" alt=""/>
|
|
100
|
+
|
|
101
|
+
<h1><%= title %></h1>
|
|
102
|
+
<h1>Table of Contents</h1>
|
|
103
|
+
|
|
104
|
+
<div class="toc">
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div id="content">
|
|
109
|
+
<%= spec %>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
</body>
|
|
114
|
+
|
|
115
|
+
</html>
|
|
116
|
+
|
data/lib/quarry/spec.rb
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Quarry
|
|
2
|
+
|
|
3
|
+
# = Mock
|
|
4
|
+
#
|
|
5
|
+
class Mock < Module
|
|
6
|
+
attr :object
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
super()
|
|
10
|
+
@table = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
def __table__ ; @table ; end
|
|
15
|
+
|
|
16
|
+
# TODO: Ruby has retry, but I need continue!
|
|
17
|
+
def method_missing(meth, *args, &block)
|
|
18
|
+
table = @table
|
|
19
|
+
interface = [meth, args, block_given?]
|
|
20
|
+
|
|
21
|
+
table[interface] = nil
|
|
22
|
+
|
|
23
|
+
define_method(meth) do |*args|
|
|
24
|
+
result = super
|
|
25
|
+
result.assert == table[interface]
|
|
26
|
+
return result
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Setter.new(table, interface)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
class Setter
|
|
34
|
+
def initialize(table, interface)
|
|
35
|
+
@table = table
|
|
36
|
+
@interface = interface
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def ==(result)
|
|
40
|
+
@table[@interface] = result
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# = Mock::Delegator
|
|
45
|
+
#
|
|
46
|
+
class Delegator
|
|
47
|
+
instance_methods(true).each{ |m| protected m unless m.to_s =~ /^__/ }
|
|
48
|
+
|
|
49
|
+
def initialize(object, mock_module)
|
|
50
|
+
@instance_delegate = object
|
|
51
|
+
extend(mock_module)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def method_missing(s, *a, &b)
|
|
55
|
+
@instance_delegate.__send__(s, *a, &b)
|
|
56
|
+
end
|
|
57
|
+
end#class Delegator
|
|
58
|
+
|
|
59
|
+
end#class Mock
|
|
60
|
+
|
|
61
|
+
class ::Object
|
|
62
|
+
# Create mock object.
|
|
63
|
+
def mock(mock_module=nil)
|
|
64
|
+
if mock_module
|
|
65
|
+
Mock::Delegator.new(self, mock_module)
|
|
66
|
+
else
|
|
67
|
+
@_mock ||= Mock.new
|
|
68
|
+
extend(@_mock)
|
|
69
|
+
@_mock
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# We can't remove the module per-say. So we have to
|
|
74
|
+
# just neuter it. This is a very weak solution, but
|
|
75
|
+
# it will suffice for the moment.
|
|
76
|
+
#--
|
|
77
|
+
# TODO: Use Carats for #unmix.
|
|
78
|
+
#++
|
|
79
|
+
def remove(mock_module=nil)
|
|
80
|
+
mock_module ||= @_mock
|
|
81
|
+
obj = self
|
|
82
|
+
mod = Module.new
|
|
83
|
+
mock_module.__table__.each do |interface, result|
|
|
84
|
+
meth = interface[0]
|
|
85
|
+
mod.module_eval do
|
|
86
|
+
define_method(meth, &obj.class.instance_method(meth).bind(obj))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
extend(mod)
|
|
90
|
+
end
|
|
91
|
+
end#class ::Object
|
|
92
|
+
|
|
93
|
+
end#module Quarry
|
|
94
|
+
|
|
File without changes
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
Testing the Number 4
|
|
3
|
+
====================
|
|
4
|
+
|
|
5
|
+
4.modulo(1) => 0
|
|
6
|
+
4.modulo(2) => 0
|
|
7
|
+
4.modulo(3) => 1
|
|
8
|
+
4.modulo(4) => 0
|
|
9
|
+
4.modulo(5) => 4
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Using Mocha
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
4.stubs(:modulo).with(1).returns(0)
|
|
16
|
+
4.stubs(:modulo).with(2).returns(0)
|
|
17
|
+
4.stubs(:modulo).with(3).returns(1)
|
|
18
|
+
4.stubs(:modulo).with(4).returns(0)
|
|
19
|
+
4.stubs(:modulo).with(5).returns(4)
|
|
20
|
+
|
|
21
|
+
Using RR
|
|
22
|
+
--------
|
|
23
|
+
|
|
24
|
+
stub(4).modulo(1){ 0 }
|
|
25
|
+
stub(4).modulo(2){ 0 }
|
|
26
|
+
stub(4).modulo(3){ 1 }
|
|
27
|
+
stub(4).modulo(4){ 0 }
|
|
28
|
+
stub(4).modulo(5){ 4 }
|
|
29
|
+
|
|
30
|
+
Using Quarry "Old-Style"
|
|
31
|
+
------------------------
|
|
32
|
+
|
|
33
|
+
4.stub.modulo(1) == 0
|
|
34
|
+
4.stub.modulo(2) == 0
|
|
35
|
+
4.stub.modulo(3) == 1
|
|
36
|
+
4.stub.modulo(4) == 0
|
|
37
|
+
4.stub.modulo(5) == 4
|
|
38
|
+
|
|
39
|
+
The #== operator is a shorthand for #returns. We could also use #returns_map:
|
|
40
|
+
|
|
41
|
+
4.stub.modulo.equate(1 => 0, 2 => 0, 3 => 1, 4 => 0, 5 => 4)
|
|
42
|
+
|
|
43
|
+
Generalizing...
|
|
44
|
+
|
|
45
|
+
Integer.stub.modulo(1) == ?
|
|
46
|
+
|
|
47
|
+
Integer.stub.modulo == lamba{ |x| divmod(x)[0] }
|
|
48
|
+
|
|
49
|
+
This testing with double entry bookkeeping. In other words, we are testing one implementation
|
|
50
|
+
by comparing it to another implementation we consider equivalent, at lease within the
|
|
51
|
+
limited range of inputs we are considering at the moment.
|
|
52
|
+
|
|
53
|
+
Now what are we really doing in all of these cases? Singleton methods:
|
|
54
|
+
|
|
55
|
+
def 4.modulo(x)
|
|
56
|
+
case x
|
|
57
|
+
when 1 then 0
|
|
58
|
+
...
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Oops. We can't do that to for "immutable" classes. But that's the idea anyway.
|
|
62
|
+
|
|
63
|
+
So what are we doing with stubs? Well, after the fact we inpsect the results.
|
|
64
|
+
|
|
65
|
+
r = 4.modulo(1)
|
|
66
|
+
|
|
67
|
+
r.assert == 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
What is a Mock?
|
|
71
|
+
---------------
|
|
72
|
+
|
|
73
|
+
Stub with attitude.
|
|
74
|
+
|
|
75
|
+
A better term for Mock might be "inspector".
|
|
76
|
+
|
|
77
|
+
In*SPEC*tor
|
|
78
|
+
|
|
79
|
+
though the modus operandi of an inspector is really as an:
|
|
80
|
+
|
|
81
|
+
Ex*SPEC*tor
|
|
82
|
+
|
|
83
|
+
Stubs stand in for things. Mocks stand in for things too. But Mocks
|
|
84
|
+
insist on being treated in certain ways.
|
|
85
|
+
|
|
86
|
+
# oops
|
|
87
|
+
4.modulo(1) #=> 1
|
|
88
|
+
|
|
89
|
+
4.mock.modulo(1) == 0
|
|
90
|
+
|
|
91
|
+
4.modulo(1) #=> raises Assertion error
|
|
92
|
+
|
|
93
|
+
Why no expections for "receives"? This couples tests too tightly to implementations.
|
|
94
|
+
We don't care how it behaves on the inside, only how it behaves on the outside.
|
|
95
|
+
Consideration of "inside" behavior is the domain of benchmarkers.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
Yes, 'stub' and 'mock' are STUPID words.
|
|
99
|
+
|
|
100
|
+
Why? Because they "Pokemon" (or "D&D" for you old-schoolers). They were coined
|
|
101
|
+
in the forge of geekdom. Now let's grow up and call things for what they DO.
|
|
102
|
+
|
|
103
|
+
"Stubbing"
|
|
104
|
+
|
|
105
|
+
4.define.modulo(1) == 0
|
|
106
|
+
|
|
107
|
+
"Mocking"
|
|
108
|
+
|
|
109
|
+
4.expect.modulo(1) == 0
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Quarry
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
class Stub < Module
|
|
5
|
+
attr :object
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
super()
|
|
9
|
+
@table = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
def __table__ ; @table ; end
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
def method_missing(meth, *args, &block)
|
|
17
|
+
table = @table
|
|
18
|
+
interface = [meth, args, block_given?]
|
|
19
|
+
|
|
20
|
+
table[interface] = nil
|
|
21
|
+
|
|
22
|
+
define_method(meth) do |*args|
|
|
23
|
+
table[interface]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Setter.new(table, interface)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
class Setter
|
|
31
|
+
def initialize(table, interface)
|
|
32
|
+
@table = table
|
|
33
|
+
@interface = interface
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ==(result)
|
|
37
|
+
@table[@interface] = result
|
|
38
|
+
end
|
|
39
|
+
end#class Setter
|
|
40
|
+
|
|
41
|
+
# = Stub::Delegator
|
|
42
|
+
#
|
|
43
|
+
class Delegator
|
|
44
|
+
instance_methods(true).each{ |m| protected m unless m.to_s =~ /^__/ }
|
|
45
|
+
|
|
46
|
+
def initialize(object, stub_module)
|
|
47
|
+
@instance_delegate = object
|
|
48
|
+
extend(stub_module)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def method_missing(s, *a, &b)
|
|
52
|
+
@instance_delegate.__send__(s, *a, &b)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end#class Stub
|
|
57
|
+
|
|
58
|
+
class ::Object
|
|
59
|
+
|
|
60
|
+
# Create a new stub.
|
|
61
|
+
def stub(stub_module=nil)
|
|
62
|
+
if stub_module
|
|
63
|
+
Stub::Delegator.new(self, stub_module)
|
|
64
|
+
else
|
|
65
|
+
@_stub ||= Stub.new
|
|
66
|
+
extend(@_stub)
|
|
67
|
+
@_stub
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# We can't remove the module per-say. So we have to
|
|
72
|
+
# just neuter it. This is a very weak solution, but
|
|
73
|
+
# it will suffice for the moment.
|
|
74
|
+
#--
|
|
75
|
+
# TODO: Use Carats for #unmix.
|
|
76
|
+
#++
|
|
77
|
+
def remove(stub_module=nil)
|
|
78
|
+
stub_module ||= @_stub
|
|
79
|
+
obj = self
|
|
80
|
+
mod = Module.new
|
|
81
|
+
stub_module.__table__.each do |interface, result|
|
|
82
|
+
meth = interface[0]
|
|
83
|
+
mod.module_eval do
|
|
84
|
+
define_method(meth, &obj.class.instance_method(meth).bind(obj))
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
extend(mod)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end#class ::Object
|
|
91
|
+
|
|
92
|
+
end#module Quarry
|
|
93
|
+
|
data/meta/abstract
ADDED
data/meta/authors
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Thomas Sawyer <transfire@gmail.com>
|