ae 1.0.0 → 1.1.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/lib/ae.rb CHANGED
@@ -3,5 +3,6 @@ module AE
3
3
  end
4
4
 
5
5
  require 'ae/assert'
6
+ #require 'ae/expect'
6
7
 
7
8
  # Copyright (c) 2008,2009 Thomas Sawyer
@@ -47,6 +47,20 @@ class Assertor
47
47
  __assert__(pass, msg)
48
48
  end
49
49
 
50
+ #
51
+ #def expect(*args, &block)
52
+ # return self if args.empty? && !block_given?
53
+ # block = args.shift if !block_given? && Proc === args.first
54
+ # if block
55
+ # pass = block.arity > 0 ? block.call(@delegate) : block.call #@delegate.instance_eval(&block)
56
+ # msg = args.shift || @message || block.inspect
57
+ # else
58
+ # pass = args.shift # truthiness
59
+ # msg = args.shift
60
+ # end
61
+ # __assert__(pass, msg)
62
+ #end
63
+
50
64
  #
51
65
  def flunk(msg=nil)
52
66
  fail Assertion.new(msg || @message, :backtrace=>@backtrace)
@@ -10,8 +10,8 @@ module Kernel
10
10
  #
11
11
  # TODO: Can we call this #fail (overriding built-in)?
12
12
  #
13
- def flunk(reason="flunk")
14
- raise Assertion.new(reason, :backtrace=>caller)
13
+ def flunk(reason=nil, backtrace=nil)
14
+ raise Assertion.new((reason || 'flunk'), :backtrace=>(backtrace || caller))
15
15
  end
16
16
 
17
17
  # Is literally true.
@@ -0,0 +1,124 @@
1
+ require 'ae/assertion'
2
+
3
+ module AE
4
+
5
+ # = Expect
6
+ #
7
+ # "When love and skill work together, expect a masterpiece."
8
+ # --John Ruskin (1819 - 1900)
9
+ #
10
+ module Expect
11
+
12
+ # The #expect method is a convenient tool for defining
13
+ # certain sets of expectations in your specifications.
14
+ #
15
+ # Expect is used to expect a result from a block of code.
16
+ # If the argument to expect is a subclass of Exception
17
+ # or instance thereof, then the block is monitored for
18
+ # the raising of such an exception.
19
+ #
20
+ # expect StandardError do
21
+ # raise ArgumentError
22
+ # end
23
+ #
24
+ # All other expectations are compared using case equality (#===).
25
+ # This allows one to verify matching Regexp.
26
+ #
27
+ # expect /x/ do
28
+ # "x"
29
+ # end
30
+ #
31
+ # As well as checking that an object is an instance of a given Class.
32
+ #
33
+ # expect String do
34
+ # "x"
35
+ # end
36
+ #
37
+ # Like #assert it can be used to designate an expectation
38
+ # via a *functor*.
39
+ #
40
+ # 4.expect == 3
41
+ #
42
+ #
43
+ def expect(*args, &block)
44
+ return Assertor.new(self, :backtrace=>caller) if args.empty? && !block
45
+ block = args.shift if !block_given? && Proc === args.first
46
+ if block
47
+ exp = args.empty? ? self : args.shift
48
+ if Exception === exp || (Class===exp && exp.ancestors.include?(Exception))
49
+ begin
50
+ block.call
51
+ pass = false
52
+ msg = "#{exp} not raised"
53
+ rescue exp => error
54
+ pass = true
55
+ rescue Exception => error
56
+ pass = false
57
+ msg = "#{exp} expected but #{error.class} was raised"
58
+ end
59
+ else
60
+ res = block.call
61
+ pass = (exp === res)
62
+ msg = "#{exp} === #{res}"
63
+ end
64
+ else
65
+ pass = (exp === self)
66
+ msg = "#{exp} === #{self}"
67
+ end
68
+ flunk(msg, caller) unless pass
69
+ end
70
+
71
+ # Designate a negated expectation. Read this as "expect not".
72
+ #
73
+ # See #expect.
74
+ #
75
+ def expect!(exp=NoArgument, &block)
76
+ return Assertor.new(self, :backtrace=>caller) if args.empty? && !block
77
+ block = args.shift if !block_given? && Proc === args.first
78
+ if block
79
+ exp = args.empty? ? self : args.shift
80
+ if Exception === exp || (Class===exp && exp.is?(Exception))
81
+ begin
82
+ block.call
83
+ pass = true
84
+ rescue exp => error
85
+ pass = false
86
+ msg = "#{exp} raised"
87
+ rescue Exception => error
88
+ pass = true
89
+ #msg = "#{exp} expected but #{error.class} was raised"
90
+ end
91
+ else
92
+ res = block.call
93
+ pass = !(exp === res)
94
+ msg = "not #{exp} === #{res}"
95
+ end
96
+ else
97
+ pass = !(exp === self)
98
+ msg = "not #{exp} === #{self}"
99
+ end
100
+ flunk(msg, caller) unless pass
101
+ end
102
+
103
+ # Alias for #expect! method.
104
+ alias_method :forbid, :expect!
105
+
106
+ # Like #expect but uses the reciever as the object
107
+ # of expectation.
108
+ #
109
+ # /x/.expected do
110
+ # "oooxooo"
111
+ # end
112
+ #
113
+ def expected(*args, &block)
114
+ expect(self, *args, &block)
115
+ end
116
+
117
+ end
118
+
119
+ end#module QED
120
+
121
+ class ::Object #:nodoc:
122
+ include AE::Expect
123
+ end
124
+
@@ -1 +1 @@
1
- http://ae.rubyforge.org
1
+ http://proutils.rubyforge.org/ae
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - trans <admin@tigerops.org>
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-03 00:00:00 -04:00
13
+ date: 2009-09-06 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -23,21 +23,23 @@ executables: []
23
23
  extensions: []
24
24
 
25
25
  extra_rdoc_files:
26
- - README
27
26
  - MANIFEST
28
27
  - LICENSE
28
+ - README.rdoc
29
29
  - HISTORY
30
30
  files:
31
31
  - demo/01_overview.rdoc
32
32
  - demo/02_assertion.rdoc
33
33
  - demo/03_assert.rdoc
34
34
  - demo/04_subjunctive.rdoc
35
+ - demo/05_expect.qed
35
36
  - doc/qedoc/index.html
36
37
  - doc/qedoc/jquery.js
37
38
  - lib/ae/assert.rb
38
39
  - lib/ae/assertion.rb
39
40
  - lib/ae/assertor.rb
40
41
  - lib/ae/core_ext.rb
42
+ - lib/ae/expect.rb
41
43
  - lib/ae/subjunctive/must.rb
42
44
  - lib/ae/subjunctive/should.rb
43
45
  - lib/ae/subjunctive.rb
@@ -57,11 +59,11 @@ files:
57
59
  - meta/title
58
60
  - meta/version
59
61
  - LICENSE
60
- - README
62
+ - README.rdoc
61
63
  - HISTORY
62
64
  - MANIFEST
63
65
  has_rdoc: true
64
- homepage: http://ae.rubyforge.org
66
+ homepage: http://proutils.rubyforge.org/ae
65
67
  licenses: []
66
68
 
67
69
  post_install_message:
@@ -69,8 +71,6 @@ rdoc_options:
69
71
  - --inline-source
70
72
  - --title
71
73
  - ae api
72
- - --main
73
- - README
74
74
  require_paths:
75
75
  - lib
76
76
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version:
88
88
  requirements: []
89
89
 
90
- rubyforge_project: ae
90
+ rubyforge_project: proutils
91
91
  rubygems_version: 1.3.5
92
92
  signing_key:
93
93
  specification_version: 3