sus 0.14.0 → 0.15.0

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: 1aa2de6186ab05050d85b1125c7244bb6cf25b1250f9973bc067f72a405e9396
4
- data.tar.gz: 0bed63c55b1d2571d981efcb44fd5c008eab6f78e47bb7bf2d53e061b356b59a
3
+ metadata.gz: 68595280910704ed5eb41683985ffaff34df40eb30e72408da93667de742fb0c
4
+ data.tar.gz: fc0ac561eae164316247c381c0a20cb244c61c0af6b68891ea120fad2f7916c4
5
5
  SHA512:
6
- metadata.gz: fe13105ac13ba02104c02e512273964b0b784cae3663faec805cd6bb4d3ed2efeb4fe0720521817766ea3a438f81ebf5ffc5a8877c864d131c31fbedaed6ec17
7
- data.tar.gz: 23abcec32de31cdb6243a43439bc2a41e38842a456feb191808734aa2387c701c75de25af39f15c35474c1c6e222ea78e797b305247a8cd6ed5b646824cf7ea4
6
+ metadata.gz: 1fa0de727817b73859de636f2414dcd08b6001cdd5d837cc9ca72caa3014bdfe08052a0d5c785c91127ee8632e21e64d1eb43817e00baeee2461e698975ab937
7
+ data.tar.gz: 2ce965a251d21411e22f8d5feb8ae5573805c18da2e8061ef47768e60600721ebd0d72cb2d8c9a6e1d6be6989dbddb32f12a8fd5a26d65e64c9cb3b47bc7d4ac
checksums.yaml.gz.sig CHANGED
Binary file
@@ -139,6 +139,10 @@ module Sus
139
139
  end
140
140
  end
141
141
 
142
+ def skip(reason)
143
+ @output.puts(:indent, :skip, skip_prefix, reason)
144
+ end
145
+
142
146
  def inform(message)
143
147
  @output.puts(:indent, :inform, inform_prefix, message)
144
148
  end
@@ -303,5 +307,9 @@ module Sus
303
307
  def inform_prefix
304
308
  "ℹ "
305
309
  end
310
+
311
+ def skip_prefix
312
+ "⚠ "
313
+ end
306
314
  end
307
315
  end
data/lib/sus/be.rb CHANGED
@@ -72,5 +72,9 @@ module Sus
72
72
  def be_nil
73
73
  Be::NIL
74
74
  end
75
+
76
+ def be_equal(other)
77
+ Be.new(:equal?, other)
78
+ end
75
79
  end
76
80
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
5
+
6
+ module Sus
7
+ module BeTruthy
8
+ def self.print(output)
9
+ output.write("be truthy")
10
+ end
11
+
12
+ def self.call(assertions, subject)
13
+ assertions.nested(self) do |assertions|
14
+ assertions.assert(subject, self)
15
+ end
16
+ end
17
+ end
18
+
19
+ module BeFalsey
20
+ def self.print(output)
21
+ output.write("be falsey")
22
+ end
23
+
24
+ def self.call(assertions, subject)
25
+ assertions.nested(self) do |assertions|
26
+ assertions.assert(!subject, self)
27
+ end
28
+ end
29
+ end
30
+
31
+ class Base
32
+ def be_truthy
33
+ BeTruthy
34
+ end
35
+
36
+ def be_falsey
37
+ BeFalsey
38
+ end
39
+ end
40
+ end
data/lib/sus/file.rb CHANGED
@@ -11,7 +11,7 @@ Sus::TOPLEVEL_CLASS_EVAL = ->(klass, path){klass.class_eval(::File.read(path), p
11
11
  module Sus
12
12
  module File
13
13
  extend Context
14
-
14
+
15
15
  def self.extended(base)
16
16
  base.children = Hash.new
17
17
  end
data/lib/sus/it.rb CHANGED
@@ -39,10 +39,20 @@ module Sus
39
39
  instance = self.new(assertions)
40
40
 
41
41
  instance.around do
42
- instance.call
42
+ handle_skip(instance, assertions)
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ def handle_skip(instance, assertions)
48
+ reason = catch(:skip) do
49
+ return instance.call
50
+ end
51
+
52
+ assertions.skip(reason)
53
+
54
+ return nil
55
+ end
46
56
  end
47
57
 
48
58
  module Context
@@ -50,4 +60,10 @@ module Sus
50
60
  add It.build(self, ...)
51
61
  end
52
62
  end
63
+
64
+ class Base
65
+ def skip(reason)
66
+ throw :skip, reason
67
+ end
68
+ end
53
69
  end
@@ -11,12 +11,18 @@ module Sus
11
11
 
12
12
  attr_accessor :shared
13
13
 
14
- def self.build(parent, shared, unique: false)
14
+ def self.build(parent, shared, unique: false, &block)
15
15
  base = Class.new(parent)
16
16
  base.singleton_class.prepend(ItBehavesLike)
17
17
  base.children = Hash.new
18
18
  base.description = shared.name
19
19
  base.identity = Identity.nested(parent.identity, base.description, unique: unique)
20
+
21
+ # User provided block is evaluated first, so that it can provide default behaviour for the shared context:
22
+ if block_given?
23
+ base.class_exec(&block)
24
+ end
25
+
20
26
  base.class_exec(&shared.block)
21
27
  return base
22
28
  end
@@ -28,8 +34,8 @@ module Sus
28
34
  end
29
35
 
30
36
  module Context
31
- def it_behaves_like(shared, **options)
32
- add ItBehavesLike.build(self, shared, **options)
37
+ def it_behaves_like(shared, **options, &block)
38
+ add ItBehavesLike.build(self, shared, **options, &block)
33
39
  end
34
40
  end
35
41
  end
@@ -14,7 +14,6 @@ module Sus
14
14
  def initialize(state = :free, context = nil)
15
15
  @state = state
16
16
  @context = context
17
- @index = 0
18
17
  end
19
18
 
20
19
  INDICATORS = {
@@ -36,8 +35,6 @@ module Sus
36
35
  end
37
36
 
38
37
  def print(output)
39
- message = @message
40
-
41
38
  output.write(
42
39
  @state, self.indicator, " "
43
40
  )
@@ -19,6 +19,8 @@ module Sus
19
19
  @styles[:indent] = @indent
20
20
  end
21
21
 
22
+ attr :styles
23
+
22
24
  def buffered
23
25
  Buffered.new(self)
24
26
  end
data/lib/sus/output.rb CHANGED
@@ -40,6 +40,7 @@ module Sus
40
40
  output[:passed] = output.style(:green)
41
41
  output[:failed] = output.style(:red)
42
42
  output[:error] = output.style(:red)
43
+ output[:skip] = output.style(:blue)
43
44
  # output[:inform] = output.style(nil, nil, :bold)
44
45
 
45
46
  return output
data/lib/sus/receive.rb CHANGED
@@ -47,14 +47,17 @@ module Sus
47
47
 
48
48
  def once
49
49
  @times = Times.new(Be.new(:==, 1))
50
+ return self
50
51
  end
51
52
 
52
53
  def twice
53
54
  @times = Times.new(Be.new(:==, 2))
55
+ return self
54
56
  end
55
57
 
56
58
  def with_call_count(predicate)
57
59
  @times = Times.new(predicate)
60
+ return self
58
61
  end
59
62
 
60
63
  def and_return(*returning)
data/lib/sus/registry.rb CHANGED
@@ -19,6 +19,8 @@ require_relative 'let'
19
19
 
20
20
  module Sus
21
21
  class Registry
22
+ DIRECTORY_GLOB = "**/*.rb"
23
+
22
24
  # Create a top level scope with self as the instance:
23
25
  def initialize(base = Sus.base(self))
24
26
  @base = base
@@ -31,9 +33,21 @@ module Sus
31
33
  end
32
34
 
33
35
  def load(path)
36
+ if ::File.directory?(path)
37
+ load_directory(path)
38
+ else
39
+ load_file(path)
40
+ end
41
+ end
42
+
43
+ private def load_file(path)
34
44
  @base.file(path)
35
45
  end
36
46
 
47
+ private def load_directory(path)
48
+ ::Dir.glob(::File.join(path, DIRECTORY_GLOB), &self.method(:load_file))
49
+ end
50
+
37
51
  def call(assertions = Assertions.default)
38
52
  @base.call(assertions)
39
53
 
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.14.0"
7
+ VERSION = "0.15.0"
8
8
  end
data/lib/sus.rb CHANGED
@@ -10,6 +10,7 @@ require_relative 'sus/assertions'
10
10
 
11
11
  require_relative 'sus/expect'
12
12
  require_relative 'sus/be'
13
+ require_relative 'sus/be_truthy'
13
14
  require_relative 'sus/be_within'
14
15
 
15
16
  require_relative 'sus/mock'
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.14.0
4
+ version: 0.15.0
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-10-03 00:00:00.000000000 Z
40
+ date: 2022-10-30 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bake-test
@@ -95,6 +95,7 @@ files:
95
95
  - lib/sus/assertions.rb
96
96
  - lib/sus/base.rb
97
97
  - lib/sus/be.rb
98
+ - lib/sus/be_truthy.rb
98
99
  - lib/sus/be_within.rb
99
100
  - lib/sus/clock.rb
100
101
  - lib/sus/config.rb
metadata.gz.sig CHANGED
Binary file