assay 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.ruby +46 -41
  2. data/COPYING.rdoc +38 -0
  3. data/HISTORY.rdoc +18 -1
  4. data/QED.rdoc +1100 -0
  5. data/README.rdoc +139 -16
  6. data/lib/assay.rb +82 -29
  7. data/lib/assay.yml +46 -41
  8. data/lib/assay/{adapters → adapter}/minitest.rb +0 -0
  9. data/lib/assay/{adapters → adapter}/testunit.rb +0 -0
  10. data/lib/assay/assertable.rb +174 -0
  11. data/lib/assay/assertion.rb +98 -124
  12. data/lib/assay/assertor.rb +187 -0
  13. data/lib/assay/boolean_assay.rb +15 -0
  14. data/lib/assay/case_assay.rb +17 -0
  15. data/lib/assay/compare_assay.rb +38 -0
  16. data/lib/assay/core_ext/kernel.rb +52 -0
  17. data/lib/assay/core_ext/na.rb +9 -0
  18. data/lib/assay/directory_assay.rb +20 -0
  19. data/lib/assay/empty_assay.rb +17 -0
  20. data/lib/assay/equal_assay.rb +35 -0
  21. data/lib/assay/equality_assay.rb +18 -0
  22. data/lib/assay/execution_assay.rb +59 -0
  23. data/lib/assay/false_assay.rb +17 -0
  24. data/lib/assay/file_assay.rb +17 -0
  25. data/lib/assay/identity_assay.rb +49 -0
  26. data/lib/assay/include_assay.rb +17 -0
  27. data/lib/assay/instance_assay.rb +17 -0
  28. data/lib/assay/kind_assay.rb +18 -0
  29. data/lib/assay/less_assay.rb +18 -0
  30. data/lib/assay/less_equal_assay.rb +25 -0
  31. data/lib/assay/like_assay.rb +17 -0
  32. data/lib/assay/match_assay.rb +17 -0
  33. data/lib/assay/more_assay.rb +18 -0
  34. data/lib/assay/more_equal_assay.rb +25 -0
  35. data/lib/assay/nil_assay.rb +15 -0
  36. data/lib/assay/nomatch_assay.rb +17 -0
  37. data/lib/assay/output_assay.rb +35 -0
  38. data/lib/assay/path_assay.rb +17 -0
  39. data/lib/assay/raise_assay.rb +109 -0
  40. data/lib/assay/rescue_assay.rb +55 -0
  41. data/lib/assay/respond_assay.rb +17 -0
  42. data/lib/assay/return_assay.rb +46 -0
  43. data/lib/assay/silent_assay.rb +59 -0
  44. data/lib/assay/stderr_assay.rb +30 -0
  45. data/lib/assay/stdout_assay.rb +30 -0
  46. data/lib/assay/throw_assay.rb +89 -0
  47. data/lib/assay/true_assay.rb +20 -0
  48. data/lib/assay/unequal_assay.rb +37 -0
  49. data/lib/assay/within_assay.rb +39 -0
  50. data/test/case_compare_assay.rb +59 -0
  51. data/test/case_empty_assay.rb +51 -0
  52. data/test/case_equal_assay.rb +53 -0
  53. data/test/case_equality_assay.rb +55 -0
  54. data/test/case_false_assay.rb +48 -0
  55. data/test/case_identity_assay.rb +51 -0
  56. data/test/case_include_assay.rb +51 -0
  57. data/test/case_instance_assay.rb +51 -0
  58. data/test/case_kind_assay.rb +51 -0
  59. data/test/case_less_assay.rb +53 -0
  60. data/test/case_less_equal_assay.rb +53 -0
  61. data/test/case_like_assay.rb +57 -0
  62. data/test/case_match_assay.rb +45 -0
  63. data/test/case_more_assay.rb +53 -0
  64. data/test/case_more_equal_assay.rb +53 -0
  65. data/test/case_nil_assay.rb +48 -0
  66. data/test/case_nomatch_assay.rb +47 -0
  67. data/test/case_raise_assay.rb +51 -0
  68. data/test/case_respond_assay.rb +51 -0
  69. data/test/case_throw_assay.rb +51 -0
  70. data/test/case_true_assay.rb +48 -0
  71. data/test/case_unequal_assay.rb +55 -0
  72. data/test/case_within_assay.rb +61 -0
  73. data/test/helper.rb +36 -0
  74. metadata +135 -108
  75. data/APACHE2.txt +0 -205
  76. data/NOTICE.rdoc +0 -18
  77. data/lib/assay/assertions/compare_failure.rb +0 -61
  78. data/lib/assay/assertions/delta_failure.rb +0 -80
  79. data/lib/assay/assertions/empty_failure.rb +0 -76
  80. data/lib/assay/assertions/equality_failure.rb +0 -100
  81. data/lib/assay/assertions/execution_failure.rb +0 -90
  82. data/lib/assay/assertions/false_failure.rb +0 -72
  83. data/lib/assay/assertions/identity_failure.rb +0 -85
  84. data/lib/assay/assertions/instance_failure.rb +0 -76
  85. data/lib/assay/assertions/kind_failure.rb +0 -80
  86. data/lib/assay/assertions/match_failure.rb +0 -85
  87. data/lib/assay/assertions/nil_failure.rb +0 -75
  88. data/lib/assay/assertions/raise_failure.rb +0 -134
  89. data/lib/assay/assertions/response_failure.rb +0 -86
  90. data/lib/assay/assertions/same_failure.rb +0 -82
  91. data/lib/assay/assertions/throw_failure.rb +0 -122
  92. data/lib/assay/assertions/true_failure.rb +0 -79
  93. data/lib/assay/matcher.rb +0 -48
  94. data/qed/01_failure_classes.rdoc +0 -75
  95. data/qed/02_assertives.rdoc +0 -118
  96. data/qed/03_matchers.rdoc +0 -118
  97. data/qed/04_lookup.rdoc +0 -10
@@ -1,85 +0,0 @@
1
- require 'assay/assertions/compare_failure'
2
-
3
- module Assay
4
-
5
- class IdentityFailure < CompareFailure
6
-
7
- def self.assertion_name
8
- :identical
9
- end
10
-
11
- def self.assertion_operator
12
- :equal?
13
- end
14
-
15
- #def self.fail_message(exp, act)
16
- # "Expected #{act.inspect} to be identical to #{exp.inspect}"
17
- #end
18
-
19
- #def self.fail_message!(exp, act)
20
- # "Expected #{act.inspect} not to be identical to #{exp.inspect}"
21
- #end
22
-
23
- # Check assertion.
24
- def self.pass?(exp, act)
25
- exp.object_id == act.object_id
26
- end
27
-
28
- #
29
- def to_s
30
- return @mesg if @mesg
31
- return super unless @arguments.size == 2
32
-
33
- iexp = @arguments[0].inspect
34
- iact = @arguments[1].inspect
35
-
36
- if @_negated
37
- "Expected #{iact} not to be identical to #{iexp}"
38
- else
39
- "Expected #{iact} to be identical to #{iexp}"
40
- end
41
- end
42
-
43
- end
44
-
45
-
46
- module Assertives
47
- # Passes if +actual+ .equal? +expected+ (i.e. they are the same instance).
48
- #
49
- # o = Object.new
50
- # assert_identical(o, o)
51
- #
52
- def assert_identical(exp, act, msg=nil)
53
- IdentityFailure.assert(exp, act, :message=>msg, :backtrace=>caller)
54
- end
55
-
56
- # Passes if ! actual .equal? expected
57
- #
58
- # assert_not_identical(Object.new, Object.new)
59
- #
60
- def assert_not_identical(exp, act, msg=nil)
61
- IdentityFailure.refute(exp, act, :message=>msg, :backtrace=>caller)
62
- end
63
- end
64
-
65
-
66
- module Matchers
67
- #
68
- #
69
- # object1.assert is_identical_to(object2)
70
- #
71
- def is_identical_to(obj)
72
- IdentityFailure.to_matcher(obj)
73
- end
74
-
75
- #
76
- #
77
- # object1.should be_identical_to(object2)
78
- #
79
- def be_identical_to(obj)
80
- IdentityFailure.to_matcher(obj)
81
- end
82
-
83
- end
84
-
85
- end
@@ -1,76 +0,0 @@
1
- require 'assay/assertions/compare_failure'
2
-
3
- module Assay
4
-
5
- class InstanceFailure < CompareFailure
6
-
7
- def self.assertion_name
8
- :instance
9
- end
10
-
11
- def self.assertion_operator
12
- :instance_of?
13
- end
14
-
15
- # Check assertion.
16
- def self.pass?(exp, act)
17
- exp.instance_of?(act)
18
- end
19
-
20
- #
21
- def to_s
22
- return @mesg if @mesg
23
- return super unless @arguments.size == 2
24
-
25
- exp = @arguments[0].inspect
26
- act = @arguments[1].inspect
27
-
28
- if @_negated
29
- "Expected #{act} to NOT be an instance of #{exp}"
30
- else
31
- "Expected #{act} to be an instance of #{exp}"
32
- end
33
- end
34
- end
35
-
36
-
37
- module Assertives
38
- # Passes if object .instance_of? klass
39
- #
40
- # assert_instance_of(String, 'foo')
41
- #
42
- def assert_instance_of(cls, obj, msg=nil)
43
- InstanceFailure.assert(cls, obj, :message=>msg, :backtrace=>caller)
44
- end
45
-
46
- # Passes if object .instance_of? klass
47
- #
48
- # assert_instance_of(String, 'foo')
49
- #
50
- def refute_instance_of(cls, obj, msg=nil)
51
- InstanceFailure.refute(cls, obj, :message=>msg, :backtrace=>caller)
52
- end
53
-
54
- alias_method :assert_not_instance_of, :refute_instance_of
55
- end
56
-
57
-
58
- module Matchers
59
- #
60
- #
61
- # object.assert is_instance_of(class)
62
- #
63
- def is_instance_of(cls)
64
- InstanceFailure.to_matcher(cls)
65
- end
66
-
67
- #
68
- #
69
- # object.should be_instance_of(class)
70
- #
71
- def be_instance_of(cls)
72
- InstanceFailure.to_matcher(cls)
73
- end
74
- end
75
-
76
- end
@@ -1,80 +0,0 @@
1
- require 'assay/assertions/compare_failure'
2
-
3
- module Assay
4
-
5
- # Comparison assertion for #kind_of?
6
- #
7
- # KindFailure.pass?(1, Integer) #=> true
8
- # KindFailure.fail?(1, String) #=> true
9
- #
10
- class KindFailure < CompareFailure
11
-
12
- def self.assertion_name
13
- :kind_of
14
- end
15
-
16
- def self.assertion_operator
17
- :kind_of?
18
- end
19
-
20
- # Check assertion.
21
- def self.pass?(exp, act)
22
- exp.kind_of? act
23
- end
24
-
25
- #
26
- def to_s
27
- return @mesg if @mesg
28
- return super unless @arguments.size == 2
29
-
30
- exp = @arguments[0].inspect
31
- act = @arguments[1].inspect
32
-
33
- if @_negated
34
- "Expected #{act} to be kind of #{exp}"
35
- else
36
- "Expected #{act} to be kind of #{exp}"
37
- end
38
- end
39
- end
40
-
41
-
42
- module Assertives
43
- # Passes if object .kind_of? klass
44
- #
45
- # assert_kind_of(Object, 'foo')
46
- #
47
- def assert_kind_of(cls, obj, msg=nil)
48
- KindFailure.assert(cls, obj, :message=>msg, :backtrace=>caller)
49
- end
50
-
51
- # Passes if object .kind_of? klass
52
- #
53
- # assert_not_kind_of(Object, 'foo')
54
- #
55
- def refute_kind_of(cls, obj, msg=nil)
56
- KindFailure.refute(cls, obj, :message=>msg, :backtrace=>caller)
57
- end
58
- alias_method :assert_not_kind_of, :refute_kind_of
59
- end
60
-
61
-
62
- module Matchers
63
- #
64
- #
65
- # object.assert is_a_kind_of(class)
66
- #
67
- def is_kind_of(cls)
68
- KindFailure.to_matcher(cls)
69
- end
70
-
71
- #
72
- #
73
- # object.should be_a_kind_of(class)
74
- #
75
- def be_kind_of(cls)
76
- KindFailure.to_matcher(cls)
77
- end
78
- end
79
-
80
- end
@@ -1,85 +0,0 @@
1
- require 'assay/assertions/compare_failure'
2
-
3
- module Assay
4
-
5
- class MatchFailure < CompareFailure
6
-
7
- def self.assertion_name
8
- :match
9
- end
10
-
11
- def self.assertion_operator
12
- :=~
13
- end
14
-
15
- # Check assertion.
16
- def self.pass?(exp, act)
17
- exp =~ act
18
- end
19
-
20
- # Check negated assertion.
21
- def self.fail?(exp, act)
22
- exp !~ act
23
- end
24
-
25
- #
26
- def self.assertable_method
27
- :assert_match
28
- end
29
-
30
- #
31
- def to_s
32
- return @mesg if @mesg
33
- return super unless @arguments.size == 2
34
-
35
- exp = @arguments[0].inspect
36
- act = @arguments[1].inspect
37
-
38
- if @_negated
39
- "Expected #{act} !~ #{exp}"
40
- else
41
- "Expected #{act} =~ #{exp}"
42
- end
43
- end
44
-
45
- end
46
-
47
-
48
- module Assertives
49
- # Passes if string =~ pattern.
50
- #
51
- # assert_match(/\d+/, 'five, 6, seven')
52
- #
53
- def assert_match(exp, act, msg=nil)
54
- MatchFailure.assert(exp, act, :message=>msg, :backtrace=>caller)
55
- end
56
-
57
- # Passes if regexp !~ string
58
- #
59
- # refute_match(/two/, 'one 2 three')
60
- #
61
- def refute_match(exp, act, msg=nil)
62
- MatchFailure.refute(exp, act, :message=>msg, :backtrace=>caller)
63
- end
64
- end
65
-
66
-
67
- module Matchers
68
- #
69
- #
70
- # object.assert is_a_match_for(regexp)
71
- #
72
- def is_match_for(regexp)
73
- MatchFailure.to_matcher(regexp)
74
- end
75
-
76
- #
77
- #
78
- # object.should be_a_match_for(regexp)
79
- #
80
- def be_match_for(regexp)
81
- MatchFailure.to_matcher(regexp)
82
- end
83
- end
84
-
85
- end
@@ -1,75 +0,0 @@
1
- require 'assay/assertions/compare_failure'
2
-
3
- module Assay
4
-
5
- class NilFailure < CompareFailure
6
-
7
- def self.assertion_name
8
- :nil
9
- end
10
-
11
- def self.assertion_operator
12
- :nil?
13
- end
14
-
15
- # Check assertion.
16
- def self.pass?(exp)
17
- exp.nil?
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 nil"
29
- else
30
- "Expected #{exp} to be nil"
31
- end
32
- end
33
-
34
- end
35
-
36
-
37
- module Assertives
38
- # Passed if object is +nil+.
39
- #
40
- def assert_nil(exp, msg=nil)
41
- NilFailure.assert(exp, :message=>msg, :backtrace=>caller)
42
- end
43
-
44
- # Passed if object is not +nil+.
45
- #
46
- # assert_not_nil(true)
47
- #
48
- def assert_not_nil(exp, msg=nil)
49
- opts[:backtrace] ||= caller
50
- NilFailure.refute(exp, :message=>msg, :backtrace=>caller)
51
- end
52
- end
53
-
54
-
55
- module Matchers
56
-
57
- #
58
- #
59
- # value.assert is_nil
60
- #
61
- def is_nil
62
- NilFailure.to_matcher
63
- end
64
-
65
- #
66
- #
67
- # value.should be_nil
68
- #
69
- def be_nil
70
- NilFailure.to_matcher
71
- end
72
-
73
- end
74
-
75
- end
@@ -1,134 +0,0 @@
1
- require 'assay/assertions/execution_failure'
2
-
3
- module Assay
4
-
5
- #
6
- class RaiseFailure < ExecutionFailure
7
-
8
- def self.assertion_name
9
- :raises
10
- end
11
-
12
- def self.assertion_name!
13
- :not_raised
14
- end
15
-
16
- #
17
- def self.assert(exp, msg=nil, call=nil) #:yeild:
18
- begin
19
- yield
20
- #msg = msg || fail_message(exp)
21
- test = false
22
- args = [exp]
23
- rescue Exception => err
24
- #msg = msg || fail_message(exp, err)
25
- test = (exp === err)
26
- args = [exp, err]
27
- end
28
- if !test
29
- err = new(msg, :backtrace=>(call || caller), :arguments=>args)
30
- fail err
31
- end
32
- end
33
-
34
- #
35
- def self.assert!(exp, msg=nil, call=nil) #:yield:
36
- begin
37
- yield
38
- test = true
39
- args = [exp]
40
- rescue Exception => err
41
- #msg = msg || fail_message!(exp, err)
42
- test = (exp === err)
43
- args = [exp, err]
44
- end
45
- if !test
46
- err = new(msg, :backtrace=>(call || caller), :arguments=>args)
47
- fail err
48
- end
49
- end
50
-
51
- # Check assertion.
52
- #
53
- # Note: This is not used by the #assert method.
54
- def self.pass?(*exp)
55
- begin
56
- yield
57
- false
58
- rescue Exception => e
59
- exp.any?{ |x| x === e }
60
- end
61
- end
62
-
63
- # Check negated assertion.
64
- #
65
- # Note: This is not used by the #assert! method.
66
- def self.fail?(*exp)
67
- begin
68
- yield
69
- true
70
- rescue Exception => e
71
- !exp.any?{ |x| x === e }
72
- end
73
- end
74
-
75
- # TODO: how to add `but got class` instead.
76
- def to_s
77
- return @mesg if @mesg
78
- return super unless @arguments.size == 1
79
-
80
- exp = @arguments[0].inspect
81
- #err = @_arguments[1].inspect
82
-
83
- if @_negated
84
- "Expected #{exp} NOT to be raised"
85
- else
86
- "Expected #{exp} to be raised" #, but was #{err} instead."
87
- end
88
- end
89
-
90
- end
91
-
92
-
93
- module Assertives
94
- # Passes if the block raises a given exception.
95
- #
96
- # assert_raises RuntimeError do
97
- # raise 'Boom!!!'
98
- # end
99
- #
100
- def assert_raises(exp, msg=nil, call=nil, &blk) #:yeild:
101
- RaiseFailure.assert(exp, msg=nil, call=nil, &blk)
102
- end
103
-
104
- # Passes if the block *does not* raise a given exceptions.
105
- #
106
- # assert_not_raised IOError do
107
- # raise 'Boom!!!'
108
- # end
109
- #
110
- def assert_not_raised(exp, msg=nil, call=nil, &blk) #:yeild:
111
- RaiseFailure.refute(exp, msg, call, &blk)
112
- end
113
- end
114
-
115
-
116
- module Matchers
117
- #
118
- #
119
- # Exception.assert is_raised{ ... }
120
- #
121
- def is_raised(&blk)
122
- RaiseFailure.to_matcher(&blk)
123
- end
124
-
125
- #
126
- #
127
- # Exception.should be_raised{ ... }
128
- #
129
- def be_raised(&blk)
130
- RaiseFailure.to_matcher(&blk)
131
- end
132
- end
133
-
134
- end