quarry 0.3.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.
Files changed (112) hide show
  1. data/CHANGES +6 -0
  2. data/COPYING +344 -0
  3. data/MANIFEST +151 -0
  4. data/METADATA +22 -0
  5. data/NEWS +8 -0
  6. data/README +75 -0
  7. data/VERSION +1 -0
  8. data/bin/rubybreak +3 -0
  9. data/bin/xact-ruby +6 -0
  10. data/demo/spec/demo_check.rb +21 -0
  11. data/demo/spec/demo_outline.rb +25 -0
  12. data/demo/test/demo_run.rb +21 -0
  13. data/doc/manual.html2 +1416 -0
  14. data/doc/rdoc/classes/Assertion.html +101 -0
  15. data/doc/rdoc/classes/Assertion/False.html +132 -0
  16. data/doc/rdoc/classes/Assertion/True.html +137 -0
  17. data/doc/rdoc/classes/Kernel.html +86 -0
  18. data/doc/rdoc/classes/Method.html +137 -0
  19. data/doc/rdoc/classes/Module.html +165 -0
  20. data/doc/rdoc/classes/Object.html +154 -0
  21. data/doc/rdoc/classes/Quarry.html +177 -0
  22. data/doc/rdoc/classes/Quarry/Design.html +170 -0
  23. data/doc/rdoc/classes/Quarry/Design/Specification.html +265 -0
  24. data/doc/rdoc/classes/Quarry/Design/Specification/Context.html +174 -0
  25. data/doc/rdoc/classes/Quarry/MethodProbe.html +267 -0
  26. data/doc/rdoc/classes/Quarry/Mock.html +89 -0
  27. data/doc/rdoc/classes/Quarry/Mock/Object.html +276 -0
  28. data/doc/rdoc/created.rid +1 -0
  29. data/doc/rdoc/files/CHANGES.html +100 -0
  30. data/doc/rdoc/files/COPYING.html +457 -0
  31. data/doc/rdoc/files/MANIFEST.html +630 -0
  32. data/doc/rdoc/files/METADATA.html +92 -0
  33. data/doc/rdoc/files/NEWS.html +99 -0
  34. data/doc/rdoc/files/README.html +171 -0
  35. data/doc/rdoc/files/VERSION.html +96 -0
  36. data/doc/rdoc/files/bin/rubybreak.html +96 -0
  37. data/doc/rdoc/files/bin/xact-ruby.html +92 -0
  38. data/doc/rdoc/files/lib/quarry/assert/must_rb.html +96 -0
  39. data/doc/rdoc/files/lib/quarry/assert/should_rb.html +96 -0
  40. data/doc/rdoc/files/lib/quarry/assertion_rb.html +96 -0
  41. data/doc/rdoc/files/lib/quarry/breakout_rb.html +144 -0
  42. data/doc/rdoc/files/lib/quarry/design/spec_rb.html +100 -0
  43. data/doc/rdoc/files/lib/quarry/document_rb.html +92 -0
  44. data/doc/rdoc/files/lib/quarry/loadmonitor_rb.html +92 -0
  45. data/doc/rdoc/files/lib/quarry/methodprobe_rb.html +111 -0
  46. data/doc/rdoc/files/lib/quarry/mock/object_rb.html +123 -0
  47. data/doc/rdoc/files/lib/quarry/mockery_rb.html +115 -0
  48. data/doc/rdoc/fr_class_index.html +60 -0
  49. data/doc/rdoc/fr_file_index.html +65 -0
  50. data/doc/rdoc/fr_method_index.html +77 -0
  51. data/doc/rdoc/index.html +26 -0
  52. data/doc/rdoc/rdoc-style.css +175 -0
  53. data/doc/ri/Assertion/False/assert-i.yaml +10 -0
  54. data/doc/ri/Assertion/False/cdesc-False.yaml +19 -0
  55. data/doc/ri/Assertion/False/message-i.yaml +10 -0
  56. data/doc/ri/Assertion/True/assert-i.yaml +11 -0
  57. data/doc/ri/Assertion/True/cdesc-True.yaml +24 -0
  58. data/doc/ri/Assertion/True/message-c.yaml +11 -0
  59. data/doc/ri/Assertion/True/message-i.yaml +11 -0
  60. data/doc/ri/Assertion/True/method_missing-i.yaml +11 -0
  61. data/doc/ri/Assertion/True/new-c.yaml +11 -0
  62. data/doc/ri/Assertion/cdesc-Assertion.yaml +17 -0
  63. data/doc/ri/Kernel/cdesc-Kernel.yaml +15 -0
  64. data/doc/ri/Method/cdesc-Method.yaml +18 -0
  65. data/doc/ri/Method/migration-i.yaml +12 -0
  66. data/doc/ri/Method/signature-i.yaml +12 -0
  67. data/doc/ri/Module/cdesc-Module.yaml +21 -0
  68. data/doc/ri/Module/doc-i.yaml +16 -0
  69. data/doc/ri/Module/method_added-i.yaml +10 -0
  70. data/doc/ri/Object/assert%21-i.yaml +14 -0
  71. data/doc/ri/Object/assert-i.yaml +14 -0
  72. data/doc/ri/Object/cdesc-Object.yaml +20 -0
  73. data/doc/ri/Quarry/Design/Specification/Context/after-i.yaml +10 -0
  74. data/doc/ri/Quarry/Design/Specification/Context/before-i.yaml +10 -0
  75. data/doc/ri/Quarry/Design/Specification/Context/cdesc-Context.yaml +24 -0
  76. data/doc/ri/Quarry/Design/Specification/Context/method_missing-i.yaml +10 -0
  77. data/doc/ri/Quarry/Design/Specification/Context/specifications-i.yaml +10 -0
  78. data/doc/ri/Quarry/Design/Specification/cdesc-Specification.yaml +44 -0
  79. data/doc/ri/Quarry/Design/Specification/check-i.yaml +12 -0
  80. data/doc/ri/Quarry/Design/Specification/new-c.yaml +12 -0
  81. data/doc/ri/Quarry/Design/Specification/outline-i.yaml +12 -0
  82. data/doc/ri/Quarry/Design/cdesc-Design.yaml +22 -0
  83. data/doc/ri/Quarry/Design/check-c.yaml +12 -0
  84. data/doc/ri/Quarry/Design/outline-c.yaml +10 -0
  85. data/doc/ri/Quarry/Design/specification-c.yaml +10 -0
  86. data/doc/ri/Quarry/Design/specifications-c.yaml +10 -0
  87. data/doc/ri/Quarry/MethodProbe/cdesc-MethodProbe.yaml +46 -0
  88. data/doc/ri/Quarry/MethodProbe/duckcall-c.yaml +10 -0
  89. data/doc/ri/Quarry/MethodProbe/initialize_copy-i.yaml +10 -0
  90. data/doc/ri/Quarry/MethodProbe/method_missing-i.yaml +10 -0
  91. data/doc/ri/Quarry/MethodProbe/new-c.yaml +10 -0
  92. data/doc/ri/Quarry/Mock/Object/cdesc-Object.yaml +52 -0
  93. data/doc/ri/Quarry/Mock/Object/echo-c.yaml +12 -0
  94. data/doc/ri/Quarry/Mock/Object/keys-c.yaml +12 -0
  95. data/doc/ri/Quarry/Mock/Object/mock-c.yaml +12 -0
  96. data/doc/ri/Quarry/Mock/Object/mocks-c.yaml +10 -0
  97. data/doc/ri/Quarry/Mock/Object/spin-c.yaml +12 -0
  98. data/doc/ri/Quarry/Mock/cdesc-Mock.yaml +15 -0
  99. data/doc/ri/Quarry/Mockery-i.yaml +12 -0
  100. data/doc/ri/Quarry/cdesc-Quarry.yaml +17 -0
  101. data/doc/ri/created.rid +1 -0
  102. data/lib/quarry/assert/must.rb +8 -0
  103. data/lib/quarry/assert/should.rb +9 -0
  104. data/lib/quarry/assertion.rb +95 -0
  105. data/lib/quarry/breakout.rb +45 -0
  106. data/lib/quarry/design/spec.rb +197 -0
  107. data/lib/quarry/document.rb +35 -0
  108. data/lib/quarry/loadmonitor.rb +14 -0
  109. data/lib/quarry/methodprobe.rb +216 -0
  110. data/lib/quarry/mock/object.rb +169 -0
  111. data/lib/quarry/mockery.rb +85 -0
  112. metadata +214 -0
@@ -0,0 +1,12 @@
1
+ --- !ruby/object:RI::MethodDescription
2
+ aliases: []
3
+
4
+ block_params:
5
+ comment:
6
+ - !ruby/struct:SM::Flow::P
7
+ body: Responds according to a mapping of input parameters.
8
+ full_name: Quarry::Mock::Object::keys
9
+ is_singleton: true
10
+ name: keys
11
+ params: ( sym, hsh )
12
+ visibility: public
@@ -0,0 +1,12 @@
1
+ --- !ruby/object:RI::MethodDescription
2
+ aliases: []
3
+
4
+ block_params:
5
+ comment:
6
+ - !ruby/struct:SM::Flow::P
7
+ body: Mock a static repsonse.
8
+ full_name: Quarry::Mock::Object::mock
9
+ is_singleton: true
10
+ name: mock
11
+ params: ( sym, val )
12
+ visibility: public
@@ -0,0 +1,10 @@
1
+ --- !ruby/object:RI::MethodDescription
2
+ aliases: []
3
+
4
+ block_params:
5
+ comment:
6
+ full_name: Quarry::Mock::Object::mocks
7
+ is_singleton: true
8
+ name: mocks
9
+ params: ()
10
+ visibility: public
@@ -0,0 +1,12 @@
1
+ --- !ruby/object:RI::MethodDescription
2
+ aliases: []
3
+
4
+ block_params:
5
+ comment:
6
+ - !ruby/struct:SM::Flow::P
7
+ body: Reponds with a rotation of reponses.
8
+ full_name: Quarry::Mock::Object::spin
9
+ is_singleton: true
10
+ name: spin
11
+ params: ( sym, arr )
12
+ visibility: public
@@ -0,0 +1,15 @@
1
+ --- !ruby/object:RI::ClassDescription
2
+ attributes: []
3
+
4
+ class_methods: []
5
+
6
+ comment:
7
+ constants: []
8
+
9
+ full_name: Quarry::Mock
10
+ includes: []
11
+
12
+ instance_methods: []
13
+
14
+ name: Mock
15
+ superclass:
@@ -0,0 +1,12 @@
1
+ --- !ruby/object:RI::MethodDescription
2
+ aliases: []
3
+
4
+ block_params:
5
+ comment:
6
+ - !ruby/struct:SM::Flow::P
7
+ body: Factory method for creating semi-functional mock object classes given the class which is to be mocked. It looks like a constant for purposes of syntactic sugar.
8
+ full_name: Quarry#Mockery
9
+ is_singleton: false
10
+ name: Mockery
11
+ params: ( realclass )
12
+ visibility: public
@@ -0,0 +1,17 @@
1
+ --- !ruby/object:RI::ClassDescription
2
+ attributes: []
3
+
4
+ class_methods: []
5
+
6
+ comment: []
7
+
8
+ constants: []
9
+
10
+ full_name: Quarry
11
+ includes: []
12
+
13
+ instance_methods:
14
+ - !ruby/object:RI::MethodSummary
15
+ name: Mockery
16
+ name: Quarry
17
+ superclass:
@@ -0,0 +1 @@
1
+ Thu, 21 Aug 2008 13:19:31 -0400
@@ -0,0 +1,8 @@
1
+ require 'quarry/assertion'
2
+
3
+ class Object
4
+ alias_method :must, :assert
5
+ alias_method :must!, :assert!
6
+ alias_method :must_not, :assert!
7
+ end
8
+
@@ -0,0 +1,9 @@
1
+ require 'quarry/assertion'
2
+
3
+ class Object
4
+ alias_method :should, :assert
5
+ alias_method :should!, :assert!
6
+ alias_method :should_not, :assert!
7
+ alias_method :shouldnt, :assert!
8
+ end
9
+
@@ -0,0 +1,95 @@
1
+ # Copyright (c) 2008 Tiger Ops
2
+
3
+ class Object
4
+ # Assert a operational relationship.
5
+ #
6
+ # 4.assert == 3 #=> Assertion Error
7
+ #
8
+ def assert
9
+ return Assertion::True.new(self)
10
+ end
11
+
12
+ # Assert not an operational relationship.
13
+ #
14
+ # 4.assert! == 4 #=> Assertion Error
15
+ #
16
+ def assert!
17
+ return Assertion::False.new(self)
18
+ end
19
+ end
20
+
21
+ # Assertion object is a special subclass of Exception,
22
+ # used to raise assertion errors.
23
+ #
24
+ class Assertion < Exception
25
+
26
+ #
27
+ class True
28
+ #
29
+ def self.message(msg,&block)
30
+ @messages ||= {}
31
+ if block
32
+ @messages[msg] = block
33
+ else
34
+ @messages[msg]
35
+ end
36
+ end
37
+
38
+ hide = instance_methods.reject { |m| m.to_s =~ /^__/ }
39
+ hide.each { |m| protected m }
40
+
41
+ private
42
+
43
+ #
44
+ def initialize(delegate)
45
+ @delegate = delegate
46
+ end
47
+
48
+ #
49
+ def assert(assertion, msg="failed assertion (no message given)")
50
+ raise Assertion, msg unless assertion
51
+ end
52
+
53
+ #
54
+ message(:==){ |*a| "Expected #{a[0].inspect} to be equal to #{a[1].inspect}" }
55
+
56
+ #
57
+ def method_missing( sym, *a, &b )
58
+ case sym
59
+ when :raise?, :raises?
60
+ begin
61
+ @delegate.call #yield
62
+ assert false, "Expected #{a[0]} to be raised"
63
+ rescue Exception => e
64
+ assert a[0] === e, "Expected #{a[0]} to be raised, but got #{e.class}"
65
+ return e
66
+ end
67
+ else
68
+ msg = message(@delegate, sym, *a, &b)
69
+ assert(@delegate.send(sym, *a, &b ), msg)
70
+ #assert( @delegate.send(sym, *a, &b ), self.class.message(sym)[@delegate, *a] )
71
+ end
72
+ end
73
+
74
+ #
75
+ def message( obj, sym, *a, &b )
76
+ "#{sym}\n< #{obj.inspect}\n---\n> #{a.collect{|x| x.inspect}.join(',')}"
77
+ end
78
+
79
+ end
80
+
81
+ #
82
+ class False < True
83
+ message(:==){ |*a| "Expected #{a[0].inspect} not to be equal to #{a[1].inspect}" }
84
+
85
+ def assert(assertion, msg="failed assertion (no message given)")
86
+ raise Assertion, msg if assertion
87
+ end
88
+
89
+ def message( obj, sym, *a, &b )
90
+ "#{obj.inspect} should not #{sym} #{a.collect{|x| x.inspect}.join(',')}"
91
+ end
92
+ end
93
+
94
+ end
95
+
@@ -0,0 +1,45 @@
1
+ require 'facets/core/string/margin' # TODO get rid of.
2
+
3
+ def breakout( error )
4
+
5
+ file, line = *error.exception.backtrace[0].split(':')
6
+ line = line.to_i
7
+
8
+ puts error
9
+
10
+ e = "# DEBUG " + error.to_s
11
+ e.gsub!("`","'")
12
+
13
+ e = Regexp.escape(e)
14
+
15
+ case ed = ENV['EDITOR']
16
+ when 'vi', 'vim', 'gvim'
17
+ cmd = %[
18
+ |#{ed} -e -s #{file} <<-EOS
19
+ |:#{line}
20
+ |a
21
+ |#{e}
22
+ |.
23
+ |:.,+#{e.size}
24
+ |EOS
25
+ ].margin
26
+ else
27
+ puts "EDITOR environment variable not set"
28
+ end
29
+
30
+ system cmd
31
+
32
+ end
33
+
34
+ # command-line mode
35
+
36
+ if __FILE__ == $0
37
+
38
+ begin
39
+ load $file = ARGV[0]
40
+ rescue Exception => e
41
+ error = breakout(e)
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,197 @@
1
+ #require 'facet/kernel/within?'
2
+ require 'quarry/assertion'
3
+
4
+ module Quarry
5
+ module Design
6
+
7
+ class << self
8
+ def specifications
9
+ @specifications ||= []
10
+ end
11
+
12
+ def specification(description, &specification)
13
+ specifications << Specification.new(nil, description, &specification)
14
+ end
15
+ alias_method :spec, :specification
16
+
17
+ # TODO: make output compatible with unit_diff ?
18
+
19
+ def check
20
+ specifications.each do |specification|
21
+ specification.check
22
+ end
23
+ end
24
+
25
+ def outline
26
+ specifications.each do |specification|
27
+ specification.outline
28
+ end
29
+ end
30
+ end
31
+
32
+ # Design specification. Sepcification can contains sub-specifications.
33
+ #
34
+ class Specification
35
+ attr :relation
36
+ attr :description
37
+ attr :specification
38
+ attr :context
39
+ attr :before
40
+ attr :after
41
+
42
+ # New Specification
43
+
44
+ def initialize(relation, description, context=nil, &specification)
45
+ @relation = relation
46
+ @description = description
47
+ @specification = specification
48
+ @context = context
49
+ @before = context.before if context
50
+ @after = context.after if context
51
+ end
52
+
53
+ # Check Specification
54
+
55
+ def check(level=0)
56
+ padding = " " * 2 * level
57
+
58
+ clause = "#{relation} #{description}".strip
59
+
60
+ new_context = Context.new
61
+ new_context.instance_eval(&before) if before
62
+ begin
63
+ new_context.instance_eval(&specification)
64
+ puts ("=" * (level+1)) + " " + clause.gsub(/\b\w/){$&.upcase}
65
+ rescue Assertion => e
66
+ #puts padding + " (FAIL) [#{e.backtrace[2]}] " + clause
67
+ puts "* " + clause.gsub('_',' ') + " [#{e.backtrace[2]}]"
68
+ puts e if $VERBOSE
69
+ rescue Exception => e
70
+ raise e if $DEBUG
71
+ print padding
72
+ #puts padding + " (ERROR) [#{e.backtrace[2]}] " + clause
73
+ puts padding + " (ERROR) #{e}"
74
+ puts e.backtrace if $VERBOSE
75
+ ensure
76
+ new_context.instance_eval(&after) if after
77
+ end
78
+
79
+ new_context.specifications.each do |s|
80
+ s.check(level+1)
81
+ end
82
+ end
83
+
84
+ # Outline Specification
85
+
86
+ def outline(level=0)
87
+ padding = (" " * 2 * level) + "- "
88
+ context = Context.new
89
+ begin
90
+ context.instance_eval(&specification)
91
+ rescue Assertion => e
92
+ #rescue Exception => e
93
+ end
94
+
95
+ str = ''
96
+ str << "#{relation} " if relation
97
+ str << "#{description}"
98
+ #str = str.strip #.gsub(/\b\w/){$&.upcase}
99
+
100
+ puts padding + str.strip
101
+
102
+ context.specifications.each do |s|
103
+ s.outline(level+1)
104
+ end
105
+ end
106
+
107
+ # A context provides a "clean room" to build a specification.
108
+
109
+ class Context
110
+
111
+ def specifications
112
+ @specifications ||= []
113
+ end
114
+
115
+ def before(&before)
116
+ before ? @before = before : before
117
+ end
118
+
119
+ def after(&after)
120
+ after ? @after = after : after
121
+ end
122
+
123
+ def method_missing(relation, *description, &specification)
124
+ if description.size > 1
125
+ super
126
+ else
127
+ specifications << Specification.new(relation, description.first, self, &specification)
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
136
+ end
137
+
138
+ at_exit { Quarry::Design.check unless $no_autocheck }
139
+
140
+
141
+ =begin demo
142
+
143
+ Quarry::Design.specification "Example Specification" do
144
+
145
+ context "demonstrate basic assertions" do
146
+
147
+ specify "fail if should is false" do
148
+ 4.assert == 3
149
+ end
150
+
151
+ specify "fail if should_not is true" do
152
+ 4.assert! == 4
153
+ end
154
+
155
+ specify "fail on should raise" do
156
+ lambda{raise ArgumentError}.assert.raise? SyntaxError
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+ $no_autocheck = true
164
+
165
+ Quarry::Design.outline
166
+
167
+ =end
168
+
169
+
170
+ if __FILE__ == $0
171
+
172
+ Quarry::Design.spec "Example Specification" do
173
+
174
+ demonstrate "basic assertions" do
175
+
176
+ that "4 == 3 fails" do
177
+ 4.assert == 3
178
+ end
179
+
180
+ that "4 != 4 fails" do
181
+ 4.assert! == 4
182
+ end
183
+
184
+ that "raising an ArgumentError does not raise a SyntaxError" do
185
+ lambda{raise ArgumentError}.assert.raise? SyntaxError
186
+ end
187
+
188
+ end
189
+
190
+ end
191
+
192
+ $no_autocheck = true
193
+
194
+ Quarry::Design.outline
195
+
196
+ end
197
+