ae 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/PACKAGE ADDED
@@ -0,0 +1,5 @@
1
+ name : ae
2
+ major: 1
3
+ minor: 3
4
+ patch: 0
5
+ date : 2010-06-17
File without changes
File without changes
@@ -58,6 +58,27 @@ Another way to get the opposite inference, is to use +not+.
58
58
  10.assert.not == 9
59
59
 
60
60
 
61
+ == Matchers & Lambda Assertions
62
+
63
+ Passing a Proc object or an objec that responds to :to_prco, will use it
64
+ as if it were a block of the method. This allows for a simple way to quickly
65
+ create reusable assertions.
66
+
67
+ palindrome = lambda{ |word| word == word.reverse }
68
+
69
+ "abracarba".assert palindrome
70
+
71
+ Additionally is the object responds to #matches? then the receiver
72
+ will be passed to this method to determine passage.
73
+
74
+ palindrome = Object.new
75
+ def palindrome.matches?(word)
76
+ word == word.reverse
77
+ end
78
+
79
+ "abracarba".assert palindrome
80
+
81
+
61
82
  == Identity Assertions
62
83
 
63
84
  Rather then the general form:
@@ -237,26 +258,10 @@ Or minimum range.
237
258
  3.in_epsilon?(3,5)
238
259
 
239
260
 
240
- == Custom Lambda Assertions
241
-
242
- Passing a lambda to the subjunctive method, will use it as if it were
243
- a block of the method. This allows for a simple way to quickly
244
- create reusable assertions.
245
-
246
- palindrome = lambda{ |x| x == x.reverse }
247
-
248
- "abracarba".assert palindrome
249
-
250
-
251
261
  == Verifying Object State
252
262
 
253
- NOTE: <i>This functionality is not currently supported, but is being
254
- considered for a future version.</i>
255
-
256
- If no block parameter is designated and the receiver differs from +self+
257
- in scope of the given block, then the block is evaluated in the scope of
258
- the receiver via +instance_eval+. This can be also be used to verify the
259
- state of an object.
263
+ Not surprisingly if underlying object state needs to be verified, +instance_eval+
264
+ can be used in conjunction with +assert+.
260
265
 
261
266
  class X
262
267
  attr :a
@@ -265,20 +270,20 @@ state of an object.
265
270
 
266
271
  x = X.new(4)
267
272
 
268
- x.assert do
273
+ x.assert.instance_eval do
269
274
  4 == @a
270
275
  end
271
276
 
272
- And should it fail...
277
+ And should it fail
273
278
 
274
279
  Assertion.assert.raised? do
275
- x.assert do
280
+ x.assert.instance_eval do
276
281
  5 == @a
277
282
  end
278
283
  end
279
284
 
280
- For some this might be considered poor form, i.e. to test underlying
281
- implementation. You will get no argument here. It should be used
282
- thoughtfully, but I would not bet against there being occasions
283
- when such validations might be handy.
285
+ For some testing underlying implementation might be considered poor
286
+ form. You will get no argument here. It should be used thoughtfully,
287
+ but I would not bet against there being occasions when such validations
288
+ might be handy.
284
289
 
File without changes
@@ -1,12 +1,13 @@
1
1
  = Expect Method
2
2
 
3
- Expect is another optional assertion nomenclature available
4
- for use in your tests or specifications. Inspired by Jay Fields'
5
- Expectations library, it provides convenient syntax for creating
6
- exception and case equality assertions.
3
+ Expect is another assertion nomenclature available for use in your
4
+ tests or specifications. Inspired by Jay Fields' Expectations library,
5
+ it provides convenient syntax for creating exception and case equality
6
+ assertions.
7
7
 
8
8
  require 'ae/expect'
9
9
 
10
+
10
11
  == Underlying Comparison
11
12
 
12
13
  Expect uses #=== for comparison. So providing an argument and a block to
@@ -67,18 +68,38 @@ We can use #expected to make the receiver the object of expectation.
67
68
  end
68
69
 
69
70
 
70
- == Function without Block
71
+ == Without Block
71
72
 
72
73
  Without a block, the receiver is compared to the argument.
73
74
 
74
75
  x.expect String
75
76
 
76
77
 
78
+ == Negative Forms
79
+
80
+ Like #assert, #expect has a negated form called #expect!
81
+
82
+ expect! /x/ do
83
+ "o"
84
+ end
85
+
86
+ The pure word form for those who do not like the clever use of the
87
+ explimation mark is #forbid.
88
+
89
+ forbid /x/ do
90
+ "o"
91
+ end
92
+
93
+
77
94
  == Functor, or Higher Order Function
78
95
 
79
96
  Like #assert, #expect can be used used as a *fluid* notation.
80
97
 
81
98
  10.expect == 10
82
99
 
83
- In which case it works just like #assert.
100
+ In which case it works just like #assert, including negative forms.
101
+
102
+ 10.expect! == 11
103
+ 10.forbid == 11
104
+
84
105
 
File without changes
data/lib/ae.rb CHANGED
@@ -1,8 +1,24 @@
1
1
  require 'yaml'
2
2
 
3
3
  module AE
4
- vers = YAML.load(File.read(File.dirname(__FILE__) + '/ae/version.yml'))
5
- VERSION = vers.values_at('major', 'minor', 'patch', 'state', 'build').compact.join('.')
4
+ DIRECTORY = File.dirname(__FILE__) + '/ae'
5
+
6
+ PROFILE = YAML.load(File.new(DIRECTORY + '/profile.yml')) rescue {}
7
+ PACKAGE = YAML.load(File.new(DIRECTORY + '/package.yml')) rescue {}
8
+
9
+ VERSION = PACKAGE.values_at('major','minor','patch','build').compact.join('.')
10
+
11
+ #
12
+ def self.const_missing(name)
13
+ key = name.to_s.downcase
14
+ if PACKAGE.key?(key)
15
+ PACKAGE[key]
16
+ elsif PROFILE.key?(key)
17
+ PROFILE[key]
18
+ else
19
+ super(name)
20
+ end
21
+ end
6
22
  end
7
23
 
8
24
  require 'ae/assert'
@@ -23,12 +23,12 @@ module AE
23
23
  # assert{ 4==3 }
24
24
  #
25
25
  def assert(*args, &block)
26
- return Assertor.new(self, :backtrace=>caller).assert(*args, &block)
26
+ Assertor.new(self, :backtrace=>caller).assert(*args, &block)
27
27
  end
28
28
 
29
29
  # Same as 'object.assert == other'.
30
30
  def assert=(cmp)
31
- return Assertor.new(self, :backtrace=>caller).assert(*args, &block) == cmp
31
+ Assertor.new(self, :backtrace=>caller).assert(*args, &block) == cmp
32
32
  end
33
33
 
34
34
  # Assert not an operational relationship.
@@ -43,7 +43,7 @@ module AE
43
43
  # may be possible in Ruby 1.9.
44
44
  #
45
45
  def assert!(*args, &block)
46
- return Assertor.new(self, :backtrace=>caller).not(*args, &block)
46
+ Assertor.new(self, :backtrace=>caller).not.assert(*args, &block)
47
47
  end
48
48
 
49
49
  # Alias for #assert!.
@@ -27,42 +27,101 @@ class Assertor
27
27
  @negated = !!opts[:negated]
28
28
  end
29
29
 
30
+ # Negate the meaning of the assertion.
30
31
  #
31
- def not(msg=nil, &block)
32
+ # TODO: Should this return a new Assertor instead of inplace negation?
33
+ def not(msg=nil)
32
34
  @negated = !@negated
33
- block ? assert(msg, &block) : self
35
+ @message = msg if msg
36
+ self
34
37
  end
35
38
 
36
39
  # Internal assert, provides all functionality associated
37
- # with external #assert Object method.
40
+ # with external #assert method. (See Assert#assert)
41
+ #
42
+ # NOTE: I'm calling YAGNI on using extra arguments to pass
43
+ # to the block. The interface is much nicer if a macro is
44
+ # created to handle any neccessry arguments. Eg.
45
+ #
46
+ # assert something(parameter)
47
+ #
48
+ # instead of
49
+ #
50
+ # assert something, parameter
38
51
  #
39
- # TODO: I'm calling YAGNI on any extra arguments to the block.
40
52
  def assert(*args, &block)
41
53
  return self if args.empty? && !block_given?
42
- block = args.shift if !block_given? && Proc === args.first
43
- if block
44
- pass = block.arity > 0 ? block.call(@delegate) : block.call #@delegate.instance_eval(&block)
45
- msg = args.shift || @message || block.inspect
54
+
55
+ target = block || args.shift
56
+
57
+ if Proc === target || target.respond_to?(:to_proc)
58
+ block = target.to_proc
59
+ match = args.shift
60
+ result = block.arity > 0 ? block.call(@delegate) : block.call
61
+ if match
62
+ pass = (match == result)
63
+ msg = @message || "#{match.inspect} == #{result.inspect}"
64
+ else
65
+ pass = result
66
+ msg = @message || block.inspect # "#{result.inspect}"
67
+ end
68
+ elsif target.respond_to?(:matches?)
69
+ pass = target.matches?(@delegate)
70
+ msg = @message || matcher_message(target) || target.inspect
46
71
  else
47
- pass = args.shift # truthiness
48
- msg = args.shift
72
+ pass = target # truthiness
73
+ msg = args.shift # optional mesage for TestUnit compatiability
49
74
  end
75
+
50
76
  __assert__(pass, msg)
51
77
  end
52
78
 
79
+ # Internal expect, provides all functionality associated
80
+ # with external #expect method. (See Expect#expect)
53
81
  #
54
- #def expect(*args, &block)
55
- # return self if args.empty? && !block_given?
56
- # block = args.shift if !block_given? && Proc === args.first
57
- # if block
58
- # pass = block.arity > 0 ? block.call(@delegate) : block.call #@delegate.instance_eval(&block)
59
- # msg = args.shift || @message || block.inspect
60
- # else
61
- # pass = args.shift # truthiness
62
- # msg = args.shift
63
- # end
64
- # __assert__(pass, msg)
65
- #end
82
+ #--
83
+ # TODO: Should we deprecate the receiver matches in favor of #expected ?
84
+ # In other words, should the <code>|| @delegate</code> be dropped?
85
+ #
86
+ # TODO: respond_to?(:exception) && match = exception if Exception === match
87
+ #++
88
+ def expect(*args, &block)
89
+ # same as #assert if no arguments of block given
90
+ return self if args.empty? && !block_given?
91
+
92
+ target = block || args.shift
93
+
94
+ if Proc === target || target.respond_to?(:to_proc)
95
+ block = target.to_proc
96
+ match = args.shift || @delegate
97
+ if Exception === match || (Class===match && match.ancestors.include?(Exception))
98
+ begin
99
+ block.arity > 0 ? block.call(@delegate) : block.call
100
+ pass = false
101
+ msg = "#{match} not raised"
102
+ rescue match => error
103
+ pass = true
104
+ msg = "#{match} raised"
105
+ rescue Exception => error
106
+ pass = false
107
+ msg = "#{match} expected but #{error.class} was raised"
108
+ end
109
+ else
110
+ result = block.arity > 0 ? block.call(@delegte) : block.call
111
+ pass = (match === result)
112
+ msg = @message || "#{match.inspect} === #{result.inspect}"
113
+ end
114
+ elsif target.respond_to?(:matches?)
115
+ pass = target.matches?(@delegate)
116
+ msg = @message || matcher_message(target) || target.inspect
117
+ else
118
+ pass = (target === @delegate)
119
+ msg = @message || "#{target.inspect} === #{@delegate.inspect}"
120
+ end
121
+
122
+ #flunk(msg, caller) unless pass
123
+ __assert__(pass, msg)
124
+ end
66
125
 
67
126
  #
68
127
  def flunk(msg=nil)
@@ -112,6 +171,19 @@ class Assertor
112
171
  @negated ? !pass : !!pass
113
172
  end
114
173
 
174
+ #
175
+ def matcher_message(matcher)
176
+ if @negated
177
+ if matcher.respond_to?(:negative_failure_message)
178
+ return matcher.failure_message
179
+ end
180
+ end
181
+ if matcher.respond_to?(:failure_message)
182
+ return matcher.failure_message
183
+ end
184
+ false
185
+ end
186
+
115
187
  # TODO: Ultimately better messages might be nice.
116
188
  #
117
189
  #def self.message(op,&block)
@@ -39,65 +39,16 @@ module AE
39
39
  #
40
40
  # 4.expect == 3
41
41
  #
42
- #
43
42
  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
43
+ Assertor.new(self, :backtrace=>caller).expect(*args, &block)
69
44
  end
70
45
 
71
46
  # Designate a negated expectation. Read this as "expect not".
72
47
  #
73
48
  # See #expect.
74
49
  #
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
50
+ def expect!(*args, &block)
51
+ Assertor.new(self, :backtrace=>caller).not.expect(*args, &block)
101
52
  end
102
53
 
103
54
  # Alias for #expect! method.
@@ -0,0 +1,5 @@
1
+ name : ae
2
+ major: 1
3
+ minor: 3
4
+ patch: 0
5
+ date : 2010-06-17
@@ -0,0 +1,18 @@
1
+ ---
2
+ title : AE
3
+ summary: Assertive Expressive
4
+ suite : proutils
5
+ contact: trans <transfire@gmail.com>
6
+ created: 2008-08-17 09:00:06
7
+ authors: Thomas Sawyer
8
+ license: MIT
9
+
10
+ description:
11
+ Assertive Expressive is an assertions library intended for reuse
12
+ by any TDD, BDD or the like system.
13
+
14
+ resources:
15
+ homepage: http://proutils.github.com/ae
16
+ repository: git://github.com/proutils/ae.git
17
+
18
+ copyright: Copyright (c) 2008 Thomas Sawyer
@@ -12,13 +12,6 @@ module AE
12
12
  #
13
13
  module Subjunctive
14
14
 
15
- #
16
- #def not(&block)
17
- # @negated = !@negated
18
- # return self if !block_given?
19
- # be(*args, &block)
20
- #end
21
-
22
15
  # Like #assert, except if an argument if provided and no block,
23
16
  # uses #equate? to compare the argument to the receiver. This
24
17
  # allows for statements of the form:
@@ -28,7 +28,7 @@ module AE
28
28
  # 4.must! == 4 #=> Assertion Error
29
29
  #
30
30
  def must!(*args, &block)
31
- Assertor.new(self, :backtrace=>caller).not(*args, &block)
31
+ Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
32
32
  end
33
33
 
34
34
  # Perhaps not literally the counter-term to *must* (rather *will*),
@@ -29,7 +29,7 @@ module AE
29
29
  # 4.should! == 4 #=> Assertion Error
30
30
  #
31
31
  def should!(*args, &block)
32
- Assertor.new(self, :backtrace=>caller).not(*args, &block)
32
+ Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
33
33
  end
34
34
 
35
35
  # Not quite the literally the counter-term to *should* (rather *shall*), but
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 2
8
8
  - 3
9
- version: 1.2.3
9
+ - 0
10
+ version: 1.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Thomas Sawyer
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-08 00:00:00 -04:00
18
+ date: 2010-06-17 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: syckle
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: qed
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -50,12 +55,12 @@ extensions: []
50
55
  extra_rdoc_files:
51
56
  - README.rdoc
52
57
  files:
53
- - qed/01_overview.rdoc
54
- - qed/02_assertion.rdoc
55
- - qed/03_assert.rdoc
56
- - qed/04_subjunctive.rdoc
57
- - qed/05_expect.rdoc
58
- - qed/06_counts.rdoc
58
+ - demo/01_overview.rdoc
59
+ - demo/02_assertion.rdoc
60
+ - demo/03_assert.rdoc
61
+ - demo/04_subjunctive.rdoc
62
+ - demo/05_expect.rdoc
63
+ - demo/06_counts.rdoc
59
64
  - lib/ae/assert.rb
60
65
  - lib/ae/assertion.rb
61
66
  - lib/ae/assertor.rb
@@ -63,18 +68,19 @@ files:
63
68
  - lib/ae/expect.rb
64
69
  - lib/ae/legacy.rb
65
70
  - lib/ae/must.rb
71
+ - lib/ae/package.yml
72
+ - lib/ae/profile.yml
66
73
  - lib/ae/should.rb
67
74
  - lib/ae/subjunctive/must.rb
68
75
  - lib/ae/subjunctive/should.rb
69
76
  - lib/ae/subjunctive.rb
70
- - lib/ae/version.yml
71
77
  - lib/ae.rb
72
78
  - PROFILE
79
+ - PACKAGE
73
80
  - LICENSE
74
81
  - README.rdoc
75
82
  - HISTORY
76
83
  - REQUIRE
77
- - VERSION
78
84
  has_rdoc: true
79
85
  homepage: http://proutils.github.com/ae
80
86
  licenses: []
@@ -88,23 +94,27 @@ rdoc_options:
88
94
  require_paths:
89
95
  - lib
90
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
91
98
  requirements:
92
99
  - - ">="
93
100
  - !ruby/object:Gem::Version
101
+ hash: 3
94
102
  segments:
95
103
  - 0
96
104
  version: "0"
97
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
98
107
  requirements:
99
108
  - - ">="
100
109
  - !ruby/object:Gem::Version
110
+ hash: 3
101
111
  segments:
102
112
  - 0
103
113
  version: "0"
104
114
  requirements: []
105
115
 
106
116
  rubyforge_project: ae
107
- rubygems_version: 1.3.6
117
+ rubygems_version: 1.3.7
108
118
  signing_key:
109
119
  specification_version: 3
110
120
  summary: Assertive Expressive
data/VERSION DELETED
@@ -1,6 +0,0 @@
1
- name : ae
2
- major: 1
3
- minor: 2
4
- patch: 3
5
- date : 2010-06-07
6
-
@@ -1,6 +0,0 @@
1
- name : ae
2
- major: 1
3
- minor: 2
4
- patch: 3
5
- date : 2010-06-07
6
-