sus-fixtures-console 0.3.1 → 0.4.1

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: 6c5226ba5f04c0aaa7a85face6d5d5ddaf0553369a5c90dbea7714b2a12d1aaf
4
- data.tar.gz: 1f07009379ae5acd0630c692656b18b555d1d2c2d6924c290268ab95f30e1a50
3
+ metadata.gz: 1e7cec179de60237b4aa5c02af965c5c408922527355fdc2a3ff4bb461af02c5
4
+ data.tar.gz: b0b6299b341defd1e00675e08188434456a6f06f63aa9fef38a879d867439e2a
5
5
  SHA512:
6
- metadata.gz: f595232b9ce0f4b252345a77b574a4fa7b01a9bc76beca7cee0a7b7fc38fdffc3d3b183186fd20b10a4921bca00ef4b8862560cdb25ebd5d1caddcdfb36e0113
7
- data.tar.gz: b4a4c3520d42adfa4a62828177b84d9d4fb69a1348d0b95da2121940ecd7ec32daa99b558097a16ee45a42e441b778fdae78bacdde4cb9f02d4b43c0773a1cb0
6
+ metadata.gz: e435cfb4bce7c62d9c94bbe46d74a347665870fd1ced6c5e8a52c6b072b85b8b67c9d81e67383ad0ec3c0ec04c8ea0214c25f78003c7c652b1c1d5863676d27b
7
+ data.tar.gz: c935ce69e39432c734c91de3fe09369b4475cc4ee7732db7af435148815bca90cacc6f613b40043fe5dc3eac5b92978cdaf2ed577e95447aab3d9b91a7c3a86b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,87 @@
1
+ # Getting Started
2
+
3
+ This guide explains how to use the `Sus::Fixtures::Console` gem to redirect console logging output during tests.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your project:
8
+
9
+ ``` bash
10
+ $ bundle add sus-fixtures-console
11
+ ```
12
+
13
+ ## Core Concepts
14
+
15
+ `sus-fixtures-console` provides two main fixtures:
16
+
17
+ - {ruby Sus::Fixtures::Console::CapturedLogger} - Captures console output for inspection and testing.
18
+ - {ruby Sus::Fixtures::Console::NullLogger} - Suppresses console output to reduce noise during test runs.
19
+
20
+ ## Usage
21
+
22
+ ### Capturing Console Output
23
+
24
+ Here is a basic example of a test, that captures the log output:
25
+
26
+ ``` ruby
27
+ require 'sus/fixtures/console/captured_logger'
28
+
29
+ describe Sus::Fixtures::Console::CapturedLogger do
30
+ include_context Sus::Fixtures::Console::CapturedLogger
31
+
32
+ it "should capture output" do
33
+ Console.debug("Hello, World!")
34
+
35
+ expect(console_capture.last).to have_keys(
36
+ severity: be == :debug,
37
+ subject: be == "Hello, World!"
38
+ )
39
+ end
40
+ end
41
+ ```
42
+
43
+ ### Ignoring Console Output
44
+
45
+ If you want to ignore the console output, you can use the `Sus::Fixtures::Console::NullLogger` fixture:
46
+
47
+ ``` ruby
48
+ describe Sus::Fixtures::Console::NullLogger do
49
+ include_context Sus::Fixtures::Console::NullLogger
50
+
51
+ it "should capture output" do
52
+ expect($stderr).not.to receive(:puts)
53
+ expect($stderr).not.to receive(:write)
54
+
55
+ Console.debug("Hello, World!")
56
+ end
57
+ end
58
+ ```
59
+
60
+ ### Advanced Usage
61
+
62
+ You can also use the `expect_console` helper method for more fluent test assertions:
63
+
64
+ ``` ruby
65
+ describe Sus::Fixtures::Console::CapturedLogger do
66
+ include_context Sus::Fixtures::Console::CapturedLogger
67
+
68
+ it "can use expect_console helper" do
69
+ Console.info("Processing complete")
70
+
71
+ expect_console.to have_logged(
72
+ severity: be == :info,
73
+ subject: be == "Processing complete"
74
+ )
75
+ end
76
+ end
77
+ ```
78
+
79
+ ### Setting a Default Log Level
80
+
81
+ In many cases, you may wish to set a default log level that only prints warnings or above:
82
+
83
+ ``` ruby
84
+ # In your `config/sus.rb` file:
85
+ require 'console'
86
+ Console.logger.warn!
87
+ ```
@@ -0,0 +1,13 @@
1
+ # Automatically generated context index for Utopia::Project guides.
2
+ # Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
3
+ ---
4
+ description: Test fixtures for capturing Console output.
5
+ metadata:
6
+ documentation_uri: https://socketry.github.io/sus-fixtures-console/
7
+ funding_uri: https://github.com/sponsors/ioquatix/
8
+ source_code_uri: https://github.com/socketry/sus-fixtures-console.git
9
+ files:
10
+ - path: getting-started.md
11
+ title: Getting Started
12
+ description: This guide explains how to use the `Sus::Fixtures::Console` gem to
13
+ redirect console logging output during tests.
@@ -3,18 +3,23 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'sus/shared'
7
- require 'console'
8
- require 'console/capture'
9
- require 'console/logger'
6
+ require "sus/shared"
7
+ require "console"
8
+ require "console/capture"
9
+ require "console/logger"
10
10
 
11
11
  module Sus
12
12
  module Fixtures
13
13
  module Console
14
+ # Shared context for capturing console output during tests.
15
+ # Provides access to captured log messages and helper methods for testing console logging.
14
16
  CapturedLogger = Sus::Shared("captured logger") do
17
+ # @attribute [Console::Capture] Captures console output for inspection.
15
18
  let(:console_capture) {::Console::Capture.new}
19
+ # @attribute [Console::Logger] Logger configured to capture output at DEBUG level.
16
20
  let(:console_logger) {::Console::Logger.new(console_capture, level: ::Console::Logger::DEBUG)}
17
21
 
22
+ # Set up console logger before test execution and clean up afterwards.
18
23
  def around
19
24
  ::Console.logger = console_logger
20
25
  super
@@ -22,10 +27,15 @@ module Sus
22
27
  ::Console.logger = nil
23
28
  end
24
29
 
30
+ # Create an expectation for the console capture.
31
+ # @returns [Object] An expectation object for the console capture.
25
32
  def expect_console
26
33
  expect(console_capture)
27
34
  end
28
35
 
36
+ # Create a matcher for checking logged messages with specific fields.
37
+ # @parameter fields [Hash] Key-value pairs to match in logged messages.
38
+ # @returns [Object] A matcher that checks for logged messages containing the specified fields.
29
39
  def have_logged(**fields)
30
40
  have_value(have_keys(**fields))
31
41
  end
@@ -3,17 +3,21 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'sus/shared'
7
- require 'console'
8
- require 'console/capture'
9
- require 'console/logger'
6
+ require "sus/shared"
7
+ require "console"
8
+ require "console/capture"
9
+ require "console/logger"
10
10
 
11
11
  module Sus
12
12
  module Fixtures
13
13
  module Console
14
+ # Shared context for suppressing console output during tests.
15
+ # Redirects all console logging to a null output to prevent noise in test runs.
14
16
  NullLogger = Sus::Shared("null logger") do
17
+ # @attribute [Console::Logger] Logger configured to suppress all output.
15
18
  let(:console_logger) {::Console::Logger.new(::Console::Output::Null.new)}
16
19
 
20
+ # Set up null logger before test execution and clean up afterwards.
17
21
  def around
18
22
  ::Console.logger = console_logger
19
23
  super
@@ -6,7 +6,7 @@
6
6
  module Sus
7
7
  module Fixtures
8
8
  module Console
9
- VERSION = "0.3.1"
9
+ VERSION = "0.4.1"
10
10
  end
11
11
  end
12
12
  end
@@ -3,5 +3,16 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require_relative 'console/version'
7
- require_relative 'console/captured_logger'
6
+ require_relative "console/version"
7
+ require_relative "console/captured_logger"
8
+ require_relative "console/null_logger"
9
+
10
+ # @namespace
11
+ module Sus
12
+ # @namespace
13
+ module Fixtures
14
+ # @namespace
15
+ module Console
16
+ end
17
+ end
18
+ end
data/readme.md CHANGED
@@ -16,6 +16,32 @@ Please see the [project documentation](https://socketry.github.io/sus-fixtures-c
16
16
 
17
17
  - [Getting Started](https://socketry.github.io/sus-fixtures-console/guides/getting-started/index) - This guide explains how to use the `Sus::Fixtures::Console` gem to redirect console logging output during tests.
18
18
 
19
+ ## Releases
20
+
21
+ Please see the [project releases](https://socketry.github.io/sus-fixtures-console/releases/index) for all releases.
22
+
23
+ ### v0.4.0
24
+
25
+ - Add agent context.
26
+
27
+ ### v0.3.1
28
+
29
+ - Modernize gem structure and dependencies.
30
+
31
+ ### v0.3.0
32
+
33
+ - Add `expect_console` helper method for more fluent test assertions.
34
+ - Add `have_logged` predicate for checking logged messages with specific fields.
35
+
36
+ ### v0.2.0
37
+
38
+ - Avoid using nested fiber to prevent potential issues with fiber-based concurrency.
39
+
40
+ ### v0.1.0
41
+
42
+ - Add `Sus::Fixtures::Console::CapturedLogger` for capturing console output during tests.
43
+ - Add `Sus::Fixtures::Console::NullLogger` for suppressing console output during tests.
44
+
19
45
  ## Contributing
20
46
 
21
47
  We welcome contributions to this project.
data/releases.md ADDED
@@ -0,0 +1,23 @@
1
+ # Releases
2
+
3
+ ## v0.4.0
4
+
5
+ - Add agent context.
6
+
7
+ ## v0.3.1
8
+
9
+ - Modernize gem structure and dependencies.
10
+
11
+ ## v0.3.0
12
+
13
+ - Add `expect_console` helper method for more fluent test assertions.
14
+ - Add `have_logged` predicate for checking logged messages with specific fields.
15
+
16
+ ## v0.2.0
17
+
18
+ - Avoid using nested fiber to prevent potential issues with fiber-based concurrency.
19
+
20
+ ## v0.1.0
21
+
22
+ - Add `Sus::Fixtures::Console::CapturedLogger` for capturing console output during tests.
23
+ - Add `Sus::Fixtures::Console::NullLogger` for suppressing console output during tests.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus-fixtures-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -37,7 +36,7 @@ cert_chain:
37
36
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
37
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
38
  -----END CERTIFICATE-----
40
- date: 2024-08-25 00:00:00.000000000 Z
39
+ date: 1980-01-02 00:00:00.000000000 Z
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: console
@@ -67,18 +66,19 @@ dependencies:
67
66
  - - "~>"
68
67
  - !ruby/object:Gem::Version
69
68
  version: '0.10'
70
- description:
71
- email:
72
69
  executables: []
73
70
  extensions: []
74
71
  extra_rdoc_files: []
75
72
  files:
73
+ - context/getting-started.md
74
+ - context/index.yaml
76
75
  - lib/sus/fixtures/console.rb
77
76
  - lib/sus/fixtures/console/captured_logger.rb
78
77
  - lib/sus/fixtures/console/null_logger.rb
79
78
  - lib/sus/fixtures/console/version.rb
80
79
  - license.md
81
80
  - readme.md
81
+ - releases.md
82
82
  homepage: https://github.com/socketry/sus-fixtures-console
83
83
  licenses:
84
84
  - MIT
@@ -86,7 +86,6 @@ metadata:
86
86
  documentation_uri: https://socketry.github.io/sus-fixtures-console/
87
87
  funding_uri: https://github.com/sponsors/ioquatix/
88
88
  source_code_uri: https://github.com/socketry/sus-fixtures-console.git
89
- post_install_message:
90
89
  rdoc_options: []
91
90
  require_paths:
92
91
  - lib
@@ -94,15 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
93
  requirements:
95
94
  - - ">="
96
95
  - !ruby/object:Gem::Version
97
- version: '3.1'
96
+ version: '3.2'
98
97
  required_rubygems_version: !ruby/object:Gem::Requirement
99
98
  requirements:
100
99
  - - ">="
101
100
  - !ruby/object:Gem::Version
102
101
  version: '0'
103
102
  requirements: []
104
- rubygems_version: 3.5.11
105
- signing_key:
103
+ rubygems_version: 3.6.9
106
104
  specification_version: 4
107
105
  summary: Test fixtures for capturing Console output.
108
106
  test_files: []
metadata.gz.sig CHANGED
Binary file