ae 1.7.0 → 1.7.1
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/.ruby +21 -9
- data/{Apache2.txt → APACHE2.txt} +0 -0
- data/{History.rdoc → HISTORY.rdoc} +11 -0
- data/README.rdoc +54 -14
- data/{Syckfile → Redfile} +3 -3
- data/lib/ae.rb +1 -1
- data/lib/ae.yml +21 -9
- data/lib/ae/adapter.rb +5 -4
- data/lib/ae/adapters/minitest.rb +24 -5
- data/lib/ae/adapters/rspec.rb +3 -0
- data/lib/ae/adapters/testunit.rb +41 -4
- data/lib/ae/assert.rb +1 -1
- data/lib/ae/assertion.rb +0 -2
- data/lib/ae/assertor.rb +125 -66
- data/lib/ae/core_ext/exception.rb +11 -1
- data/lib/ae/legacy.rb +0 -7
- data/lib/ae/must.rb +1 -1
- data/lib/ae/pry.rb +4 -1
- metadata +8 -10
- data/lib/ae/detest.rb +0 -68
- data/lib/ae/dot.rb +0 -45
data/.ruby
CHANGED
@@ -1,33 +1,45 @@
|
|
1
1
|
---
|
2
2
|
spec_version: 1.0.0
|
3
|
+
replaces: []
|
4
|
+
|
5
|
+
loadpath:
|
6
|
+
- lib
|
3
7
|
name: ae
|
4
|
-
|
5
|
-
|
8
|
+
repositories:
|
9
|
+
public: git://github.com/rubyworks/ae.git
|
10
|
+
conflicts: []
|
11
|
+
|
12
|
+
engine_check:
|
6
13
|
- ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
|
14
|
+
- ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
|
15
|
+
title: AE
|
7
16
|
contact: trans <transfire@gmail.com>
|
8
17
|
resources:
|
9
|
-
repo: git://github.com/rubyworks/ae.git
|
10
18
|
code: http://github.com/rubyworks/ae
|
11
19
|
mail: http://groups.google.com/group/rubyworks-mailinglist
|
12
20
|
docs: http://wiki.github.com/rubyworks/ae/docs/qed
|
13
|
-
bugs: http://github.com/rubyworks/ae/issues
|
14
21
|
wiki: http://wiki.github.com/rubyworks/ae
|
22
|
+
bugs: http://github.com/rubyworks/ae/issues
|
15
23
|
home: http://rubyworks.github.com/ae
|
24
|
+
maintainers: []
|
25
|
+
|
16
26
|
requires:
|
17
27
|
- group:
|
18
28
|
- build
|
19
|
-
name:
|
29
|
+
name: redline
|
20
30
|
version: 0+
|
21
31
|
- group:
|
22
32
|
- test
|
23
33
|
name: qed
|
24
34
|
version: 0+
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
manifest: MANIFEST
|
36
|
+
version: 1.7.1
|
37
|
+
licenses:
|
38
|
+
- Apache 2.0
|
28
39
|
copyright: Copyright (c) 2008 Thomas Sawyer
|
29
|
-
description: Assertive Expressive is an assertions library specifically designed for reuse by other test frameworks.
|
30
40
|
authors:
|
31
41
|
- Thomas Sawyer
|
42
|
+
organization: Rubyworks
|
43
|
+
description: Assertive Expressive is an assertions library specifically designed for reuse by other test frameworks.
|
32
44
|
summary: Assertive Expressive
|
33
45
|
created: 2008-08-17
|
data/{Apache2.txt → APACHE2.txt}
RENAMED
File without changes
|
@@ -1,5 +1,16 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 1.7.1 / 2011-05-06
|
4
|
+
|
5
|
+
This release adds a specialized message for certain comparision
|
6
|
+
operators to allow them have a more forensic output. This is done
|
7
|
+
via ANSI::Diff library.
|
8
|
+
|
9
|
+
Changes:
|
10
|
+
|
11
|
+
* Add special message for comparison assertions.
|
12
|
+
|
13
|
+
|
3
14
|
== 1.7.0 / 2011-04-28
|
4
15
|
|
5
16
|
AE now uses proper namespace for all classes. In particular, the `Assertor`
|
data/README.rdoc
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= Assertive Expressive
|
2
2
|
|
3
|
+
Author:: Thomas Sawyer
|
4
|
+
License:: Apache 2.0
|
5
|
+
|
6
|
+
|
3
7
|
== DESCRIPTION
|
4
8
|
|
5
9
|
Assertive Expressive (AE) is an assertions framework
|
@@ -19,8 +23,12 @@ intended for reuse by any TDD, BDD or similar system.
|
|
19
23
|
|
20
24
|
== RESOURCES
|
21
25
|
|
22
|
-
* home: http://rubyworks.github.com/ae
|
23
|
-
* code: http://github.com/rubyworks/ae
|
26
|
+
* home: http://rubyworks.github.com/ae
|
27
|
+
* code: http://github.com/rubyworks/ae
|
28
|
+
* docs: http://wiki.github.com/rubyworks/ae/docs/qed
|
29
|
+
* wiki: http://wiki.github.com/rubyworks/ae
|
30
|
+
* bugs: http://github.com/rubyworks/ae/issues
|
31
|
+
* mail: http://googlegroups.com/group/rubyworks-mailinglist
|
24
32
|
|
25
33
|
|
26
34
|
== SYNOPSIS
|
@@ -82,24 +90,54 @@ counts are correct, a little extra interfacing code may be necessary.
|
|
82
90
|
Lucky for you AE has already done the leg work for the most common
|
83
91
|
test frameworks:
|
84
92
|
|
85
|
-
|
86
|
-
|
87
|
-
|
93
|
+
require 'ae/adapters/testunit'
|
94
|
+
require 'ae/adapters/minitest'
|
95
|
+
require 'ae/adapters/rspec'
|
88
96
|
|
89
|
-
Note that Cucumber does not need an adapter.
|
97
|
+
(Note that Cucumber does not need an adapter.)
|
90
98
|
|
99
|
+
AE also includes a script that will automatically detect the current
|
100
|
+
test framework by checking for the existence of their respective
|
101
|
+
namespace modules.
|
91
102
|
|
92
|
-
|
103
|
+
require 'ae/adapter'
|
104
|
+
|
105
|
+
|
106
|
+
== NOMENCLATURE
|
107
|
+
|
108
|
+
With AE, defining assertions centers around the #assert method. So
|
109
|
+
*assert* can be thought of as AE's primary _nomenclature_. However, variant
|
110
|
+
nomenclatures have been popularized by other test frameworks, in particular
|
111
|
+
*should* and *must*. If you prefer one of them terms, AE provides optional
|
112
|
+
libraries that can loaded for utilizing them.
|
113
|
+
|
114
|
+
require 'ae/should'
|
115
|
+
require 'ae/must'
|
116
|
+
|
117
|
+
By loading one of these scripts (or both) into your test system (e.g. via a test
|
118
|
+
helper script) you gain access to subjunctive terminology. See the API documentation
|
119
|
+
for the Subjunctive module for details.
|
93
120
|
|
94
|
-
=== Gem Installs
|
95
121
|
|
96
|
-
|
97
|
-
installed do:
|
122
|
+
== LEGACY
|
98
123
|
|
99
|
-
|
100
|
-
|
124
|
+
To ease transition from TestUnit style assertion methods, AE provides
|
125
|
+
a TestUnit legacy module.
|
101
126
|
|
102
|
-
|
127
|
+
require 'ae/legacy'
|
128
|
+
|
129
|
+
This provides a module AE::Legacy::Assertions which is included in AE::World
|
130
|
+
and can be mixed into your test environment to provide old-school assertion
|
131
|
+
methods. E.g.
|
132
|
+
|
133
|
+
assert_equal(foo, bar, "it failed")
|
134
|
+
|
135
|
+
|
136
|
+
== INSTALLATION
|
137
|
+
|
138
|
+
=== Gem Installs
|
139
|
+
|
140
|
+
Install AE in the usual fashion:
|
103
141
|
|
104
142
|
$ gem install ae
|
105
143
|
|
@@ -129,6 +167,8 @@ Unless otherwise provided for by the originating author, this
|
|
129
167
|
program is distributed under the terms of the Apache 2.0 license.
|
130
168
|
See the Apache2.txt for details.
|
131
169
|
|
132
|
-
|
170
|
+
Portions of this program may be copyrighted by others. See the
|
133
171
|
NOTICE.rdoc file for details.
|
134
172
|
|
173
|
+
AE is a Rubyworks[http://rubyworks.github.com] project.
|
174
|
+
|
data/{Syckfile → Redfile}
RENAMED
@@ -22,11 +22,11 @@ stats:
|
|
22
22
|
rdoc:
|
23
23
|
service : rdoc
|
24
24
|
format : redfish
|
25
|
-
exclude : [
|
25
|
+
exclude : [Redfile, Profile, MANIFEST, Version]
|
26
26
|
output : site/doc/api
|
27
27
|
|
28
|
-
|
29
|
-
service:
|
28
|
+
ri:
|
29
|
+
service: RI
|
30
30
|
include: ~
|
31
31
|
exclude: ~
|
32
32
|
output : .ri
|
data/lib/ae.rb
CHANGED
data/lib/ae.yml
CHANGED
@@ -1,33 +1,45 @@
|
|
1
1
|
---
|
2
2
|
spec_version: 1.0.0
|
3
|
+
replaces: []
|
4
|
+
|
5
|
+
loadpath:
|
6
|
+
- lib
|
3
7
|
name: ae
|
4
|
-
|
5
|
-
|
8
|
+
repositories:
|
9
|
+
public: git://github.com/rubyworks/ae.git
|
10
|
+
conflicts: []
|
11
|
+
|
12
|
+
engine_check:
|
6
13
|
- ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
|
14
|
+
- ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
|
15
|
+
title: AE
|
7
16
|
contact: trans <transfire@gmail.com>
|
8
17
|
resources:
|
9
|
-
repo: git://github.com/rubyworks/ae.git
|
10
18
|
code: http://github.com/rubyworks/ae
|
11
19
|
mail: http://groups.google.com/group/rubyworks-mailinglist
|
12
20
|
docs: http://wiki.github.com/rubyworks/ae/docs/qed
|
13
|
-
bugs: http://github.com/rubyworks/ae/issues
|
14
21
|
wiki: http://wiki.github.com/rubyworks/ae
|
22
|
+
bugs: http://github.com/rubyworks/ae/issues
|
15
23
|
home: http://rubyworks.github.com/ae
|
24
|
+
maintainers: []
|
25
|
+
|
16
26
|
requires:
|
17
27
|
- group:
|
18
28
|
- build
|
19
|
-
name:
|
29
|
+
name: redline
|
20
30
|
version: 0+
|
21
31
|
- group:
|
22
32
|
- test
|
23
33
|
name: qed
|
24
34
|
version: 0+
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
manifest: MANIFEST
|
36
|
+
version: 1.7.1
|
37
|
+
licenses:
|
38
|
+
- Apache 2.0
|
28
39
|
copyright: Copyright (c) 2008 Thomas Sawyer
|
29
|
-
description: Assertive Expressive is an assertions library specifically designed for reuse by other test frameworks.
|
30
40
|
authors:
|
31
41
|
- Thomas Sawyer
|
42
|
+
organization: Rubyworks
|
43
|
+
description: Assertive Expressive is an assertions library specifically designed for reuse by other test frameworks.
|
32
44
|
summary: Assertive Expressive
|
33
45
|
created: 2008-08-17
|
data/lib/ae/adapter.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
if defined?(::
|
2
|
-
require 'ae/adapters/testunit'
|
3
|
-
elsif defined?(::MiniTest)
|
1
|
+
if defined?(::MiniTest)
|
4
2
|
require 'ae/adapters/minitest'
|
5
|
-
elsif defined?(::
|
3
|
+
elsif defined?(::Test::Unit)
|
4
|
+
require 'ae/adapters/testunit'
|
5
|
+
elsif defined?(::RSpec)
|
6
6
|
require 'ae/adapters/rspec'
|
7
7
|
end
|
8
|
+
|
data/lib/ae/adapters/minitest.rb
CHANGED
@@ -2,16 +2,35 @@ require 'ae'
|
|
2
2
|
|
3
3
|
AE.assertion_error = ::MiniTest::Assertion
|
4
4
|
|
5
|
-
# MiniTest tracks assertion counts internally in it's Unit class via the
|
6
|
-
# +assertion_count+ attribute. To work with AE we need add in AE's assertion
|
7
|
-
# total by overriding the +assertion_count+ method.
|
8
|
-
|
9
5
|
module MiniTest #:nodoc:
|
10
6
|
class Unit #:nodoc:
|
7
|
+
# MiniTest tracks assertion counts internally in it's Unit class via the
|
8
|
+
# +assertion_count+ attribute. To work with AE we need add in AE's assertion
|
9
|
+
# total by overriding the +assertion_count+ method.
|
11
10
|
def assertion_count
|
12
11
|
@assertion_count + AE::Assertor.counts[:total]
|
13
12
|
end
|
13
|
+
# To teach MiniTest to recognize AE's expanded concept of assertions
|
14
|
+
# we add in an extra capture clause to the it's #puke method.
|
15
|
+
def puke c, m, x
|
16
|
+
case x
|
17
|
+
when MiniTest::Skip
|
18
|
+
@skips = @skips + 1
|
19
|
+
x = "Skipped:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n"
|
20
|
+
when MiniTest::Assertion
|
21
|
+
@failures = @failures + 1
|
22
|
+
x = "Failure:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n"
|
23
|
+
when x.respond_to?(:assertion?) && x.assertion?
|
24
|
+
@failures = @failures + 1
|
25
|
+
x = "Failure:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n"
|
26
|
+
else
|
27
|
+
@errors = @errors + 1
|
28
|
+
b = MiniTest::filter_backtrace(x.backtrace).join("\n ")
|
29
|
+
x = "Error:\n#{m}(#{c}):\n#{x.class}: #{x.message}\n #{b}\n"
|
30
|
+
end
|
31
|
+
@report << x
|
32
|
+
x[0, 1]
|
33
|
+
end
|
14
34
|
end
|
15
35
|
end
|
16
36
|
|
17
|
-
|
data/lib/ae/adapters/rspec.rb
CHANGED
data/lib/ae/adapters/testunit.rb
CHANGED
@@ -6,15 +6,52 @@ AE.assertion_error = ::Test::Unit::AssertionFailedError
|
|
6
6
|
# We capture the result object by overriding the TestCase#run method,
|
7
7
|
# store it in a global variable and then use it when AE increments
|
8
8
|
# assertion counts.
|
9
|
+
#
|
10
|
+
# In addition we teach #run to recognize any Exception class that
|
11
|
+
# responds to #assertion? in the affirmative as an assertion
|
12
|
+
# rather than an error.
|
9
13
|
|
10
14
|
module Test #:nodoc:
|
11
15
|
module Unit #:nodoc:
|
12
16
|
class TestCase #:nodoc:
|
13
|
-
|
14
|
-
|
17
|
+
# These exceptions are not caught by #run.
|
18
|
+
PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt, SystemExit]
|
19
|
+
# Runs the individual test method represented by this
|
20
|
+
# instance of the fixture, collecting statistics, failures
|
21
|
+
# and errors in result.
|
22
|
+
def run(result)
|
15
23
|
$_test_unit_result = result
|
16
|
-
|
17
|
-
|
24
|
+
yield(STARTED, name)
|
25
|
+
@_result = result
|
26
|
+
begin
|
27
|
+
setup
|
28
|
+
__send__(@method_name)
|
29
|
+
rescue AssertionFailedError => e
|
30
|
+
add_failure(e.message, e.backtrace)
|
31
|
+
rescue Exception => e
|
32
|
+
if e.respond_to?(:assertion?) && e.assertion?
|
33
|
+
add_failure(e.message, e.backtrace)
|
34
|
+
else
|
35
|
+
raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
|
36
|
+
add_error($!)
|
37
|
+
end
|
38
|
+
ensure
|
39
|
+
begin
|
40
|
+
teardown
|
41
|
+
rescue AssertionFailedError => e
|
42
|
+
add_failure(e.message, e.backtrace)
|
43
|
+
rescue Exception => e
|
44
|
+
if e.respond_to?(:assertion?) && e.assertion?
|
45
|
+
add_failure(e.message, e.backtrace)
|
46
|
+
else
|
47
|
+
raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
|
48
|
+
add_error($!)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
result.add_run
|
53
|
+
yield(FINISHED, name)
|
54
|
+
end
|
18
55
|
end
|
19
56
|
end
|
20
57
|
end
|
data/lib/ae/assert.rb
CHANGED
@@ -59,7 +59,7 @@ module AE
|
|
59
59
|
# Directly raise an Assertion failure.
|
60
60
|
def flunk(message=nil, backtrace=nil)
|
61
61
|
#Assertor.new(self, :backtrace=>caller).assert(false, message)
|
62
|
-
Assertor.assert(false, message, caller)
|
62
|
+
Assertor.assert(false, message, backtrace || caller)
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
data/lib/ae/assertion.rb
CHANGED
data/lib/ae/assertor.rb
CHANGED
@@ -27,17 +27,17 @@ module AE
|
|
27
27
|
|
28
28
|
# Reset assertion counts.
|
29
29
|
#
|
30
|
-
# reset - Hash which
|
30
|
+
# reset - Hash which can be used to set counts manually (optional).
|
31
31
|
#
|
32
32
|
# Returns the Hash of previous counts.
|
33
|
-
def self.recount(reset=
|
33
|
+
def self.recount(reset=nil)
|
34
34
|
old_counts = counts.dup
|
35
|
-
if reset
|
36
|
-
counts.replace(ZERO_COUNTS.dup)
|
37
|
-
else
|
35
|
+
if reset
|
38
36
|
reset.each do |type, value|
|
39
37
|
counts[type.to_sym] = value
|
40
38
|
end
|
39
|
+
else
|
40
|
+
counts.replace(ZERO_COUNTS.dup)
|
41
41
|
end
|
42
42
|
return old_counts
|
43
43
|
end
|
@@ -57,25 +57,25 @@ module AE
|
|
57
57
|
|
58
58
|
# Basic assertion. This method by-passes all the Assertor fluent
|
59
59
|
# constructs and performs the underlying assertion procedure. It
|
60
|
-
# is used by Assertor as the end
|
61
|
-
def self.assert(pass,
|
60
|
+
# is used by Assertor as the end call of an assertion.
|
61
|
+
def self.assert(pass, error=nil, negated=nil, backtrace=nil)
|
62
|
+
pass = negated ^ !!pass
|
62
63
|
increment_counts(pass)
|
63
64
|
if !pass
|
64
65
|
backtrace = backtrace || caller
|
65
|
-
|
66
|
-
raise_assertion(message, backtrace)
|
66
|
+
raise_assertion(error, negated, backtrace)
|
67
67
|
end
|
68
68
|
return pass
|
69
69
|
end
|
70
70
|
|
71
|
-
#
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
error
|
78
|
-
error.set_backtrace(backtrace)
|
71
|
+
# The intent of the method is to raise an assertion failure
|
72
|
+
# class that the test framework supports.
|
73
|
+
def self.raise_assertion(error, negated, backtrace=nil)
|
74
|
+
if not Exception === error
|
75
|
+
error = assertion_error.new(error)
|
76
|
+
end
|
77
|
+
error.set_negative(negated)
|
78
|
+
error.set_backtrace(backtrace || caller)
|
79
79
|
error.set_assertion(true)
|
80
80
|
fail error
|
81
81
|
end
|
@@ -85,6 +85,22 @@ module AE
|
|
85
85
|
::Assertion
|
86
86
|
end
|
87
87
|
|
88
|
+
# NOT HAPPENING
|
89
|
+
## Is ::Assay defined. This is used for integration of the Assay library.
|
90
|
+
#def self.assay?
|
91
|
+
# @_assay ||= defined?(::Assay)
|
92
|
+
#end
|
93
|
+
|
94
|
+
#
|
95
|
+
#def self.message(sym, neg, *args, &blk)
|
96
|
+
# if method = Message.lookup(sym)
|
97
|
+
# method = "non_#{method}" if neg
|
98
|
+
# Message.send(method, *args, &blk)
|
99
|
+
# else
|
100
|
+
# nil
|
101
|
+
# end
|
102
|
+
#end
|
103
|
+
|
88
104
|
#
|
89
105
|
if ::RUBY_VERSION >= '1.9'
|
90
106
|
eval "private :==, :!, :!=" # using eval here b/c it's a syntax error in 1.8-
|
@@ -124,31 +140,45 @@ module AE
|
|
124
140
|
# assert something, parameter
|
125
141
|
#
|
126
142
|
# Returns +true+ or +false+ based on assertions success.
|
143
|
+
#--
|
144
|
+
# The use of #to_proc and #matches? as sepcial cases is not
|
145
|
+
# a robust solution.
|
146
|
+
#++
|
127
147
|
def assert(*args, &block)
|
128
148
|
return self if args.empty? && !block
|
129
149
|
|
130
150
|
target = block || args.shift
|
151
|
+
error = nil
|
131
152
|
|
153
|
+
# Lambda
|
132
154
|
if ::Proc === target || target.respond_to?(:to_proc)
|
133
155
|
block = target.to_proc
|
134
156
|
match = args.shift
|
135
157
|
result = block.arity > 0 ? block.call(@delegate) : block.call
|
136
158
|
if match
|
137
|
-
pass
|
138
|
-
|
159
|
+
pass = (match == result)
|
160
|
+
error = @message || "#{match.inspect} == #{result.inspect}"
|
139
161
|
else
|
140
|
-
pass
|
141
|
-
|
162
|
+
pass = result
|
163
|
+
error = @message || block.inspect # "#{result.inspect}"
|
142
164
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
165
|
+
|
166
|
+
# Matcher
|
167
|
+
elsif target.respond_to?(:matches?) # Matchers
|
168
|
+
pass = target.matches?(@delegate)
|
169
|
+
error = @message || matcher_message(target) #|| target.inspect
|
170
|
+
if target.respond_to?(:exception)
|
171
|
+
#error_class = target.failure_class
|
172
|
+
error = target.exception #(:backtrace=>@backtrace, :negated=>@negated)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Truthiness
|
146
176
|
else
|
147
|
-
pass
|
148
|
-
|
177
|
+
pass = target # truthiness
|
178
|
+
error = args.shift # optional message for TestUnit compatiability
|
149
179
|
end
|
150
180
|
|
151
|
-
__assert__(pass,
|
181
|
+
__assert__(pass, error)
|
152
182
|
end
|
153
183
|
|
154
184
|
# Internal expect, provides all functionality associated
|
@@ -162,7 +192,9 @@ module AE
|
|
162
192
|
return self if args.empty? && !block # same as #assert
|
163
193
|
|
164
194
|
target = block || args.shift
|
195
|
+
error = nil
|
165
196
|
|
197
|
+
# Lambda
|
166
198
|
if ::Proc === target #|| target.respond_to?(:to_proc)
|
167
199
|
#block = target.to_proc
|
168
200
|
match = args.shift || @delegate
|
@@ -170,31 +202,39 @@ module AE
|
|
170
202
|
$DEBUG, debug = false, $DEBUG # b/c it always spits-out a NameError
|
171
203
|
begin
|
172
204
|
block.arity > 0 ? block.call(@delegate) : block.call
|
173
|
-
pass
|
174
|
-
|
205
|
+
pass = false
|
206
|
+
error = "#{match} not raised"
|
175
207
|
rescue match => error
|
176
|
-
pass
|
177
|
-
|
208
|
+
pass = true
|
209
|
+
error = "#{match} raised"
|
178
210
|
rescue ::Exception => error
|
179
|
-
pass
|
180
|
-
|
211
|
+
pass = false
|
212
|
+
error = "#{match} expected but #{error.class} was raised"
|
181
213
|
ensure
|
182
214
|
$DEBUG = debug
|
183
215
|
end
|
184
216
|
else
|
185
217
|
result = block.arity > 0 ? block.call(@delegte) : block.call
|
186
218
|
pass = (match === result)
|
187
|
-
|
219
|
+
error = @message || "#{match.inspect} === #{result.inspect}"
|
188
220
|
end
|
221
|
+
|
222
|
+
# Matcher
|
189
223
|
elsif target.respond_to?(:matches?)
|
190
|
-
pass
|
191
|
-
|
224
|
+
pass = target.matches?(@delegate)
|
225
|
+
error = @message || matcher_message(target) #|| target.inspect
|
226
|
+
if target.respond_to?(:exception)
|
227
|
+
#error_class = target.failure_class
|
228
|
+
error = target.exception #failure(:backtrace=>@backtrace, :negated=>@negated)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Case Equals
|
192
232
|
else
|
193
|
-
pass
|
194
|
-
|
233
|
+
pass = (target === @delegate)
|
234
|
+
error = @message || "#{target.inspect} === #{@delegate.inspect}"
|
195
235
|
end
|
196
236
|
|
197
|
-
__assert__(pass,
|
237
|
+
__assert__(pass, error)
|
198
238
|
end
|
199
239
|
|
200
240
|
#
|
@@ -233,30 +273,21 @@ module AE
|
|
233
273
|
# Converts a missing method into an Assertion.
|
234
274
|
#
|
235
275
|
# TODO: In future should probably be `@delegate.public_send(sym, *a, &b)`.
|
236
|
-
def method_missing(sym, *
|
237
|
-
|
238
|
-
__assert__(pass, @message || __msg__(sym, *a, &b))
|
239
|
-
end
|
276
|
+
def method_missing(sym, *args, &block)
|
277
|
+
error = @message || compare_message(sym, *args, &block) || generic_message(sym, *args, &block)
|
240
278
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
inspection = @delegate.send(:inspect)
|
245
|
-
if @negated
|
246
|
-
"! #{inspection} #{m} #{a.collect{|x| x.inspect}.join(',')}"
|
247
|
-
else
|
248
|
-
"#{inspection} #{m} #{a.collect{|x| x.inspect}.join(',')}"
|
249
|
-
end
|
250
|
-
#self.class.message(m)[@delegate, *a] )
|
279
|
+
pass = @delegate.__send__(sym, *args, &block)
|
280
|
+
|
281
|
+
__assert__(pass, error)
|
251
282
|
end
|
252
283
|
|
284
|
+
|
253
285
|
# Simple assert.
|
254
286
|
#--
|
255
287
|
# TODO: Can the handling of the message be simplified/improved?
|
256
288
|
#++
|
257
|
-
def __assert__(pass,
|
258
|
-
pass
|
259
|
-
Assertor.assert(pass, message, @backtrace)
|
289
|
+
def __assert__(pass, error=nil)
|
290
|
+
Assertor.assert(pass, error, @negated, @backtrace)
|
260
291
|
end
|
261
292
|
|
262
293
|
#
|
@@ -265,21 +296,49 @@ module AE
|
|
265
296
|
if matcher.respond_to?(:negative_failure_message)
|
266
297
|
return matcher.failure_message
|
267
298
|
end
|
299
|
+
else
|
300
|
+
if matcher.respond_to?(:failure_message)
|
301
|
+
return matcher.failure_message
|
302
|
+
end
|
268
303
|
end
|
269
|
-
|
270
|
-
|
304
|
+
return nil
|
305
|
+
end
|
306
|
+
|
307
|
+
COMPARISON_OPERATORS = { :"==" => :"!=" }
|
308
|
+
|
309
|
+
# Message to use when making a comparion assertion.
|
310
|
+
def compare_message(operator, *args, &blk)
|
311
|
+
return nil unless COMPARISON_OPERATORS.key?(operator)
|
312
|
+
prefix = ""
|
313
|
+
a, b = @delegate, args.first
|
314
|
+
if @negated
|
315
|
+
op = COMPARISON_OPERATORS[operator]
|
316
|
+
if op
|
317
|
+
operator = op
|
318
|
+
else
|
319
|
+
prefix = "NOT "
|
320
|
+
end
|
321
|
+
end
|
322
|
+
if a.size > 13 or b.size > 13
|
323
|
+
diff = ANSI::Diff.new(a,b)
|
324
|
+
prefix + "a #{operator} b\na) " + diff.diff1 + "\nb) " + diff.diff2
|
325
|
+
else
|
326
|
+
prefix + "#{a.inspect} #{operator} #{b.inspect}"
|
271
327
|
end
|
272
|
-
false
|
273
328
|
end
|
274
329
|
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#def self.message(op,&block)
|
278
|
-
# @message ||= {}
|
279
|
-
# block ? @message[op.to_sym] = block : @message[op.to_sym]
|
280
|
-
#end
|
330
|
+
# Puts together a suitable error message.
|
281
331
|
#
|
282
|
-
|
332
|
+
def generic_message(op, *a, &b)
|
333
|
+
inspection = @delegate.send(:inspect)
|
334
|
+
if @negated
|
335
|
+
"! #{inspection} #{op} #{a.collect{|x| x.inspect}.join(',')}"
|
336
|
+
else
|
337
|
+
"#{inspection} #{op} #{a.collect{|x| x.inspect}.join(',')}"
|
338
|
+
end
|
339
|
+
#self.class.message(m)[@delegate, *a] )
|
340
|
+
end
|
341
|
+
|
283
342
|
end
|
284
343
|
|
285
344
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Exception
|
2
2
|
# Is this exception the result of an assertion?
|
3
3
|
def assertion?
|
4
|
-
@assertion
|
4
|
+
@assertion || false
|
5
5
|
end
|
6
6
|
|
7
7
|
# Set +true+/+false+ if the this exception is
|
@@ -9,5 +9,15 @@ class Exception
|
|
9
9
|
def set_assertion(boolean)
|
10
10
|
@assertion = !!boolean
|
11
11
|
end
|
12
|
+
|
13
|
+
#
|
14
|
+
def negative?
|
15
|
+
@negative || false
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
def set_negative(boolean)
|
20
|
+
@negative = !!boolean
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
data/lib/ae/legacy.rb
CHANGED
@@ -275,13 +275,6 @@ module AE
|
|
275
275
|
|
276
276
|
end #module Legacy
|
277
277
|
|
278
|
-
# # This could be in Object, but since they will only be needed in
|
279
|
-
# # the context of a, well, Context...
|
280
|
-
# #
|
281
|
-
# class Context #:nodoc:
|
282
|
-
# include Legacy::Assertions
|
283
|
-
# end
|
284
|
-
|
285
278
|
module World
|
286
279
|
include AE::Legacy::Assertions
|
287
280
|
end
|
data/lib/ae/must.rb
CHANGED
@@ -33,7 +33,7 @@ module AE
|
|
33
33
|
|
34
34
|
# Perhaps not literally the counter-term to *must* (rather *will*),
|
35
35
|
# it is close enough for our purposes and conveys the appropriate
|
36
|
-
# semantics, and I think more sightly than *mustnt*.
|
36
|
+
# semantics, and I think is more sightly than *mustnt*.
|
37
37
|
#
|
38
38
|
# This method may be deprecated in the future when Ruby 1.9 becomes
|
39
39
|
# mainstream, as it allows for redefining *#!* as a method.
|
data/lib/ae/pry.rb
CHANGED
@@ -13,7 +13,10 @@ module Kernel
|
|
13
13
|
# considered implementation details. But sometimes is necessary
|
14
14
|
# to test them directly, or if you wish to achieve *absolute
|
15
15
|
# coverage*, say in mission critical systems.
|
16
|
-
|
16
|
+
#
|
17
|
+
#--
|
18
|
+
# TODO: Is th cache really neccessry?
|
19
|
+
#++
|
17
20
|
def pry
|
18
21
|
$PRY_TABLE[self] ||= Pry.new do |op, *a, &b|
|
19
22
|
__send__(op, *a, &b)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 1.7.
|
9
|
+
- 1
|
10
|
+
version: 1.7.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thomas Sawyer
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: redline
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -75,8 +75,6 @@ files:
|
|
75
75
|
- lib/ae/core_ext/exception.rb
|
76
76
|
- lib/ae/core_ext/helpers.rb
|
77
77
|
- lib/ae/core_ext.rb
|
78
|
-
- lib/ae/detest.rb
|
79
|
-
- lib/ae/dot.rb
|
80
78
|
- lib/ae/expect.rb
|
81
79
|
- lib/ae/legacy.rb
|
82
80
|
- lib/ae/must.rb
|
@@ -86,10 +84,10 @@ files:
|
|
86
84
|
- lib/ae/version.rb
|
87
85
|
- lib/ae.rb
|
88
86
|
- lib/ae.yml
|
87
|
+
- HISTORY.rdoc
|
88
|
+
- APACHE2.txt
|
89
89
|
- README.rdoc
|
90
|
-
-
|
91
|
-
- Syckfile
|
92
|
-
- History.rdoc
|
90
|
+
- Redfile
|
93
91
|
- NOTICE.rdoc
|
94
92
|
has_rdoc: true
|
95
93
|
homepage: http://rubyworks.github.com/ae
|
data/lib/ae/detest.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'ae/assertion'
|
2
|
-
|
3
|
-
class AE
|
4
|
-
# Given that x is "tom" then we can assert it
|
5
|
-
# is using an asseretion pipe.
|
6
|
-
#
|
7
|
-
# x = "tom"
|
8
|
-
#
|
9
|
-
# T x == "tom"
|
10
|
-
#
|
11
|
-
# We can assert the opposite using F.
|
12
|
-
#
|
13
|
-
# F x == "tom"
|
14
|
-
#
|
15
|
-
# These can be used at any point of return.
|
16
|
-
#
|
17
|
-
# T case x
|
18
|
-
# when 'tom' then true
|
19
|
-
# else false
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
module Detest
|
23
|
-
|
24
|
-
# Test for true.
|
25
|
-
#
|
26
|
-
# T 1 == 1
|
27
|
-
#
|
28
|
-
def T(x=nil, &b)
|
29
|
-
Assertion.test(x || b.call, :backtrace=>caller)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Test for not.
|
33
|
-
#
|
34
|
-
# F 1 == 2
|
35
|
-
#
|
36
|
-
def F(x=nil, &b)
|
37
|
-
Assertion.test(!(x || b.call), :backtrace=>caller)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Test for nil?.
|
41
|
-
#
|
42
|
-
# N nil
|
43
|
-
#
|
44
|
-
def N(x=nil,&b)
|
45
|
-
Assertion.test(nil == (x || b.call), :backtrace=>caller)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Expect and error.
|
49
|
-
#
|
50
|
-
# E { raise }
|
51
|
-
#
|
52
|
-
# Unless #T, #F and #N, the #E method only supports block notation.
|
53
|
-
def E(&b)
|
54
|
-
expect(Exception, &b)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Catch a symbol.
|
58
|
-
#def C
|
59
|
-
#end
|
60
|
-
end
|
61
|
-
|
62
|
-
module World
|
63
|
-
include AE::Detest
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
|
data/lib/ae/dot.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Expiremental Concept
|
2
|
-
|
3
|
-
#
|
4
|
-
class TrueClass
|
5
|
-
# Assert true.
|
6
|
-
#
|
7
|
-
# (x == y).true!
|
8
|
-
#
|
9
|
-
def true!(msg=nil)
|
10
|
-
true
|
11
|
-
end
|
12
|
-
# Assert false.
|
13
|
-
#
|
14
|
-
# (x == y).false!
|
15
|
-
#
|
16
|
-
def false!(err="not false")
|
17
|
-
if Exception === err
|
18
|
-
fail err
|
19
|
-
else
|
20
|
-
fail Assertion.new(err.to_s, :backtrace=>caller)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class FalseClass
|
26
|
-
# Assert true.
|
27
|
-
#
|
28
|
-
# (x == y).true!
|
29
|
-
#
|
30
|
-
def true!(err="not true")
|
31
|
-
if Exception === err
|
32
|
-
fail err
|
33
|
-
else
|
34
|
-
fail Assertion.new(err.to_s, :backtrace=>caller)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
# Assert false.
|
38
|
-
#
|
39
|
-
# (x == y).false!
|
40
|
-
#
|
41
|
-
def false!(msg=nil)
|
42
|
-
true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|