passert 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 24bc8b6a6f929cd97fbca9a3d4b72e99a7f779ff
4
- data.tar.gz: f6991f53e826b87bc11d14a3fc4c84b176c6ece3
2
+ SHA256:
3
+ metadata.gz: 8903935f3bebcb9affa052c61128c916f98d3e5c8730f633e31a39449a116a0a
4
+ data.tar.gz: d9c50854c5693e1d2496918520df36ecb14ec106d64c8f8994c2093b0f042bdd
5
5
  SHA512:
6
- metadata.gz: 72cb81ca9f2eb946b11c3d3d45107f97bf2fcee0dfff7f66b110c168ed184ccdc8d70fed967dc19b00050c66f4c4f50e7496275c41a9db127e605d40c5cd35c5
7
- data.tar.gz: f4eb8ab3a43fd7c586e02cb14ce25b38ed44272f0b4361acaedc751c868c75924fbe31e14080aa916215cd36109b90b65b0887d9b9391632ec767114bdc57721
6
+ metadata.gz: 300cbefe7fe1782620c5352fa4e9d0d5bd6914fd3b339dd4804a23db9996349940ab9621bd9cb9bd08a5408dee55253896d6f30437474b38f5a76a1953f2bda4
7
+ data.tar.gz: bc0293cfed20301b4507cf2d4a23fb51ae13658e732bb6ee22ef7adc6f1ffcacf6d431b822f379a4ad06c4acabfe74ec02c76a416f6faab97e85e24ffe22a6c9
data/lib/passert.rb CHANGED
@@ -4,36 +4,20 @@ module Passert
4
4
  class AssertionFailed < StandardError; end
5
5
 
6
6
  class << self
7
- def assert(first, second = (second_omitted = true; nil))
8
- # Want to support:
9
- # assert(x) # Truthiness.
10
- # assert(thing, other) # Trip-equals.
11
- # assert([thing1, thing2], other) # Multiple Trip-equals.
12
-
13
- if second_omitted
14
- comparison = nil
15
- truth = first
16
- else
17
- comparison = first
18
- truth = second
19
- end
20
-
21
- pass =
22
- if second_omitted
23
- truth
24
- elsif comparison.is_a?(Array)
25
- comparison.any? { |k| k === truth }
26
- else
27
- comparison === truth
28
- end
7
+ def assert?(*args)
8
+ pass, _, _ = _check_assertion(*args)
9
+ pass
10
+ end
29
11
 
30
- return truth if pass
12
+ def assert(*args)
13
+ pass, expected, actual = _check_assertion(*args)
14
+ return actual if pass
31
15
 
32
16
  message =
33
17
  if block_given?
34
18
  yield
35
- elsif comparison
36
- "Expected #{comparison.inspect}, got #{truth.inspect}!"
19
+ elsif expected
20
+ "Expected #{expected.inspect}, got #{actual.inspect}!"
37
21
  else
38
22
  "Assertion failed!"
39
23
  end
@@ -48,5 +32,33 @@ module Passert
48
32
  raise AssertionFailed, message.to_s, backtrace
49
33
  end
50
34
  end
35
+
36
+ private
37
+
38
+ def _check_assertion(first, second = (second_omitted = true; nil))
39
+ # Want to support:
40
+ # assert(x) # Truthiness.
41
+ # assert(thing, other) # Trip-equals.
42
+ # assert([thing1, thing2], other) # Multiple Trip-equals.
43
+
44
+ if second_omitted
45
+ expected = nil
46
+ actual = first
47
+ else
48
+ expected = first
49
+ actual = second
50
+ end
51
+
52
+ pass =
53
+ if second_omitted
54
+ actual
55
+ elsif expected.is_a?(Array)
56
+ expected.any? { |k| k === actual }
57
+ else
58
+ expected === actual
59
+ end
60
+
61
+ [!!pass, expected, actual]
62
+ end
51
63
  end
52
64
  end
@@ -5,9 +5,13 @@ AssertionFailed = Passert::AssertionFailed
5
5
  module Kernel
6
6
  def assert(*args, &block)
7
7
  Passert.assert(*args, &block)
8
- rescue => e
8
+ rescue AssertionFailed => e
9
9
  # Remove this method from the backtrace, since it's not helpful.
10
10
  e.backtrace.shift
11
11
  raise e
12
12
  end
13
+
14
+ def assert?(*args, &block)
15
+ Passert.assert?(*args, &block)
16
+ end
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module Passert
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.5.1
93
+ rubygems_version: 2.7.3
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Simple assertions in Ruby.