sus 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6150fc65498872a9502ff62dbaa6e377ad47b0412e7f5109646dc6b0331d4a3
4
- data.tar.gz: fb632958567ea9539e1eea8a1b6bc81ad567f8834cc82495a9ec626c86ad2ae5
3
+ metadata.gz: cbfd2216a9188a212a020c1e4780bc01e2d7b1246bf2f9475d28ad7e4e939f31
4
+ data.tar.gz: 4929af7ca54b12e5e5cf460a097a507c782c64a5eb9265e425df12ed71e5c1b2
5
5
  SHA512:
6
- metadata.gz: e3c430dd6e1fb26da0c3da657fe39677f2301db6fc312a0dc27f8078bfc7bcd3f666685fdd02d5a5bbcefd0e40fda4bcb7b704654e97e169658c82ea60f88d70
7
- data.tar.gz: c740efacfa31ee8306a81a15d2b5ed1573fc10376752fe5a55cab4883a90e0d90315a11a4af0b39428e05b7d3e8aaa72ecd4e6efa767595d3e94a1065d83d7d4
6
+ metadata.gz: 7f246c6a57ec8c2ac0bf995e7e7194e1aa2b526f858fc9efb6942b7769b7fe801b7c8095e06c4f5127d71669510813c00185d831cf983624cf2b6ad1776fc2d0
7
+ data.tar.gz: 279b9ec5642a6a3a4af069524c0944ff08d0d101066189054ac00ebacd215886a0f84b23dd2a6ae07ad0c65bc6c646bcd6374298910b913d9a9b152259aa64de
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/sus/be.rb CHANGED
@@ -66,5 +66,9 @@ module Sus
66
66
  def be_a(klass)
67
67
  Be.new(:is_a?, klass)
68
68
  end
69
+
70
+ def be_nil
71
+ Be.new(:nil?)
72
+ end
69
73
  end
70
74
  end
data/lib/sus/expect.rb CHANGED
@@ -51,5 +51,9 @@ module Sus
51
51
  Expect.new(@__assertions__, subject, **options)
52
52
  end
53
53
  end
54
+
55
+ def is_expected
56
+ expect(subject)
57
+ end
54
58
  end
55
59
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
5
+
6
+ module Sus
7
+ class HaveAttributes
8
+ def initialize(attributes)
9
+ @attributes = attributes
10
+ end
11
+
12
+ def print(output)
13
+ first = true
14
+ output.write("have attributes {")
15
+ @attributes.each do |key, predicate|
16
+ if first
17
+ first = false
18
+ else
19
+ output.write(", ")
20
+ end
21
+
22
+ output.write(:variable, key.to_s, :reset, " ", predicate, :reset)
23
+ end
24
+ output.write("}")
25
+ end
26
+
27
+ def call(assertions, subject)
28
+ assertions.nested(self) do |assertions|
29
+ @attributes.each do |key, predicate|
30
+ predicate.call(assertions, subject.public_send(key))
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ class Base
37
+ def have_attributes(...)
38
+ HaveAttributes.new(...)
39
+ end
40
+ end
41
+ end
data/lib/sus/it.rb CHANGED
@@ -7,7 +7,7 @@ require_relative 'context'
7
7
 
8
8
  module Sus
9
9
  module It
10
- def self.build(parent, description, &block)
10
+ def self.build(parent, description = nil, &block)
11
11
  base = Class.new(parent)
12
12
  base.extend(It)
13
13
  base.description = description
@@ -26,7 +26,12 @@ module Sus
26
26
 
27
27
  def print(output)
28
28
  self.superclass.print(output)
29
- output.write(" it ", :it, self.description, :reset, " ", :identity, self.identity.to_s, :reset)
29
+
30
+ if description = self.description
31
+ output.write(" it ", :it, description, :reset, " ", :identity, self.identity.to_s, :reset)
32
+ else
33
+ output.write(" and ", :identity, self.identity.to_s, :reset)
34
+ end
30
35
  end
31
36
 
32
37
  def call(assertions)
@@ -13,7 +13,9 @@ module Sus
13
13
  end
14
14
 
15
15
  def self.for(exception, identity = nil)
16
- self.new(exception.backtrace_locations, identity&.path)
16
+ # I've disabled the root filter here, because partial backtraces are not very useful.
17
+ # We might want to do something to improve presentation of the backtrace based on the root instead.
18
+ self.new(exception.backtrace_locations) # , identity&.path)
17
19
  end
18
20
 
19
21
  def initialize(stack, root = nil, limit = nil)
@@ -8,6 +8,12 @@ module Sus
8
8
  def initialize(exception_class = nil, message: nil)
9
9
  @exception_class = exception_class
10
10
  @message = message
11
+ @predicate = nil
12
+ end
13
+
14
+ def and(predicate)
15
+ @predicate = predicate
16
+ return self
11
17
  end
12
18
 
13
19
  def call(assertions, subject)
@@ -16,14 +22,16 @@ module Sus
16
22
  subject.call
17
23
 
18
24
  # Didn't throw any exception, so the expectation failed:
19
- assertions.assert(false, self)
25
+ assertions.assert(false, "raised")
20
26
  rescue @exception_class => exception
21
27
  # Did it have the right message?
22
28
  if @message
23
- assertions.assert(@message === exception.message)
29
+ assertions.assert(@message === exception.message, "raised with message")
24
30
  else
25
- assertions.assert(true, self)
31
+ assertions.assert(true, "raised")
26
32
  end
33
+
34
+ @predicate&.call(assertions, exception)
27
35
  end
28
36
  end
29
37
  end
@@ -38,6 +46,10 @@ module Sus
38
46
  if @message
39
47
  output.write(" with message ", :variable, @message, :reset)
40
48
  end
49
+
50
+ if @predicate
51
+ output.write(" and ", @predicate)
52
+ end
41
53
  end
42
54
  end
43
55
 
data/lib/sus/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2022, by Samuel Williams.
5
5
 
6
6
  module Sus
7
- VERSION = "0.10.3"
7
+ VERSION = "0.10.4"
8
8
  end
data/lib/sus.rb CHANGED
@@ -17,5 +17,6 @@ require_relative 'sus/receive'
17
17
 
18
18
  require_relative 'sus/raise_exception'
19
19
  require_relative 'sus/have_duration'
20
+ require_relative 'sus/have_attributes'
20
21
 
21
22
  require_relative 'sus/filter'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-08-25 00:00:00.000000000 Z
40
+ date: 2022-08-26 00:00:00.000000000 Z
41
41
  dependencies: []
42
42
  description:
43
43
  email:
@@ -62,6 +62,7 @@ files:
62
62
  - lib/sus/file.rb
63
63
  - lib/sus/filter.rb
64
64
  - lib/sus/fixtures.rb
65
+ - lib/sus/have_attributes.rb
65
66
  - lib/sus/have_duration.rb
66
67
  - lib/sus/identity.rb
67
68
  - lib/sus/include_context.rb
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- fa��ب�]`F���Й��]f�>�"������z���Züsj7N8Q�7���g-�0�x�V��$���cJA���8L^$�p[>P(�$  ;Qvlhv����M�|9Am�� ?*���h0Sj*�����}��q'f9۔��&� ���}2e0�m�~����~�Z��)�bu��*�` 74[]_�T/�A���*6>f4��}������1�%74x��'���L7W:Ư�9)0��`p��ƽN��a{�H�ɒ�Zķ�X-�+�� �;B�2ia��N��sMk��G�h��ʷ"E
2
- �ӽ�ѽ��ׁ��M���1T�-����%>>uaZ>v�.#\�z{��LI�:)s?
1
+ ��J��X^�v9�p���?^[�<~bE��>��$njh���h��V��#ux��VPAf|aDV}��s/��#��dA7-�6U�1��T;a��f��������3��h�TT��W��:���M �=����̃��
2
+ �nA�%��%����w������Q6\�6��t㳉9I۾�d��2Uܠ��d{ ���,\_�t��]AH��'E�?A���+?���5�e.p!%��z��