sus 0.29.1 → 0.31.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
2
  SHA256:
3
- metadata.gz: fb73658184c73da088c57ee5bb4a86834116fdfb31cccf7a7c93248bac9854c1
4
- data.tar.gz: ba96338fe0a444462b1a1d4d5f2c249b84874a7be4431a0aac395427e3e92cb5
3
+ metadata.gz: c3ef71ae68fa2f1c55825c77c389370bd8903b6888bc1a4034126d945c0d0e0c
4
+ data.tar.gz: 4abbb662af110be31822445fbb76049a26df539630d68466231dd117bb4ef50b
5
5
  SHA512:
6
- metadata.gz: 9f6469a0c7d2168a11cf3da899e348db511fba9a019fff95a28079ad0b4fb21639fb14a0883f59d69b4fe992aa326b6a58917b05470ed513ae713b0f9b0340dd
7
- data.tar.gz: 81282c2660c353a69d38800e70386fdba27a8f8221d522967a66d442a9be1692c75340c75f4a3bf14b0f774bc8367c5a2f5ac43e281cf01112b4d31d0f232782
6
+ metadata.gz: c7ccf1055d49fdb0dcb45b4c3cad14c91f325bc0e897018680354cc1a6ae83c5476f7a240370a98569eabb523603d7b2006e3bd028571e82ef8e0138c337cd13
7
+ data.tar.gz: 49c602c11a456c8eaefcf105e4c135efd18c8c62a3106fc475de03245ce99ace9281d2a246528b0bff96ff153983430748967e4ee7b530e6a91008bbf9044394
checksums.yaml.gz.sig CHANGED
Binary file
data/bin/sus CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # require 'stackprof'
4
5
  # StackProf.start(mode: :wall, interval: 10)
data/bin/sus-host CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'json'
4
5
 
data/bin/sus-parallel CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative '../lib/sus/config'
4
5
  config = Sus::Config.load
data/bin/sus-tree CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'json'
4
5
 
data/lib/sus/base.rb CHANGED
@@ -16,18 +16,31 @@ module Sus
16
16
  "\#<Sus::Base for #{self.class.description.inspect}>"
17
17
  end
18
18
 
19
+ # A hook which is called before the test is executed.
20
+ #
21
+ # If you override this method, you must call super.
19
22
  def before
20
23
  end
21
24
 
22
- def after
25
+ # A hook which is called after the test is executed.
26
+ #
27
+ # If you override this method, you must call super.
28
+ def after(error = nil)
23
29
  end
24
30
 
25
- def around
31
+ # Wrap logic around the test being executed.
32
+ #
33
+ # Invokes the before hook, then the block, then the after hook.
34
+ #
35
+ # @yields {...} the block which should execute a test.
36
+ def around(&block)
26
37
  self.before
27
38
 
28
- return yield
39
+ return block.call
40
+ rescue => error
41
+ raise
29
42
  ensure
30
- self.after
43
+ self.after(error)
31
44
  end
32
45
 
33
46
  def assert(...)
data/lib/sus/context.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2023, by Samuel Williams.
4
+ # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'assertions'
7
7
  require_relative 'identity'
@@ -75,5 +75,56 @@ module Sus
75
75
  end
76
76
  end
77
77
  end
78
+
79
+ # Include an around method to the context class, that invokes the given block before running the test.
80
+ #
81
+ # Before hooks are usually invoked in the order they are defined, i.e. the first defined hook is invoked first.
82
+ #
83
+ # @parameter hook [Proc] The block to execute before each test.
84
+ def before(&hook)
85
+ wrapper = Module.new
86
+
87
+ wrapper.define_method(:before) do
88
+ super()
89
+
90
+ instance_exec(&hook)
91
+ end
92
+
93
+ self.include(wrapper)
94
+ end
95
+
96
+ # Include an around method to the context class, that invokes the given block after running the test.
97
+ #
98
+ # After hooks are usually invoked in the reverse order they are defined, i.e. the last defined hook is invoked first.
99
+ #
100
+ # @parameter hook [Proc] The block to execute after each test. An `error` argument is passed if the test failed with an exception.
101
+ def after(&hook)
102
+ wrapper = Module.new
103
+
104
+ wrapper.define_method(:after) do |error|
105
+ instance_exec(error, &hook)
106
+ rescue => error
107
+ raise
108
+ ensure
109
+ super(error)
110
+ end
111
+
112
+ self.include(wrapper)
113
+ end
114
+
115
+ # Add an around hook to the context class.
116
+ #
117
+ # Around hooks are called in the reverse order they are defined.
118
+ #
119
+ # The top level `around` implementation invokes before and after hooks.
120
+ #
121
+ # @paremeter block [Proc] The block to execute around each test.
122
+ def around(&block)
123
+ wrapper = Module.new
124
+
125
+ wrapper.define_method(:around, &block)
126
+
127
+ self.include(wrapper)
128
+ end
78
129
  end
79
130
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2023, by Samuel Williams.
4
+ # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'context'
7
7
 
8
8
  module Sus
9
9
  module Context
10
+ # Include a shared context into the current context, along with any arguments or options.
11
+ #
12
+ # @parameter shared [Sus::Shared] The shared context to include.
13
+ # @parameter arguments [Array] The arguments to pass to the shared context.
14
+ # @parameter options [Hash] The options to pass to the shared context.
10
15
  def include_context(shared, *arguments, **options)
11
16
  self.class_exec(*arguments, **options, &shared.block)
12
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2023, by Samuel Williams.
4
+ # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'context'
7
7
 
@@ -18,12 +18,12 @@ module Sus
18
18
  base.description = shared.name
19
19
  base.identity = Identity.nested(parent.identity, base.description, unique: unique)
20
20
  base.set_temporary_name("#{self}[#{base.description}]")
21
-
21
+
22
22
  # User provided block is evaluated first, so that it can provide default behaviour for the shared context:
23
23
  if block_given?
24
24
  base.class_exec(*arguments, &block)
25
25
  end
26
-
26
+
27
27
  base.class_exec(*arguments, &shared.block)
28
28
  return base
29
29
  end
data/lib/sus/mock.rb CHANGED
@@ -82,7 +82,7 @@ module Sus
82
82
  end
83
83
 
84
84
  module Mocks
85
- def after
85
+ def after(error = nil)
86
86
  super
87
87
 
88
88
  @mocks&.each_value(&:clear)
data/lib/sus/shared.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
4
+ # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'context'
7
7
 
@@ -11,13 +11,21 @@ module Sus
11
11
  attr_accessor :block
12
12
 
13
13
  def self.build(name, block)
14
- base = Class.new
14
+ base = Module.new
15
15
  base.extend(Shared)
16
16
  base.name = name
17
17
  base.block = block
18
18
 
19
19
  return base
20
20
  end
21
+
22
+ def included(base)
23
+ base.class_exec(&self.block)
24
+ end
25
+
26
+ def prepended(base)
27
+ base.class_exec(&self.block)
28
+ end
21
29
  end
22
30
 
23
31
  def self.Shared(name, &block)
data/lib/sus/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  module Sus
7
- VERSION = "0.29.1"
7
+ VERSION = "0.31.0"
8
8
  end
data/readme.md CHANGED
@@ -1,40 +1,33 @@
1
- # Sus(picious)
1
+ # Sus
2
2
 
3
- An opinionated test framework designed with several goals:
3
+ Sus is a testing framework for Ruby.
4
4
 
5
- - As fast as possible, aiming for \~10,000 assertions per second per core.
6
- - Isolated tests which parallelise easily (including `class` definitions).
7
- - Native support for balanced (work-stealing) multi-core execution.
8
- - Incredible test output with detailed failure logging (including nested assertions and predicates).
5
+ - It's similar to RSpec but with less baggage and more parallelism.
6
+ - It uses `expect` style syntax with first-class predicates.
7
+ - It has direct [support for code coverage](https://github.com/socketry/covered).
8
+ - It supports the [VSCode Test Runner interface](https://github.com/socketry/sus-vscode).
9
+ - It's based on my experience writing thousands of tests.
10
+ - It's easy to extend (see the `sus-fixtures-` gems for examples).
9
11
 
10
- Non-features:
12
+ [![Development Status](https://github.com/socketry/sus/workflows/Test/badge.svg)](https://github.com/socketry/sus/actions?workflow=Test)
11
13
 
12
- - Flexibility at the expense of performance.
13
- - Backwards compatibility.
14
+ ## Lightning Talk: Testing with Sus (2023)
14
15
 
15
- [![Development Status](https://github.com/sus-rb/sus/workflows/Test/badge.svg)](https://github.com/sus-rb/sus/actions?workflow=Test)
16
+ <div align="center">
17
+ <a href="https://www.youtube.com/watch?v=BDQHgb2rrwU">
18
+ <img src="https://img.youtube.com/vi/BDQHgb2rrwU/0.jpg" alt="Testing with Sus">
19
+ </a>
20
+ </div>
16
21
 
17
- ## Ideas
18
-
19
- I've been thinking about how this should grow long term. I see a separation between "defining tests" and "running tests". I think this gem should be split across those responsibilities. By doing so, defining tests remains relatively static, but can be extended independently of execution model. And execution models which include parallelism, code coverage, multi-server, etc can be implemented effectively.
20
-
21
- The key point is that we need a well defined interface between defining tests and running tests. This interface is provided by the test registry, which can load test files. The test registry provides a way to enumerate all tests where each test has an identity that uniquely identifies it.
22
-
23
- ### Sequential vs Parallel
24
-
25
- `sus` has both sequential and multi-threaded (`sus-parallel`) execution models for tests. Parallel execution is potentially much faster. This is an experimental feature.
26
-
27
- ![Sequential vs Parallel](https://user-images.githubusercontent.com/30030/144770080-092cf07b-b121-4754-96e0-8ff1d8ea0695.mov)
22
+ ## Usage
28
23
 
29
- ## Installation
24
+ Please see the [project documentation](https://socketry.github.io/sus/) for more details.
30
25
 
31
- ``` shell
32
- bundle add sus
33
- ```
26
+ - [Getting Started](https://socketry.github.io/sus/guides/getting-started/index) - This guide explains how to use the `sus` gem to write tests for your Ruby projects.
34
27
 
35
- ## Usage
28
+ ## See Also
36
29
 
37
- Check `test` directory for examples.
30
+ - [sus-vscode](https://github.com/socketry/sus-vscode) - Visual Studio Code extension for Sus.
38
31
 
39
32
  ## Contributing
40
33
 
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.29.1
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2024-07-17 00:00:00.000000000 Z
41
+ date: 2024-07-28 00:00:00.000000000 Z
42
42
  dependencies: []
43
43
  description:
44
44
  email:
@@ -101,13 +101,13 @@ files:
101
101
  - lib/sus/with.rb
102
102
  - license.md
103
103
  - readme.md
104
- homepage: https://github.com/sus-rb/sus
104
+ homepage: https://github.com/socketry/sus
105
105
  licenses:
106
106
  - MIT
107
107
  metadata:
108
- documentation_uri: https://sus-rb.github.io/sus/
108
+ documentation_uri: https://socketry.github.io/sus/
109
109
  funding_uri: https://github.com/sponsors/ioquatix/
110
- source_code_uri: https://github.com/sus-rb/sus.git
110
+ source_code_uri: https://github.com/socketry/sus.git
111
111
  post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
metadata.gz.sig CHANGED
Binary file