assay 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/.ruby +46 -41
- data/COPYING.rdoc +38 -0
- data/HISTORY.rdoc +18 -1
- data/QED.rdoc +1100 -0
- data/README.rdoc +139 -16
- data/lib/assay.rb +82 -29
- data/lib/assay.yml +46 -41
- data/lib/assay/{adapters → adapter}/minitest.rb +0 -0
- data/lib/assay/{adapters → adapter}/testunit.rb +0 -0
- data/lib/assay/assertable.rb +174 -0
- data/lib/assay/assertion.rb +98 -124
- data/lib/assay/assertor.rb +187 -0
- data/lib/assay/boolean_assay.rb +15 -0
- data/lib/assay/case_assay.rb +17 -0
- data/lib/assay/compare_assay.rb +38 -0
- data/lib/assay/core_ext/kernel.rb +52 -0
- data/lib/assay/core_ext/na.rb +9 -0
- data/lib/assay/directory_assay.rb +20 -0
- data/lib/assay/empty_assay.rb +17 -0
- data/lib/assay/equal_assay.rb +35 -0
- data/lib/assay/equality_assay.rb +18 -0
- data/lib/assay/execution_assay.rb +59 -0
- data/lib/assay/false_assay.rb +17 -0
- data/lib/assay/file_assay.rb +17 -0
- data/lib/assay/identity_assay.rb +49 -0
- data/lib/assay/include_assay.rb +17 -0
- data/lib/assay/instance_assay.rb +17 -0
- data/lib/assay/kind_assay.rb +18 -0
- data/lib/assay/less_assay.rb +18 -0
- data/lib/assay/less_equal_assay.rb +25 -0
- data/lib/assay/like_assay.rb +17 -0
- data/lib/assay/match_assay.rb +17 -0
- data/lib/assay/more_assay.rb +18 -0
- data/lib/assay/more_equal_assay.rb +25 -0
- data/lib/assay/nil_assay.rb +15 -0
- data/lib/assay/nomatch_assay.rb +17 -0
- data/lib/assay/output_assay.rb +35 -0
- data/lib/assay/path_assay.rb +17 -0
- data/lib/assay/raise_assay.rb +109 -0
- data/lib/assay/rescue_assay.rb +55 -0
- data/lib/assay/respond_assay.rb +17 -0
- data/lib/assay/return_assay.rb +46 -0
- data/lib/assay/silent_assay.rb +59 -0
- data/lib/assay/stderr_assay.rb +30 -0
- data/lib/assay/stdout_assay.rb +30 -0
- data/lib/assay/throw_assay.rb +89 -0
- data/lib/assay/true_assay.rb +20 -0
- data/lib/assay/unequal_assay.rb +37 -0
- data/lib/assay/within_assay.rb +39 -0
- data/test/case_compare_assay.rb +59 -0
- data/test/case_empty_assay.rb +51 -0
- data/test/case_equal_assay.rb +53 -0
- data/test/case_equality_assay.rb +55 -0
- data/test/case_false_assay.rb +48 -0
- data/test/case_identity_assay.rb +51 -0
- data/test/case_include_assay.rb +51 -0
- data/test/case_instance_assay.rb +51 -0
- data/test/case_kind_assay.rb +51 -0
- data/test/case_less_assay.rb +53 -0
- data/test/case_less_equal_assay.rb +53 -0
- data/test/case_like_assay.rb +57 -0
- data/test/case_match_assay.rb +45 -0
- data/test/case_more_assay.rb +53 -0
- data/test/case_more_equal_assay.rb +53 -0
- data/test/case_nil_assay.rb +48 -0
- data/test/case_nomatch_assay.rb +47 -0
- data/test/case_raise_assay.rb +51 -0
- data/test/case_respond_assay.rb +51 -0
- data/test/case_throw_assay.rb +51 -0
- data/test/case_true_assay.rb +48 -0
- data/test/case_unequal_assay.rb +55 -0
- data/test/case_within_assay.rb +61 -0
- data/test/helper.rb +36 -0
- metadata +135 -108
- data/APACHE2.txt +0 -205
- data/NOTICE.rdoc +0 -18
- data/lib/assay/assertions/compare_failure.rb +0 -61
- data/lib/assay/assertions/delta_failure.rb +0 -80
- data/lib/assay/assertions/empty_failure.rb +0 -76
- data/lib/assay/assertions/equality_failure.rb +0 -100
- data/lib/assay/assertions/execution_failure.rb +0 -90
- data/lib/assay/assertions/false_failure.rb +0 -72
- data/lib/assay/assertions/identity_failure.rb +0 -85
- data/lib/assay/assertions/instance_failure.rb +0 -76
- data/lib/assay/assertions/kind_failure.rb +0 -80
- data/lib/assay/assertions/match_failure.rb +0 -85
- data/lib/assay/assertions/nil_failure.rb +0 -75
- data/lib/assay/assertions/raise_failure.rb +0 -134
- data/lib/assay/assertions/response_failure.rb +0 -86
- data/lib/assay/assertions/same_failure.rb +0 -82
- data/lib/assay/assertions/throw_failure.rb +0 -122
- data/lib/assay/assertions/true_failure.rb +0 -79
- data/lib/assay/matcher.rb +0 -48
- data/qed/01_failure_classes.rdoc +0 -75
- data/qed/02_assertives.rdoc +0 -118
- data/qed/03_matchers.rdoc +0 -118
- data/qed/04_lookup.rdoc +0 -10
data/NOTICE.rdoc
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
= COPYRIGHT NOTICES
|
2
|
-
|
3
|
-
== Assay
|
4
|
-
|
5
|
-
Copyright 2009 Thomas Sawyer
|
6
|
-
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
you may not use this file except in compliance with the License.
|
9
|
-
You may obtain a copy of the License at
|
10
|
-
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
|
13
|
-
Unless required by applicable law or agreed to in writing, software
|
14
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
See the License for the specific language governing permissions and
|
17
|
-
limitations under the License.
|
18
|
-
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'assay/assertion'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
class CompareFailure < Assertion
|
6
|
-
|
7
|
-
def self.assertion_name
|
8
|
-
:like
|
9
|
-
end
|
10
|
-
|
11
|
-
# Test assertion.
|
12
|
-
def self.pass?(exp, act)
|
13
|
-
exp.equal?(act) ||
|
14
|
-
exp.eq?(act) ||
|
15
|
-
exp.==(act) ||
|
16
|
-
exp.===(act)
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
def to_s
|
21
|
-
return @mesg if @mesg
|
22
|
-
return super unless @arguments.size == 2
|
23
|
-
|
24
|
-
iexp = @arguments[0].inspect
|
25
|
-
iact = @arguments[1].inspect
|
26
|
-
|
27
|
-
if @_negated
|
28
|
-
"Expected #{iact} to NOT be like #{iexp}"
|
29
|
-
else
|
30
|
-
"Expected #{iact} to be like #{iexp}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
module Assertives
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
module Matchers
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# object1.should be_like(object2)
|
46
|
-
#
|
47
|
-
def be_like(act)
|
48
|
-
CompareFailure.to_matcher(act)
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# object1.should be_like(object2)
|
54
|
-
#
|
55
|
-
def is_like(act)
|
56
|
-
CompareFailure.to_matcher(act)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'assay/assertions/compare_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
# TODO: Support Range
|
6
|
-
class DeltaFailure < CompareFailure
|
7
|
-
|
8
|
-
#
|
9
|
-
def self.assertion_name
|
10
|
-
:in_delta
|
11
|
-
end
|
12
|
-
|
13
|
-
# Check assertion.
|
14
|
-
def self.pass?(exp, act, delta)
|
15
|
-
case delta
|
16
|
-
when Numeric
|
17
|
-
(exp.to_f - act.to_f).abs <= delta.to_f
|
18
|
-
else
|
19
|
-
exp - act <= delta
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
def to_s
|
25
|
-
return @mesg if @mesg
|
26
|
-
return super unless @arguments.size == 3
|
27
|
-
|
28
|
-
exp = @arguments[0].inspect
|
29
|
-
act = @arguments[1].inspect
|
30
|
-
delta = @arguments[2].inspect
|
31
|
-
|
32
|
-
if @_negated
|
33
|
-
"Expected #{exp} to NOT be within #{delta} of #{act}"
|
34
|
-
else
|
35
|
-
"Expected #{exp} to be within #{delta} of #{act}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
module Assertives
|
43
|
-
# Passes if expected and actual are equal within delta tolerance.
|
44
|
-
#
|
45
|
-
# assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
|
46
|
-
#
|
47
|
-
def assert_in_delta(exp, act, delta, msg=nil)
|
48
|
-
DeltaFailure.assert(exp, act, delta, :message=>msg, :backtrace=>caller)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Passes if expected and actual are equal not within delta tolerance.
|
52
|
-
#
|
53
|
-
# assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001
|
54
|
-
#
|
55
|
-
def self.not_in_delta(exp, act, delta, msg=nil)
|
56
|
-
opts[:backtrace] ||= caller
|
57
|
-
DeltaFailure.refute(exp, act, delta, :message=>msg, :backtrace=>caller)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
module Matchers
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# value1.should be_within(delta, value2)
|
66
|
-
#
|
67
|
-
def is_within(delta, act)
|
68
|
-
DeltaFailure.to_matcher(act, delta)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# value1.assert is_within(delta, value2)
|
74
|
-
#
|
75
|
-
def be_within(delta, act)
|
76
|
-
DeltaFailure.to_matcher(act, delta)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'assay/assertion'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
class EmptyFailure < Assertion
|
6
|
-
|
7
|
-
def self.assertion_name
|
8
|
-
:empty
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.assertion_operator
|
12
|
-
:empty?
|
13
|
-
end
|
14
|
-
|
15
|
-
# Check assertion.
|
16
|
-
def self.pass?(exp)
|
17
|
-
exp.empty?
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
def to_s
|
22
|
-
return @mesg if @mesg
|
23
|
-
return super unless @arguments.size == 1
|
24
|
-
|
25
|
-
exp = @arguments.first.inspect
|
26
|
-
|
27
|
-
if @_negated
|
28
|
-
"Expected #{exp} to NOT be empty"
|
29
|
-
else
|
30
|
-
"Expected #{exp} to be empty"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
module Assertives
|
38
|
-
# Passed if object is +true+.
|
39
|
-
#
|
40
|
-
def assert_empty(exp, msg=nil)
|
41
|
-
EmptyFailure.assert(exp, :message=>msg, :backtrace=>caller)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Passed if object is not +true+.
|
45
|
-
#
|
46
|
-
# assert_not_true(false)
|
47
|
-
#
|
48
|
-
def refute_empty(exp, msg=nil)
|
49
|
-
opts[:backtrace] ||= caller
|
50
|
-
EmptyFailure.refute(exp, :message=>msg, :backtrace=>caller)
|
51
|
-
end
|
52
|
-
|
53
|
-
alias_method :assert_not_empty, :refute_empty
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
module Matchers
|
58
|
-
# Empty?
|
59
|
-
#
|
60
|
-
# object.assert is_true
|
61
|
-
#
|
62
|
-
def is_empty
|
63
|
-
EmptyFailure.to_matcher
|
64
|
-
end
|
65
|
-
|
66
|
-
# Empty?
|
67
|
-
#
|
68
|
-
# object.should be_empty
|
69
|
-
#
|
70
|
-
def be_empty
|
71
|
-
EmptyFailure.to_matcher
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'assay/assertions/compare_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
#
|
6
|
-
class EqualityFailure < CompareFailure
|
7
|
-
|
8
|
-
#
|
9
|
-
def self.assertion_name
|
10
|
-
:equal
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
def self.assertion_operator
|
15
|
-
:==
|
16
|
-
end
|
17
|
-
|
18
|
-
# Check assertion.
|
19
|
-
def self.pass?(exp, act)
|
20
|
-
exp == act
|
21
|
-
end
|
22
|
-
|
23
|
-
# Check negated assertion.
|
24
|
-
def self.fail?(exp, act)
|
25
|
-
exp != act
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
def to_s
|
30
|
-
return @mesg if @mesg
|
31
|
-
return super unless @arguments.size == 2
|
32
|
-
|
33
|
-
oper = @_negated ? "!=" : "=="
|
34
|
-
iexp = @arguments[0].inspect
|
35
|
-
iact = @arguments[1].inspect
|
36
|
-
|
37
|
-
if iexp.size > SIZE_LIMIT or iact.size > SIZE_LIMIT
|
38
|
-
diff = ANSI::Diff.new(iact, iexp)
|
39
|
-
"a #{oper} b\na) #{diff.diff1}\nb) #{diff.diff2}"
|
40
|
-
else
|
41
|
-
"#{iact} #{oper} #{iexp}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
module Assertives
|
49
|
-
# Passes if expected == +actual.
|
50
|
-
#
|
51
|
-
# Note that the ordering of arguments is important,
|
52
|
-
# since a helpful error message is generated when this
|
53
|
-
# one fails that tells you the values of expected and actual.
|
54
|
-
#
|
55
|
-
# assert_equal 'MY STRING', 'my string'.upcase
|
56
|
-
#
|
57
|
-
def assert_equal(exp, act, msg=nil)
|
58
|
-
EqualityFailure.assert(exp, act, :message=>msg, :backtrace=>caller)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Passes if expected != actual
|
62
|
-
#
|
63
|
-
# assert_not_equal 'some string', 5
|
64
|
-
#
|
65
|
-
def assert_not_equal(exp, act, msg=nil)
|
66
|
-
EqualityFailure.refute(exp, act, :message=>msg, :backtrace=>caller)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
module Matchers
|
72
|
-
# Passes if +expected+ == +actual+.
|
73
|
-
#
|
74
|
-
# 'MY STRING'.assert is_equal_to('my string'.upcase)
|
75
|
-
# 'MY STRING'.refute is_equal_to('another string')
|
76
|
-
#
|
77
|
-
def is_equal_to(exp, opts={})
|
78
|
-
EqualityFailure.to_matcher(exp)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Passes if +expected+ == +actual+.
|
82
|
-
#
|
83
|
-
# 'MY STRING'.should be_equal_to('my string'.upcase)
|
84
|
-
# 'MY STRING'.should_not be_equal_to('another string')
|
85
|
-
#
|
86
|
-
def be_equal_to(exp)
|
87
|
-
EqualityFailure.to_matcher(exp)
|
88
|
-
end
|
89
|
-
|
90
|
-
## # Passes if expected != actual
|
91
|
-
## #
|
92
|
-
## # 'some string'.should not_be_equal_to('foo')
|
93
|
-
## #
|
94
|
-
## def not_be_equal_to(exp, act, opts)
|
95
|
-
## opts[:backtrace] ||= caller
|
96
|
-
## EqualityFailure.to_matcher!(exp, opts)
|
97
|
-
## end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'assay/assertion'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
# Assert that a block of coded executes without error.
|
6
|
-
#
|
7
|
-
# ExecutionFailure is also the base class of the other
|
8
|
-
# block-executing assertion classes.
|
9
|
-
class ExecutionFailure < Assertion
|
10
|
-
#
|
11
|
-
def self.assertion_name
|
12
|
-
:execution
|
13
|
-
end
|
14
|
-
|
15
|
-
# Check assertion.
|
16
|
-
def self.pass?(_=nil, &block)
|
17
|
-
begin
|
18
|
-
block.call
|
19
|
-
true
|
20
|
-
rescue Exception
|
21
|
-
false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Check negated assertion.
|
26
|
-
def self.fail?(_=nil, &block)
|
27
|
-
begin
|
28
|
-
block.call
|
29
|
-
false
|
30
|
-
rescue Exception
|
31
|
-
true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
def to_s
|
37
|
-
return @mesg if @mesg
|
38
|
-
if @_negated
|
39
|
-
"Expected procedure to raise an exception"
|
40
|
-
else
|
41
|
-
"Expected procedure to execute successfully"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
module Assertives
|
49
|
-
# Passes if the block yields successfully.
|
50
|
-
#
|
51
|
-
# assert_executes "Couldn't do the thing" do
|
52
|
-
# do_the_thing
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
def assert_executes(msg=nil, &blk)
|
56
|
-
ExecutionFailure.assert(:message=>msg, :backtrace=>caller, &blk)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Passes if the block does not yield successfully.
|
60
|
-
#
|
61
|
-
# assert_not_executes "Couldn't do the thing" do
|
62
|
-
# do_the_thing
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
def assert_not_executes(msg=nil, &blk)
|
66
|
-
ExecutionFailure.refute(:message=>msg, :backtrace=>caller, &blk)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
module Matchers
|
72
|
-
# TODO: Reasonable matcher for ExectuionFailure ?
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# proc.assert is_executed(*args)
|
76
|
-
#
|
77
|
-
def is_executed(&block)
|
78
|
-
ExecutionFailure.to_matcher(&block)
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
# proc.should be_executed(*args)
|
84
|
-
#
|
85
|
-
def be_extecuted(&block)
|
86
|
-
ExecutionFailure.to_matcher(&block)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'assay/assertions/compare_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
class FalseFailure < CompareFailure
|
6
|
-
|
7
|
-
def self.assertion_name
|
8
|
-
:false
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.assertion_operator
|
12
|
-
:false?
|
13
|
-
end
|
14
|
-
|
15
|
-
# Check assertion.
|
16
|
-
def self.pass?(exp)
|
17
|
-
FalseClass === exp
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
def to_s
|
22
|
-
return @mesg if @mesg
|
23
|
-
return super unless @arguments.size == 1
|
24
|
-
|
25
|
-
exp = @arguments[0].inspect
|
26
|
-
|
27
|
-
if @_negated
|
28
|
-
"Expected #{exp} to NOT be false"
|
29
|
-
else
|
30
|
-
"Expected #{exp} to be false"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
module Assertives
|
38
|
-
# Passed if object is +false+.
|
39
|
-
#
|
40
|
-
def assert_false(exp, msg=nil)
|
41
|
-
FalseFailure.assert(exp, :message=>msg, :backtrace=>caller)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Passed if object is not +false+.
|
45
|
-
#
|
46
|
-
# assert_not_false(false)
|
47
|
-
#
|
48
|
-
def assert_not_false(exp, msg=nil)
|
49
|
-
FalseFailure.refute(exp, :message=>msg, :backtrace=>caller)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
module Matchers
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# value.assert is_false
|
58
|
-
#
|
59
|
-
def is_false
|
60
|
-
FalseFailure.to_matcher
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# value.should be_false
|
66
|
-
#
|
67
|
-
def be_false
|
68
|
-
FalseFailure.to_matcher
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|