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
@@ -0,0 +1,30 @@
1
+ require_relative 'output_assay'
2
+
3
+ # Assert that there is output $stderr.
4
+ #
5
+ # StderrAssay.pass?(/foo/){ $stderr.puts 'foo!' } #=> true
6
+ #
7
+ class StderrAssay < OutputAssay
8
+
9
+ register :stderr
10
+
11
+ #
12
+ # Check assertion via `#===` method.
13
+ #
14
+ def self.pass?(match, &block)
15
+ require 'stringio'
16
+
17
+ begin
18
+ stderr = $stderr
19
+ newerr = StringIO.new
20
+ $stderr = newerr
21
+ yield
22
+ ensure
23
+ $stderr = stderr
24
+ end
25
+
26
+ match === newerr.string.chomp("\n")
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ require_relative 'output_assay'
2
+
3
+ # Assert that there is output, either from stdout or stderr.
4
+ #
5
+ # StdoutAssay.pass?(/foo/){ puts 'foo!' } #=> true
6
+ #
7
+ class StdoutAssay < OutputAssay
8
+
9
+ register :output
10
+
11
+ #
12
+ # Check assertion via `#===` method.
13
+ #
14
+ def self.pass?(match, &block)
15
+ require 'stringio'
16
+
17
+ begin
18
+ stdout = $stdout
19
+ newout = StringIO.new
20
+ $stdout = newout
21
+ yield
22
+ ensure
23
+ $stdout = stdout
24
+ end
25
+
26
+ match === newout.string.chomp("\n")
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,89 @@
1
+ require_relative 'execution_assay'
2
+
3
+ # Assertion for catching specific throws.
4
+ #
5
+ class ThrowAssay < ExecutionAssay
6
+
7
+ register :throw
8
+
9
+ # TODO: Is it possible to catch _any_ type of throw? If so make the
10
+ # argument optional for that.
11
+
12
+ # Passes if the block throws given symbol.
13
+ #
14
+ # ThrowAssay.pass? :done do
15
+ # throw :done
16
+ # end
17
+ #
18
+ # If no symbol is given than passes if any is thrown.
19
+ # But note that in `#assert!`, the symbol must be `nil`
20
+ # rather than not given.
21
+ #
22
+ def self.pass?(symbol=nil) #:yield:
23
+ pass = true
24
+ if symbol
25
+ catch(symbol) do
26
+ begin
27
+ yield
28
+ rescue ArgumentError => err # 1.9 exception
29
+ #msg += ", not #{err.message.split(/ /).last}"
30
+ rescue NameError => err # 1.8 exception
31
+ #msg += ", not #{err.name.inspect}"
32
+ end
33
+ pass = false
34
+ end
35
+ else
36
+ begin
37
+ yield
38
+ pass = false
39
+ rescue ArgumentError => error
40
+ pass = false if /\Auncaught throw (.+)\z/ !~ error.message
41
+ end
42
+ end
43
+ pass
44
+ end
45
+
46
+ # Passes if the block does not throw given +symbol+.
47
+ #
48
+ # ThrowAssay.fail? :done do
49
+ # throw :chimp
50
+ # end
51
+ #
52
+ # If no symbol is given then passes if nothing is thrown.
53
+ # But note that in `#refute!`, the symbol must be `nil`
54
+ # rather than not given.
55
+ #
56
+ def self.fail?(symbol=nil) #:yield:
57
+ if symbol
58
+ pass = false
59
+ catch(symbol) do
60
+ begin
61
+ yield
62
+ rescue ArgumentError => err # 1.9 exception
63
+ #msg += ", not #{err.message.split(/ /).last}"
64
+ rescue NameError => err # 1.8 exception
65
+ #msg += ", not #{err.name.inspect}"
66
+ end
67
+ pass = true
68
+ end
69
+ else
70
+ pass = false
71
+ begin
72
+ yield
73
+ pass = true
74
+ rescue ArgumentError => error
75
+ pass = true if /\Auncaught throw (.+)\z/ !~ error.message
76
+ end
77
+ end
78
+ pass
79
+ end
80
+
81
+ #
82
+ #
83
+ #
84
+ def self.assert_message(symbol)
85
+ s = symbol.inspect
86
+ "throw #{s}"
87
+ end
88
+
89
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'boolean_assay'
2
+
3
+ # Comparison assertion for TrueClass.
4
+ #
5
+ # TrueAssay.pass?(true) #=> true
6
+ # TrueAssay.fail?(true) #=> false
7
+ # TrueAssay.pass?(1) #=> false
8
+ #
9
+ class TrueAssay < BooleanAssay
10
+
11
+ register :true
12
+
13
+ #
14
+ # Check assertion using `#true?` method.
15
+ #
16
+ def self.pass?(subject)
17
+ subject.true? #TrueClass === subject
18
+ end
19
+
20
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'equal_assay'
2
+
3
+ # UnequalAssay compares objects with `#!=` operator. Yes, as of Ruby 1.9
4
+ # the `!=` is a redefinable method, and as such, we need a separate
5
+ # assay to cover it.
6
+ #
7
+ class UnequalAssay < EqualAssay
8
+
9
+ register :!=, :unequal
10
+
11
+ #
12
+ # Check assertion using `#!=` method.
13
+ #
14
+ def self.pass?(subject, criterion)
15
+ subject != criterion
16
+ end
17
+
18
+ #
19
+ # Failed assertion message.
20
+ #
21
+ def self.assert_message(subject, criterion)
22
+ a = subject.inspect
23
+ b = criterion.inspect
24
+
25
+ if a.size > SIZE_LIMIT or b.size > SIZE_LIMIT
26
+ if $ansi
27
+ d = ANSI::Diff.new(a, b)
28
+ a, b = d.diff1, d.diff2 # *d.to_a
29
+ end
30
+ "a != b\na) #{a}\nb) #{b}"
31
+ else
32
+ "#{a} != #{b}"
33
+ end
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,39 @@
1
+ require_relative 'compare_assay'
2
+
3
+ # TODO: Support Range for Delta comparisons.
4
+
5
+ #
6
+ class WithinAssay < CompareAssay
7
+
8
+ register :within
9
+
10
+ #
11
+ # Check assertion.
12
+ #
13
+ def self.pass?(subject, criterion, delta)
14
+ if [subject, criterion, delta].all?{ |v| Numeric === v }
15
+ a, b, d = subject.to_f, criterion.to_f, delta.to_f
16
+ else
17
+ a, b, d = subject, criterion, delta
18
+ end
19
+
20
+ (b - d) <= a && (b + d) >= a
21
+ end
22
+
23
+ #
24
+ # Failed assertion message.
25
+ #
26
+ def self.assert_message(subject, criterion, delta)
27
+ a = subject.inspect
28
+ b = criterion.inspect
29
+ d = delta.inspect
30
+
31
+ if [a, b, d].any?{ |e| e.size > SIZE_LIMIT }
32
+ "b - d <= a <= b + d\na) #{a}\nb) #{b}\nd) #{d}"
33
+ else
34
+ "#{b} - #{d} <= #{a} <= #{b} + #{d}"
35
+ end
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,59 @@
1
+ covers 'assay/compare_assay'
2
+
3
+ testcase CompareAssay do
4
+
5
+ class_method :pass? do
6
+
7
+ test do
8
+ assert CompareAssay.pass?(1, 1, 0)
9
+ assert CompareAssay.pass?(1, 2, -1)
10
+ assert CompareAssay.pass?(2, 1, 1)
11
+
12
+ refute CompareAssay.pass?(1, 1, 1)
13
+ refute CompareAssay.pass?(1, 1, -1)
14
+ end
15
+
16
+ end
17
+
18
+ class_method :fail? do
19
+
20
+ test do
21
+ assert CompareAssay.fail?(1, 1, 1)
22
+ assert CompareAssay.fail?(1, 1, -1)
23
+
24
+ refute CompareAssay.fail?(1, 1, 0)
25
+ refute CompareAssay.fail?(1, 2, -1)
26
+ refute CompareAssay.fail?(2, 1, 1)
27
+ end
28
+
29
+ end
30
+
31
+ class_method :assert! do
32
+
33
+ test do
34
+ CompareAssay.assert!(1, 1, 0)
35
+ end
36
+
37
+ test do
38
+ expect CompareAssay do
39
+ CompareAssay.assert!(1, 1, 1)
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ class_method :refute! do
46
+
47
+ test do
48
+ CompareAssay.refute!(1, 2, 0)
49
+ end
50
+
51
+ test do
52
+ expect CompareAssay do
53
+ CompareAssay.refute!(1, 1, 0)
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,51 @@
1
+ covers 'assay/empty_assay'
2
+
3
+ testcase EmptyAssay do
4
+
5
+ class_method :pass? do
6
+
7
+ test do
8
+ assert EmptyAssay.pass?([])
9
+ refute EmptyAssay.pass?([1])
10
+ end
11
+
12
+ end
13
+
14
+ class_method :fail? do
15
+
16
+ test do
17
+ refute EmptyAssay.fail?([])
18
+ assert EmptyAssay.fail?([1])
19
+ end
20
+
21
+ end
22
+
23
+ class_method :assert! do
24
+
25
+ test do
26
+ EmptyAssay.assert!([])
27
+ end
28
+
29
+ test do
30
+ expect EmptyAssay do
31
+ EmptyAssay.assert!([1])
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ class_method :refute! do
38
+
39
+ test do
40
+ EmptyAssay.refute!([1])
41
+ end
42
+
43
+ test do
44
+ expect EmptyAssay do
45
+ EmptyAssay.refute!([])
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,53 @@
1
+ covers 'assay/equal_assay'
2
+
3
+ testcase EqualAssay do
4
+
5
+ class_method :pass? do
6
+
7
+ test do
8
+ assert EqualAssay.pass?(1, 1)
9
+ assert EqualAssay.pass?(1, 1.0)
10
+ refute EqualAssay.pass?(1, 2)
11
+ end
12
+
13
+ end
14
+
15
+ class_method :fail? do
16
+
17
+ test do
18
+ refute EqualAssay.fail?(1, 1)
19
+ refute EqualAssay.fail?(1, 1.0)
20
+ assert EqualAssay.fail?(1, 2)
21
+ end
22
+
23
+ end
24
+
25
+ class_method :assert! do
26
+
27
+ test do
28
+ EqualAssay.assert!(1, 1)
29
+ end
30
+
31
+ test do
32
+ expect EqualAssay do
33
+ EqualAssay.assert!(1, 2)
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ class_method :refute! do
40
+
41
+ test do
42
+ EqualAssay.refute!(1, 2)
43
+ end
44
+
45
+ test do
46
+ expect EqualAssay do
47
+ EqualAssay.refute!(1, 1)
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,55 @@
1
+ covers 'assay/equality_assay'
2
+
3
+ testcase EqualityAssay do
4
+
5
+ class_method :pass? do
6
+
7
+ test do
8
+ assert EqualityAssay.pass?(1, 1)
9
+
10
+ refute EqualityAssay.pass?(1, 1.0)
11
+ refute EqualityAssay.pass?(1, 2)
12
+ end
13
+
14
+ end
15
+
16
+ class_method :fail? do
17
+
18
+ test do
19
+ refute EqualityAssay.fail?(1, 1)
20
+
21
+ assert EqualityAssay.fail?(1, 1.0)
22
+ assert EqualityAssay.fail?(1, 2)
23
+ end
24
+
25
+ end
26
+
27
+ class_method :assert! do
28
+
29
+ test do
30
+ EqualityAssay.assert!(1, 1)
31
+ end
32
+
33
+ test do
34
+ expect EqualityAssay do
35
+ EqualityAssay.assert!(1, 2)
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ class_method :refute! do
42
+
43
+ test do
44
+ EqualityAssay.refute!(1, 1.0)
45
+ end
46
+
47
+ test do
48
+ expect EqualityAssay do
49
+ EqualityAssay.refute!(1, 1)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end