ae 1.8.2 → 1.9.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/demo/05_expect.md ADDED
@@ -0,0 +1,104 @@
1
+ # Expect Method
2
+
3
+ Expect is another assertion nomenclature available for use in your
4
+ tests or specifications. Inspired by Jay Fields' Expectations library,
5
+ it provides convenient syntax for creating exception and case equality
6
+ assertions.
7
+
8
+ require 'ae/expect'
9
+
10
+
11
+ ## Underlying Comparison
12
+
13
+ Expect uses `#===` for comparison. So providing an argument and a block
14
+ to #expect we can test for a somewhat broader range of compassion
15
+ than #assert. For example we can test for a subclass.
16
+
17
+ expect Numeric do
18
+ 3
19
+ end
20
+
21
+ Assertion.assert.raised? do
22
+ expect Numeric do
23
+ "3"
24
+ end
25
+ end
26
+
27
+
28
+ ## Exception Expectation
29
+
30
+ If the comparator is an Exception class or a instance of an Exception class,
31
+ then #expect will check to see if the block raises that kind of exception.
32
+
33
+ expect StandardError do
34
+ some_undefined_method
35
+ end
36
+
37
+ expect Assertion do
38
+ expect(nil)
39
+ end
40
+
41
+ This is an important distinction to note because it means `#expect` can not be used
42
+ if verify instances of Exception classes.
43
+
44
+ Assertion.assert.raised? do
45
+ expect Exception do
46
+ Exception.new
47
+ end
48
+ end
49
+
50
+
51
+ ## Regex Expectations
52
+
53
+ That #expect entails `#===` also means we can check for Regexp matches.
54
+
55
+ expect /x/ do
56
+ "oooxooo"
57
+ end
58
+
59
+
60
+ ## Expected Method
61
+
62
+ We can use #expected to make the receiver the object of expectation.
63
+
64
+ x = "dummy"
65
+
66
+ /x/.expected do
67
+ "x"
68
+ end
69
+
70
+
71
+ ## Without Block
72
+
73
+ Without a block, the receiver is compared to the argument.
74
+
75
+ x.expect String
76
+
77
+
78
+ ## Negative Forms
79
+
80
+ Like #assert, `#expect` has a negated form called #expect!
81
+
82
+ expect! /x/ do
83
+ "o"
84
+ end
85
+
86
+ The pure word form for those who do not like the clever use of the
87
+ explimation mark is #forbid.
88
+
89
+ forbid /x/ do
90
+ "o"
91
+ end
92
+
93
+
94
+ ## Functor, or Higher Order Function
95
+
96
+ Like #assert, #expect can be used used as a *fluid* notation.
97
+
98
+ 10.expect == 10
99
+
100
+ In which case it works just like `#assert`, including negative forms.
101
+
102
+ 10.expect! == 11
103
+ 10.forbid == 11
104
+
data/demo/06_counts.md ADDED
@@ -0,0 +1,33 @@
1
+ # Assertion Counts
2
+
3
+ AE tracks the number of assertions made and the number that failed to pass.
4
+ We can reset the count using the +recount+ class method.
5
+
6
+ old_counts = AE::Assertor.recount
7
+
8
+ For example if we have one assertion pass and another fail.
9
+
10
+ assert(true)
11
+
12
+ expect Assertion do
13
+ assert(false)
14
+ end
15
+
16
+ We will see that AE counted three assertions and one failure.
17
+
18
+ counts = AE::Assertor.counts.dup
19
+
20
+ counts[:total].assert == 3
21
+ counts[:pass].assert == 2
22
+ counts[:fail].assert == 1
23
+
24
+ The #expect call is an assertion too, which is why the total count is 3
25
+ rather than 2.
26
+
27
+ Now that we are done checking counts we will restore them so that
28
+ any other demos being run with this will tally correctly.
29
+
30
+ AE::Assertor.recount(old_counts)
31
+ AE::Assertor.counts[:total] += 3
32
+ AE::Assertor.counts[:pass] += 3
33
+
@@ -0,0 +1,34 @@
1
+ # Matchers
2
+
3
+ Matchers are simply Procs or objects with the proper interface that can be
4
+ passed to #assert or #refute (or other Assertor) as an ecapsulated test.
5
+
6
+ ## Proc or #to_proc
7
+
8
+ Passing a Proc object or an object that responds to `:to_proc`, will use it
9
+ as if it were a block of the method. This allows for a simple way to quickly
10
+ create reusable assertions.
11
+
12
+ palindrome = lambda{ |word| word == word.reverse }
13
+
14
+ "abracarba".assert palindrome
15
+
16
+ ## #matches?
17
+
18
+ Additionally if an object responds to #matches? then the receiver
19
+ will be passed to this method to determine if the assertion passes.
20
+
21
+ palindrome = Object.new
22
+
23
+ def palindrome.matches?(word)
24
+ word == word.reverse
25
+ end
26
+
27
+ "abracarba".assert palindrome
28
+
29
+ ## RSpec, Shoulda and other 3rd-Party Matchers
30
+
31
+ With tha addition of #matches?, AE supports the same interface for matchers
32
+ as RSpec. Any matcher library designed for use with RSpec should therefore
33
+ be usable with AE as well. This includes RSpecs own matchers and Shoulda's
34
+ excellent Rails matchers.
data/demo/08_check.md ADDED
@@ -0,0 +1,61 @@
1
+ ## Check Ok/No
2
+
3
+ The Check library is an optional library that can be used
4
+ to conveniently speed-up construction of reptitive assertions.
5
+
6
+ To use it, first require the library, then include the mixin
7
+ into the namespace in which you will utilize it.
8
+
9
+ require 'ae/check'
10
+
11
+ include AE::Check
12
+
13
+ Now we can define ok/no check procedures. A one-off procedure is
14
+ defined with a block only.
15
+
16
+ check do |x, y|
17
+ x == y
18
+ end
19
+
20
+ ok 1,1
21
+ no 1,2
22
+
23
+ To define reusable check procedures, give the procedure a name.
24
+
25
+ check :palindrome do |x|
26
+ x.reverse == x
27
+ end
28
+
29
+ This will also cause the current check method to be set.
30
+ Later in the code, the check procedure can be reset to this
31
+ by just passing the name.
32
+
33
+ check :palindrome
34
+
35
+ ok 'abracarba'
36
+ no 'foolishness'
37
+
38
+ The Check mixin comes preloaded with a few standard checks.
39
+ By default the `:equality` procedure is used.
40
+
41
+ check :equality
42
+
43
+ ok 1=>1.0
44
+
45
+ Notice the use of the hash argument here. This is a useful construct for
46
+ many check procedures becuase it it akin to the `#=>` pattern we often
47
+ see in code examples and it also allows for multiple assertions in one call.
48
+ For instance, in the case of `:equality`, multiple entries convey a
49
+ meaning of logical-or.
50
+
51
+ ok 1=>2, 1.0=>1
52
+
53
+ This would pass because the second assertion of equality is true.
54
+
55
+ Another built in check is `:case_equality` which uses `#===` instead of `#==`
56
+ to make the comparison.
57
+
58
+ check :case_equality
59
+
60
+ ok 1=>Integer
61
+
@@ -0,0 +1 @@
1
+ require 'ae'
@@ -1,46 +1,41 @@
1
1
  require 'ae'
2
2
 
3
- AE.assertion_error = ::MiniTest::Assertion
3
+ AE.assertion_error = ::Minitest::Assertion
4
4
 
5
- module MiniTest #:nodoc:
6
- class Unit #:nodoc:
5
+ module Minitest #:nodoc:
6
+ class Test #:nodoc:
7
+ # Override capture_exceptions to recognize AE assertion errors
8
+ # as test failures rather than errors.
9
+ alias_method :capture_exceptions_without_ae, :capture_exceptions
7
10
 
8
- # MiniTest tracks assertion counts internally in it's Unit class via the
9
- # +assertion_count+ attribute. To work with AE we need add in AE's assertion
10
- # total by overriding the +assertion_count+ method.
11
- #
12
- # @return [Integer] Number of assertions made.
13
- def assertion_count
14
- @assertion_count + AE::Assertor.counts[:total]
15
- end
16
-
17
- # To teach MiniTest to recognize AE's expanded concept of assertions
18
- # we add in an extra capture clause to it's #puke method.
19
- #
20
- # @return [String] Status code is `S`, `F`, or `E`.
21
- def puke k, m, e
22
- case e
23
- when MiniTest::Skip
24
- @skips += 1
25
- return "S" unless @verbose
26
- e = "Skipped:\n#{m}(#{k}) [#{location e}]:\n#{e.message}\n"
27
- when MiniTest::Assertion
28
- @failures += 1
29
- e = "Failure:\n#{m}(#{k}) [#{location e}]:\n#{e.message}\n"
11
+ def capture_exceptions
12
+ yield
13
+ rescue *PASSTHROUGH_EXCEPTIONS
14
+ raise
15
+ rescue Assertion => e
16
+ self.failures << e
17
+ rescue Exception => e
18
+ if e.respond_to?(:assertion?) && e.assertion?
19
+ failure = Assertion.new(e.message)
20
+ failure.set_backtrace(e.backtrace)
21
+ self.failures << failure
30
22
  else
31
- if e.respond_to?(:assertion?) && e.assertion?
32
- @failures += 1
33
- e = "Failure:\n#{m}(#{c}) [#{location e}]:\n#{e.message}\n"
34
- else
35
- @errors += 1
36
- b = MiniTest::filter_backtrace(e.backtrace).join "\n "
37
- e = "Error:\n#{m}(#{k}):\n#{e.class}: #{e.message}\n #{b}\n"
38
- end
23
+ self.failures << UnexpectedError.new(sanitize_exception(e))
39
24
  end
40
- @report << e
41
- e[0, 1]
42
25
  end
43
-
44
26
  end
45
27
  end
46
28
 
29
+ class AE::Assertor #:nodoc:
30
+ # MiniTest tracks assertion counts internally. To work with AE we
31
+ # override increment_counts to also update AE's own counter.
32
+ def self.increment_counts(pass)
33
+ counts[:total] += 1
34
+ if pass
35
+ counts[:pass] += 1
36
+ else
37
+ counts[:fail] += 1
38
+ end
39
+ return counts
40
+ end
41
+ end
@@ -2,63 +2,33 @@ require 'ae'
2
2
 
3
3
  AE.assertion_error = ::Test::Unit::AssertionFailedError
4
4
 
5
- # TestUnit uses #add_assertion on it's +result+ object to track counts.
6
- # We capture the result object by overriding the TestCase#run method,
7
- # store it in a global variable and then use it when AE increments
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.
13
- #
14
5
  module Test #:nodoc:
15
6
  module Unit #:nodoc:
16
- class TestCase #:nodoc:
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)
23
- $_test_unit_result = result
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
7
+
8
+ module AEAssertionHandler
9
+ class << self
10
+ def included(base)
11
+ base.exception_handler(:handle_ae_assertion_error)
51
12
  end
52
- result.add_run
53
- yield(FINISHED, name)
54
- end
13
+ end
14
+
15
+ private
16
+ def handle_ae_assertion_error(exception)
17
+ return false unless exception.respond_to?(:assertion?) && exception.assertion?
18
+ problem_occurred
19
+ add_failure(exception.message, exception.backtrace)
20
+ true
21
+ end
22
+ end
23
+
24
+ class TestCase #:nodoc:
25
+ include AEAssertionHandler
55
26
  end
56
27
  end
57
28
  end
58
29
 
59
30
  class AE::Assertor #:nodoc:
60
31
  def self.increment_counts(pass)
61
- $_test_unit_result.add_assertion if $_test_unit_result
62
32
  counts[:total] += 1
63
33
  if pass
64
34
  counts[:pass] += 1
@@ -68,4 +38,3 @@ class AE::Assertor #:nodoc:
68
38
  return counts
69
39
  end
70
40
  end
71
-
@@ -161,7 +161,7 @@ class Proc
161
161
  # TODO: wrong place, change yield?
162
162
  def change?
163
163
  pre_result = yield
164
- called = call
164
+ call
165
165
  post_result = yield
166
166
  pre_result != post_result
167
167
  end
data/lib/ae/version.rb CHANGED
@@ -1,21 +1,3 @@
1
1
  module AE
2
- # Access project metadata.
3
- #
4
- # @return [Hash]
5
- def self.metadata
6
- @metadata ||= (
7
- require 'yaml'
8
- YAML.load(File.new(File.dirname(__FILE__) + '/../ae.yml'))
9
- )
10
- end
11
-
12
- #
13
- def self.const_missing(name)
14
- key = name.to_s.downcase
15
- metadata[key] || super(name)
16
- end
17
-
18
- # Becuase Ruby 1.8~ gets in the way :(
19
- VERSION = metadata['version']
2
+ VERSION = '1.9.0'
20
3
  end
21
-
metadata CHANGED
@@ -1,78 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
5
- prerelease:
4
+ version: 1.9.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Trans
9
- autorequire:
10
8
  bindir: bin
11
9
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
13
11
  dependencies:
14
12
  - !ruby/object:Gem::Dependency
15
13
  name: ansi
16
14
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
15
  requirements:
19
- - - ! '>='
16
+ - - ">="
20
17
  - !ruby/object:Gem::Version
21
18
  version: '0'
22
19
  type: :runtime
23
20
  prerelease: false
24
21
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
22
  requirements:
27
- - - ! '>='
23
+ - - ">="
28
24
  - !ruby/object:Gem::Version
29
25
  version: '0'
30
26
  - !ruby/object:Gem::Dependency
31
- name: detroit
27
+ name: rake
32
28
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
29
  requirements:
35
- - - ! '>='
30
+ - - ">="
36
31
  - !ruby/object:Gem::Version
37
- version: '0'
32
+ version: '13'
38
33
  type: :development
39
34
  prerelease: false
40
35
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
36
  requirements:
43
- - - ! '>='
37
+ - - ">="
44
38
  - !ruby/object:Gem::Version
45
- version: '0'
39
+ version: '13'
46
40
  - !ruby/object:Gem::Dependency
47
41
  name: qed
48
42
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
43
  requirements:
51
- - - ! '>='
44
+ - - ">="
52
45
  - !ruby/object:Gem::Version
53
- version: '0'
46
+ version: '2.9'
54
47
  type: :development
55
48
  prerelease: false
56
49
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
50
  requirements:
59
- - - ! '>='
51
+ - - ">="
60
52
  - !ruby/object:Gem::Version
61
- version: '0'
62
- description: ! "Assertive Expressive is an assertions library specifically designed
63
- \nfor reuse by other test frameworks."
53
+ version: '2.9'
54
+ description: Assertive Expressive is an assertions library specifically designed for
55
+ reuse by other test frameworks.
64
56
  email:
65
57
  - transfire@gmail.com
66
58
  executables: []
67
59
  extensions: []
68
- extra_rdoc_files:
69
- - DEMO.rdoc
60
+ extra_rdoc_files: []
61
+ files:
70
62
  - HISTORY.md
71
- - README.md
63
+ - LICENSE.txt
72
64
  - NOTICE.md
73
- files:
74
- - .ruby
75
- - .yardopts
65
+ - README.md
66
+ - demo/01_overview.md
67
+ - demo/02_assertion.md
68
+ - demo/03_assert.md
69
+ - demo/04_subjunctive.md
70
+ - demo/05_expect.md
71
+ - demo/06_counts.md
72
+ - demo/07_matchers.md
73
+ - demo/08_check.md
74
+ - demo/applique/ae.rb
75
+ - lib/ae.rb
76
76
  - lib/ae/adapter.rb
77
77
  - lib/ae/adapters/minitest.rb
78
78
  - lib/ae/adapters/rspec.rb
@@ -83,9 +83,9 @@ files:
83
83
  - lib/ae/assertor.rb
84
84
  - lib/ae/basic_object.rb
85
85
  - lib/ae/check.rb
86
+ - lib/ae/core_ext.rb
86
87
  - lib/ae/core_ext/exception.rb
87
88
  - lib/ae/core_ext/helpers.rb
88
- - lib/ae/core_ext.rb
89
89
  - lib/ae/expect.rb
90
90
  - lib/ae/legacy.rb
91
91
  - lib/ae/must.rb
@@ -93,36 +93,25 @@ files:
93
93
  - lib/ae/should.rb
94
94
  - lib/ae/subjunctive.rb
95
95
  - lib/ae/version.rb
96
- - lib/ae.rb
97
- - lib/ae.yml
98
- - DEMO.rdoc
99
- - HISTORY.md
100
- - README.md
101
- - NOTICE.md
102
- homepage: http://rubyworks.github.com/ae
96
+ homepage: https://github.com/rubyworks/ae
103
97
  licenses:
104
98
  - BSD-2-Clause
105
- post_install_message:
99
+ metadata: {}
106
100
  rdoc_options: []
107
101
  require_paths:
108
102
  - lib
109
103
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
104
  requirements:
112
- - - ! '>='
105
+ - - ">="
113
106
  - !ruby/object:Gem::Version
114
- version: '0'
107
+ version: '3.1'
115
108
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
109
  requirements:
118
- - - ! '>='
110
+ - - ">="
119
111
  - !ruby/object:Gem::Version
120
112
  version: '0'
121
113
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 1.8.24
124
- signing_key:
125
- specification_version: 3
114
+ rubygems_version: 3.6.9
115
+ specification_version: 4
126
116
  summary: Assertive Expressive
127
117
  test_files: []
128
- has_rdoc:
data/.ruby DELETED
File without changes
data/.yardopts DELETED
@@ -1,7 +0,0 @@
1
- --title "AE API"
2
- --protected
3
- --private
4
- lib/
5
- -
6
- [A-Z]*.*
7
-