assay 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'assay/assertion'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
# Does an object #respond_to? a method call.
|
6
|
-
class ResponseFailure < Assertion
|
7
|
-
|
8
|
-
def self.assertion_name
|
9
|
-
:respond_to
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.assertion_name!
|
13
|
-
:not_respond_to
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.operator_name
|
17
|
-
:respond_to?
|
18
|
-
end
|
19
|
-
|
20
|
-
# Check assertion.
|
21
|
-
def self.pass?(reciever, method)
|
22
|
-
#flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
|
23
|
-
#obj, meth = meth, obj if flip
|
24
|
-
reciever.respond_to?(method)
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
def to_s
|
29
|
-
return @mesg if @mesg
|
30
|
-
return super unless @arguments.size == 2
|
31
|
-
|
32
|
-
reciever = @arguments[0].inspect
|
33
|
-
method = @arguments[1].inspect
|
34
|
-
|
35
|
-
if @_negated
|
36
|
-
"Expected #{reciever} (#{reciever.class}) to NOT respond to ##{method}"
|
37
|
-
else
|
38
|
-
"Expected #{reciever} (#{reciever.class}) to respond to ##{method}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
module Assertives
|
46
|
-
# Passes if +object+ respond_to? +methods+.
|
47
|
-
#
|
48
|
-
# assert_respond_to 'bugbear', :slice
|
49
|
-
#
|
50
|
-
def assert_respond_to(reciever, method, msg=nil)
|
51
|
-
ResponseFailure.assert(reciever, method, :message=>msg, :backtrace=>caller)
|
52
|
-
end
|
53
|
-
alias_method :assert_responds_to, :assert_respond_to
|
54
|
-
|
55
|
-
# Passes if +object+ does not respond_to? +methods+.
|
56
|
-
#
|
57
|
-
# assert_not_respond_to 'bugbear', :slice
|
58
|
-
#
|
59
|
-
def assert_not_respond_to(reciever, method, msg=nil)
|
60
|
-
ResponseFailure.refute(reciever, method, :message=>msg, :backtrace=>caller)
|
61
|
-
end
|
62
|
-
|
63
|
-
alias_method :assert_not_responds_to, :assert_not_respond_to
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
module Matchers
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# object.assert is_responsive_to(:method_symbol)
|
71
|
-
#
|
72
|
-
def is_responsive_to(method)
|
73
|
-
ResponseFailure.to_matcher(method)
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# object.should be_responsive_to(:method_symbol)
|
79
|
-
#
|
80
|
-
def be_responsive_to(method)
|
81
|
-
ResponseFailure.to_matcher(method)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'assay/assertions/compare_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
# Comparison assertion for the #eql? method.
|
6
|
-
class SameFailure < CompareFailure
|
7
|
-
|
8
|
-
def self.assertion_name
|
9
|
-
:same
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.assertion_operator
|
13
|
-
:eql?
|
14
|
-
end
|
15
|
-
|
16
|
-
# Check assertion.
|
17
|
-
def self.pass?(exp, act)
|
18
|
-
exp.eql?(act)
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
def to_s
|
23
|
-
return @mesg if @mesg
|
24
|
-
return super unless @arguments.size == 2
|
25
|
-
|
26
|
-
exp = @arguments[0].inspect
|
27
|
-
act = @arguments[1].inspect
|
28
|
-
|
29
|
-
if @_negated
|
30
|
-
"Expected #{act} to NOT be the same as #{exp}"
|
31
|
-
else
|
32
|
-
"Expected #{act} to be the same as #{exp}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
module Assertives
|
40
|
-
# Passes if +expected+ .eq? +actual+.
|
41
|
-
#
|
42
|
-
# Note that the ordering of arguments is important,
|
43
|
-
# since a helpful error message is generated when this
|
44
|
-
# one fails that tells you the values of expected and actual.
|
45
|
-
#
|
46
|
-
# assert_same 'MY STRING', 'my string'.upcase
|
47
|
-
#
|
48
|
-
def assert_same(exp, act, msg=nil)
|
49
|
-
SameFailure.assert(exp, act, :message=>msg, :backtrace=>caller)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Passes if not +expected+ .eq? +actual+.
|
53
|
-
#
|
54
|
-
# assert_not_the_same 'some string', 5
|
55
|
-
#
|
56
|
-
def refute_same(exp, act, msg=nil)
|
57
|
-
SameFailure.refute(exp, act, :message=>msg, :backtrace=>caller)
|
58
|
-
end
|
59
|
-
|
60
|
-
alias_method :assert_not_same, :refute_same
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
module Matchers
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# object1.assert is_same_as(object2)
|
68
|
-
#
|
69
|
-
def is_same_as(obj)
|
70
|
-
SameFailure.to_matcher(obj)
|
71
|
-
end
|
72
|
-
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# object1.should be_same_as(object2)
|
76
|
-
#
|
77
|
-
def be_same_as(obj)
|
78
|
-
SameFailure.to_matcher(obj)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'assay/assertions/execution_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
#
|
6
|
-
class ThrowFailure < ExecutionFailure
|
7
|
-
|
8
|
-
def self.assertion_name
|
9
|
-
:throws
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.assertion_name!
|
13
|
-
:not_thrown
|
14
|
-
end
|
15
|
-
|
16
|
-
# Passes if the block throws expected_symbol
|
17
|
-
#
|
18
|
-
# assert_throws :done do
|
19
|
-
# throw :done
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
def self.pass?(sym, &block)
|
23
|
-
pass = true
|
24
|
-
catch(sym) do
|
25
|
-
begin
|
26
|
-
block.call
|
27
|
-
rescue ArgumentError => err # 1.9 exception
|
28
|
-
#msg += ", not #{err.message.split(/ /).last}"
|
29
|
-
pass = false
|
30
|
-
rescue NameError => err # 1.8 exception
|
31
|
-
#msg += ", not #{err.name.inspect}"
|
32
|
-
pass = false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
pass
|
36
|
-
end
|
37
|
-
|
38
|
-
# Passes if the block throws expected_symbol
|
39
|
-
#
|
40
|
-
# assert_not_thrown :done do
|
41
|
-
# throw :chimp
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# FIXME: Is this correct?
|
45
|
-
def self.fail?(sym, &block)
|
46
|
-
pass = false
|
47
|
-
catch(sym) do
|
48
|
-
begin
|
49
|
-
block.call
|
50
|
-
rescue ArgumentError => err # 1.9 exception
|
51
|
-
#msg += ", not #{err.message.split(/ /).last}"
|
52
|
-
pass = true
|
53
|
-
rescue NameError => err # 1.8 exception
|
54
|
-
#msg += ", not #{err.name.inspect}"
|
55
|
-
pass = true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
pass
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
def to_s
|
63
|
-
return @mesg if @mesg
|
64
|
-
return super unless @arguments.size == 1
|
65
|
-
|
66
|
-
sym = @arguments[0].inspect
|
67
|
-
|
68
|
-
if @_negated
|
69
|
-
"Expected #{sym} to have been thrown"
|
70
|
-
else
|
71
|
-
"Expected #{sym} NOT to have been thrown"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
module Assertives
|
79
|
-
# Passes if the block throws expected_symbol
|
80
|
-
#
|
81
|
-
# assert_throws :done do
|
82
|
-
# throw :done
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
def assert_throws(sym, msg=nil, &blk)
|
86
|
-
ThrowFailure.assert(sym, :message=>msg, :backtrace=>caller, &blk)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Passes if the block throws expected_symbol
|
90
|
-
#
|
91
|
-
# refute_throws :done do
|
92
|
-
# throw :chimp
|
93
|
-
# end
|
94
|
-
#
|
95
|
-
def refute_throws(sym, msg=nil, &blk)
|
96
|
-
ThrowFailure.refute(sym, :message=>msg, :backtrace=>caller, &blk)
|
97
|
-
end
|
98
|
-
|
99
|
-
alias_method :assert_not_thrown, :refute_throws
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
module Matchers
|
104
|
-
#
|
105
|
-
#
|
106
|
-
# :symbol.assert is_thrown{ ... }
|
107
|
-
#
|
108
|
-
def is_thrown(&blk)
|
109
|
-
ThrowFailure.to_matcher(&blk)
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
#
|
114
|
-
# :symbol.should be_thrown{ ... }
|
115
|
-
#
|
116
|
-
def be_thrown(&blk)
|
117
|
-
ThrowFailure.to_matcher(&blk)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'assay/assertions/compare_failure'
|
2
|
-
|
3
|
-
module Assay
|
4
|
-
|
5
|
-
# Comparison assertion for TrueClass.
|
6
|
-
#
|
7
|
-
# TrueFailure.pass?(true) #=> true
|
8
|
-
# TrueFailure.fail?(true) #=> false
|
9
|
-
# TrueFailure.pass?(1) #=> false
|
10
|
-
#
|
11
|
-
class TrueFailure < CompareFailure
|
12
|
-
|
13
|
-
def self.assertion_name
|
14
|
-
:true
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.assertion_operator
|
18
|
-
:true?
|
19
|
-
end
|
20
|
-
|
21
|
-
# Check assertion.
|
22
|
-
def self.pass?(exp)
|
23
|
-
TrueClass === exp
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
def to_s
|
28
|
-
return @mesg if @mesg
|
29
|
-
return super unless @arguments.size == 1
|
30
|
-
|
31
|
-
exp = @arguments[0].inspect
|
32
|
-
|
33
|
-
if @_negated
|
34
|
-
"Expected #{exp} to NOT be true"
|
35
|
-
else
|
36
|
-
"Expected #{exp} to be true"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
module Assertives
|
44
|
-
# Passed if object is +true+.
|
45
|
-
#
|
46
|
-
def assert_true(exp, msg=nil)
|
47
|
-
TrueFailure.assert(exp, :message=>msg, :backtrace=>caller)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Passed if object is not +true+.
|
51
|
-
#
|
52
|
-
# assert_not_true(false)
|
53
|
-
#
|
54
|
-
def assert_not_true(exp, msg=nil)
|
55
|
-
TrueFailure.refute(exp, :message=>msg, :backtrace=>caller)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
module Matchers
|
61
|
-
# True?
|
62
|
-
#
|
63
|
-
# value.assert is_true
|
64
|
-
#
|
65
|
-
def is_true
|
66
|
-
TrueFailure.to_matcher
|
67
|
-
end
|
68
|
-
|
69
|
-
# True?
|
70
|
-
#
|
71
|
-
# value.should be_true
|
72
|
-
#
|
73
|
-
def be_true
|
74
|
-
TrueFailure.to_matcher
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
data/lib/assay/matcher.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Assay
|
2
|
-
|
3
|
-
#
|
4
|
-
class Matcher
|
5
|
-
def initialize(fail_class, *arguments, &block)
|
6
|
-
@fail_class = fail_class
|
7
|
-
@arguments = arguments
|
8
|
-
@block = block
|
9
|
-
end
|
10
|
-
|
11
|
-
#
|
12
|
-
def fail_class
|
13
|
-
@fail_class
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
def matches?(target)
|
18
|
-
@exception = nil
|
19
|
-
@target = target
|
20
|
-
|
21
|
-
@fail_class.pass?(target, *@arguments, &@block)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns Exception class.
|
25
|
-
def exception(message=nil)
|
26
|
-
@exception ||= fail_class.new(message, @target, *@arguments, &@block)
|
27
|
-
# :negated => options[:negated],
|
28
|
-
# :backtrace => options[:backtrace] || caller,
|
29
|
-
end
|
30
|
-
|
31
|
-
# This is just for RSpec matcher compatability.
|
32
|
-
def fail_message
|
33
|
-
exception.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
# This is just for RSpec matcher compatability.
|
37
|
-
def negative_fail_message
|
38
|
-
#exception.set_negative(true)
|
39
|
-
exception.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
def fail(backtrace=nil)
|
44
|
-
super exception #(backtrace || caller)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/qed/01_failure_classes.rdoc
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
= Failure Classes
|
2
|
-
|
3
|
-
require 'assay'
|
4
|
-
|
5
|
-
== EqualityFailure
|
6
|
-
|
7
|
-
assert Assay::EqualityFailure.pass?(1,1)
|
8
|
-
refute Assay::EqualityFailure.pass?(1,2)
|
9
|
-
|
10
|
-
== TrueFailure
|
11
|
-
|
12
|
-
assert Assay::TrueFailure.pass?(true)
|
13
|
-
refute Assay::TrueFailure.pass?(false)
|
14
|
-
|
15
|
-
== FalseFailure
|
16
|
-
|
17
|
-
assert Assay::FalseFailure.pass?(false)
|
18
|
-
refute Assay::FalseFailure.pass?(true)
|
19
|
-
|
20
|
-
== NilFailure
|
21
|
-
|
22
|
-
assert Assay::NilFailure.pass?(nil)
|
23
|
-
refute Assay::NilFailure.pass?(true)
|
24
|
-
refute Assay::NilFailure.pass?(false)
|
25
|
-
|
26
|
-
== DeltaFailure
|
27
|
-
|
28
|
-
assert Assay::DeltaFailure.pass?(1, 1.5, 2)
|
29
|
-
refute Assay::DeltaFailure.pass?(1, 2.5, 1)
|
30
|
-
|
31
|
-
== MatchFailure
|
32
|
-
|
33
|
-
assert Assay::MatchFailure.pass?(/a/, "abc")
|
34
|
-
refute Assay::MatchFailure.pass?(/x/, "abc")
|
35
|
-
|
36
|
-
== SameFailure
|
37
|
-
|
38
|
-
assert Assay::SameFailure.pass?(1, 1)
|
39
|
-
refute Assay::SameFailure.pass?(1, 1.0)
|
40
|
-
|
41
|
-
== IdentityFailure
|
42
|
-
|
43
|
-
assert Assay::IdentityFailure.pass?(:a, :a)
|
44
|
-
refute Assay::IdentityFailure.pass?("a", "a")
|
45
|
-
|
46
|
-
== InstanceFailure
|
47
|
-
|
48
|
-
assert Assay::InstanceFailure.pass?(1, Fixnum)
|
49
|
-
refute Assay::InstanceFailure.pass?(1, String)
|
50
|
-
|
51
|
-
== KindFailure
|
52
|
-
|
53
|
-
assert Assay::KindFailure.pass?(1, Integer)
|
54
|
-
refute Assay::KindFailure.pass?(1, String)
|
55
|
-
|
56
|
-
== RaiseFailure
|
57
|
-
|
58
|
-
assert Assay::RaiseFailure.pass?(ArgumentError){ raise ArgumentError }
|
59
|
-
refute Assay::RaiseFailure.pass?(ArgumentError){ raise TypeError }
|
60
|
-
|
61
|
-
== ResponseFailure
|
62
|
-
|
63
|
-
assert Assay::ResponseFailure.pass?("string", :upcase)
|
64
|
-
refute Assay::ResponseFailure.pass?("string", :not_a_method)
|
65
|
-
|
66
|
-
== ExecutionFailure
|
67
|
-
|
68
|
-
assert Assay::ExecutionFailure.pass?(){ nil }
|
69
|
-
refute Assay::ExecutionFailure.pass?(){ raise }
|
70
|
-
|
71
|
-
== ThrowFailure
|
72
|
-
|
73
|
-
assert Assay::ThrowFailure.pass?(:foo){ throw :foo }
|
74
|
-
refute Assay::ThrowFailure.pass?(:foo){ throw :bar }
|
75
|
-
|