passert 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/passert.rb +37 -25
- data/lib/passert/core_ext.rb +5 -1
- data/lib/passert/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8903935f3bebcb9affa052c61128c916f98d3e5c8730f633e31a39449a116a0a
|
4
|
+
data.tar.gz: d9c50854c5693e1d2496918520df36ecb14ec106d64c8f8994c2093b0f042bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
36
|
-
"Expected #{
|
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
|
data/lib/passert/core_ext.rb
CHANGED
@@ -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
|
data/lib/passert/version.rb
CHANGED
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.
|
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:
|
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.
|
93
|
+
rubygems_version: 2.7.3
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Simple assertions in Ruby.
|