sus-fixtures-console 0.4.0 → 0.5.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +87 -0
- data/context/index.yaml +13 -0
- data/lib/sus/fixtures/console/captured_logger.rb +11 -6
- data/lib/sus/fixtures/console/null_logger.rb +6 -4
- data/lib/sus/fixtures/console/version.rb +2 -2
- data/lib/sus/fixtures/console.rb +1 -1
- data/license.md +1 -1
- data/readme.md +5 -0
- data/releases.md +5 -0
- data.tar.gz.sig +0 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7422fc0acabbaaab2d3cf9f23b802989e50c3a8aeadc4889270288c7fe4b6bc
|
|
4
|
+
data.tar.gz: 320c04a418a41a2f536d8a3b4919439b45e06a3b1b709966c03663c9cbf8b992
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aefade50186e2ed0af3e6c3d0c81a270bb4645b63aaa999c650fe4c4113418c867ac513273d487293c4810f7624af30facfc0b6e6bba5ff385dd8579b975d52e
|
|
7
|
+
data.tar.gz: 72883f4c29cbd9e34df52befc688c68a51f55a73994568a378062c9f4f50a87d930e72288f4ef4d67830382d4e0c1099c9b17fc89d22fd92124270fd78b36eb8
|
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 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 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 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
|
+
```
|
data/context/index.yaml
ADDED
|
@@ -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.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2024, by Samuel Williams.
|
|
4
|
+
# Copyright, 2024-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require "sus/shared"
|
|
7
7
|
require "console"
|
|
@@ -13,11 +13,16 @@ module Sus
|
|
|
13
13
|
module Console
|
|
14
14
|
# Shared context for capturing console output during tests.
|
|
15
15
|
# Provides access to captured log messages and helper methods for testing console logging.
|
|
16
|
-
CapturedLogger
|
|
17
|
-
# @
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
module CapturedLogger
|
|
17
|
+
# @returns [Console::Capture] Captures console output for inspection.
|
|
18
|
+
def console_capture
|
|
19
|
+
@console_capture ||= ::Console::Capture.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @returns [Console::Logger] Logger configured to capture output at DEBUG level.
|
|
23
|
+
def console_logger
|
|
24
|
+
@console_logger ||= ::Console::Logger.new(console_capture, level: ::Console::Logger::DEBUG)
|
|
25
|
+
end
|
|
21
26
|
|
|
22
27
|
# Set up console logger before test execution and clean up afterwards.
|
|
23
28
|
def around
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2024, by Samuel Williams.
|
|
4
|
+
# Copyright, 2024-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require "sus/shared"
|
|
7
7
|
require "console"
|
|
@@ -13,9 +13,11 @@ module Sus
|
|
|
13
13
|
module Console
|
|
14
14
|
# Shared context for suppressing console output during tests.
|
|
15
15
|
# Redirects all console logging to a null output to prevent noise in test runs.
|
|
16
|
-
NullLogger
|
|
17
|
-
# @
|
|
18
|
-
|
|
16
|
+
module NullLogger
|
|
17
|
+
# @returns [Console::Logger] Logger configured to suppress all output.
|
|
18
|
+
def console_logger
|
|
19
|
+
@console_logger ||= ::Console::Logger.new(::Console::Output::Null.new)
|
|
20
|
+
end
|
|
19
21
|
|
|
20
22
|
# Set up null logger before test execution and clean up afterwards.
|
|
21
23
|
def around
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2024, by Samuel Williams.
|
|
4
|
+
# Copyright, 2024-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
module Sus
|
|
7
7
|
module Fixtures
|
|
8
8
|
module Console
|
|
9
|
-
VERSION = "0.
|
|
9
|
+
VERSION = "0.5.0"
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
data/lib/sus/fixtures/console.rb
CHANGED
data/license.md
CHANGED
data/readme.md
CHANGED
|
@@ -20,6 +20,11 @@ Please see the [project documentation](https://socketry.github.io/sus-fixtures-c
|
|
|
20
20
|
|
|
21
21
|
Please see the [project releases](https://socketry.github.io/sus-fixtures-console/releases/index) for all releases.
|
|
22
22
|
|
|
23
|
+
### v0.5.0
|
|
24
|
+
|
|
25
|
+
- Prefer modules over `Sus::Shared` contexts for better integration.
|
|
26
|
+
- Use `include Sus::Fixtures::Console::NullLogger` instead of `include_context Sus::Fixtures::Console::NullLogger`.
|
|
27
|
+
|
|
23
28
|
### v0.4.0
|
|
24
29
|
|
|
25
30
|
- Add agent context.
|
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sus-fixtures-console
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -70,6 +70,8 @@ executables: []
|
|
|
70
70
|
extensions: []
|
|
71
71
|
extra_rdoc_files: []
|
|
72
72
|
files:
|
|
73
|
+
- context/getting-started.md
|
|
74
|
+
- context/index.yaml
|
|
73
75
|
- lib/sus/fixtures/console.rb
|
|
74
76
|
- lib/sus/fixtures/console/captured_logger.rb
|
|
75
77
|
- lib/sus/fixtures/console/null_logger.rb
|
|
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
100
|
- !ruby/object:Gem::Version
|
|
99
101
|
version: '0'
|
|
100
102
|
requirements: []
|
|
101
|
-
rubygems_version: 3.
|
|
103
|
+
rubygems_version: 3.7.2
|
|
102
104
|
specification_version: 4
|
|
103
105
|
summary: Test fixtures for capturing Console output.
|
|
104
106
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|