jet_black 0.3.0 → 0.4.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
- data/.circleci/config.yml +51 -32
- data/.gitignore +2 -0
- data/CHANGELOG.md +5 -0
- data/Dockerfile +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +30 -26
- data/bin/docker_test +6 -0
- data/bin/jet_black_bin_example +1 -1
- data/lib/jet_black/ansi_scrubber.rb +22 -0
- data/lib/jet_black/environment.rb +1 -1
- data/lib/jet_black/executed_command.rb +14 -3
- data/lib/jet_black/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb06cc77894ad09aa2a5c00da5226227b6416624ac7c02a0d0c558e457667c1
|
4
|
+
data.tar.gz: 494d96406354c2d46fd34ea105830ee54f2b84da23fe43167446d9ab41d3cad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b27d58676baaa1ef5d3513b0515398798aa137461e5eb649a8cd598e51bd24e344db543e67d68c2a12449e44808a775abc769fcc0adffd5e7bc0c0a22404f463
|
7
|
+
data.tar.gz: 99451118f6c55638e989f41c8ef83773c5f9e6fa86d281ae0087282e2ea6694788eed7637d47e02f9e431c4472782f10007cc4fcd1d6a9ccbf7720268075679a
|
data/.circleci/config.yml
CHANGED
@@ -1,43 +1,62 @@
|
|
1
|
+
---
|
1
2
|
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.5
|
6
|
-
environment:
|
7
|
-
ENABLE_COVERAGE: 1
|
8
3
|
|
9
|
-
|
4
|
+
#-------------------------------------------------------------------------------
|
10
5
|
|
11
|
-
|
12
|
-
|
6
|
+
base_job: &base_job
|
7
|
+
working_directory: ~/repo
|
8
|
+
steps:
|
9
|
+
- checkout
|
13
10
|
|
14
|
-
|
15
|
-
|
11
|
+
- restore_cache:
|
12
|
+
keys:
|
16
13
|
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
17
14
|
# fallback to using the latest cache if no exact match is found
|
18
15
|
- v1-dependencies-
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
bundle exec rspec --format progress \
|
17
|
+
- run:
|
18
|
+
name: install dependencies
|
19
|
+
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
20
|
+
|
21
|
+
- save_cache:
|
22
|
+
paths:
|
23
|
+
- ./vendor/bundle
|
24
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
25
|
+
|
26
|
+
- run:
|
27
|
+
name: run tests
|
28
|
+
command: |
|
29
|
+
mkdir /tmp/test-results
|
30
|
+
bundle exec rspec --format progress \
|
35
31
|
--format RspecJunitFormatter \
|
36
32
|
--out /tmp/test-results/rspec.xml
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
# collect reports
|
35
|
+
- store_test_results:
|
36
|
+
path: /tmp/test-results
|
37
|
+
- store_artifacts:
|
38
|
+
path: /tmp/test-results
|
39
|
+
destination: test-results
|
40
|
+
|
41
|
+
#-------------------------------------------------------------------------------
|
42
|
+
|
43
|
+
jobs:
|
44
|
+
ruby-2.4:
|
45
|
+
<<: *base_job
|
46
|
+
docker:
|
47
|
+
- image: circleci/ruby:2.4
|
48
|
+
ruby-2.5:
|
49
|
+
<<: *base_job
|
50
|
+
docker:
|
51
|
+
- image: circleci/ruby:2.5
|
52
|
+
environment:
|
53
|
+
ENABLE_COVERAGE: 1
|
54
|
+
|
55
|
+
#-------------------------------------------------------------------------------
|
56
|
+
|
57
|
+
workflows:
|
58
|
+
version: 2
|
59
|
+
multiple-rubies:
|
60
|
+
jobs:
|
61
|
+
- ruby-2.5
|
62
|
+
- ruby-2.4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM ruby:2.5-alpine
|
2
|
+
|
3
|
+
RUN apk update && \
|
4
|
+
apk add git && \
|
5
|
+
mkdir -p /app/lib/jet_black
|
6
|
+
|
7
|
+
WORKDIR /app
|
8
|
+
|
9
|
+
COPY Gemfile* jet_black.gemspec /app/
|
10
|
+
COPY lib/jet_black/version.rb /app/lib/jet_black/version.rb
|
11
|
+
|
12
|
+
RUN bundle install --jobs=4 --retry=3
|
13
|
+
|
14
|
+
COPY . /app
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,22 +8,22 @@ with [RSpec] in mind. Features:
|
|
8
8
|
[RSpec]: http://rspec.info/
|
9
9
|
|
10
10
|
- Each session takes place within a unique temporary directory, outside the project
|
11
|
-
- Synchronously [run commands](#running-commands) then write assertions on
|
12
|
-
- `stdout` / `stderr` content
|
13
|
-
- exit status of the process
|
14
|
-
-
|
11
|
+
- Synchronously [run commands](#running-commands) then write assertions on:
|
12
|
+
- The `stdout` / `stderr` content
|
13
|
+
- The exit status of the process
|
14
|
+
- Manipulate files in the temporary directory:
|
15
15
|
- [Create files](#file-manipulation)
|
16
16
|
- [Create executable files](#file-manipulation)
|
17
17
|
- [Append content to files](#file-manipulation)
|
18
18
|
- [Copy fixture files](#copying-fixture-files) from your project
|
19
|
-
- Modify the environment without
|
19
|
+
- Modify the environment without changing the parent test process:
|
20
20
|
- [Override environment variables](#environment-variable-overrides)
|
21
21
|
- [Escape the current Bundler context](#clean-bundler-environment)
|
22
22
|
- [Adjust `$PATH`](#path-prefix) to include your executable / Subject Under Test
|
23
23
|
- [RSpec matchers](#rspec-matchers) (optional)
|
24
24
|
|
25
|
-
The temporary directory is discarded after each spec. This means you can write
|
26
|
-
|
25
|
+
The temporary directory is discarded after each spec. This means you can write &
|
26
|
+
modify files and run commands (like `git init`) without worrying about tidying
|
27
27
|
up after or impacting your actual project.
|
28
28
|
|
29
29
|
## Setup
|
@@ -48,6 +48,8 @@ require "jet_black/rspec"
|
|
48
48
|
Any specs you write in the `spec/black_box` folder will then have an inferred
|
49
49
|
`:black_box` meta type, and the matchers will be available in those examples.
|
50
50
|
|
51
|
+
#### Manual RSpec setup
|
52
|
+
|
51
53
|
Alternatively you can manually include the matchers:
|
52
54
|
|
53
55
|
```ruby
|
@@ -114,30 +116,30 @@ TXT
|
|
114
116
|
### Copying fixture files
|
115
117
|
|
116
118
|
It's ideal to create pertinent files inline within a spec, to provide context
|
117
|
-
for the reader, but sometimes
|
118
|
-
|
119
|
+
for the reader, but sometimes it's better to copy across a large or
|
120
|
+
non-human-readable file.
|
119
121
|
|
120
|
-
|
121
|
-
`spec/fixtures/black_box`. Then configure the fixture path in
|
122
|
-
`spec/support/jet_black.rb`:
|
122
|
+
1. Create a fixture directory in your project, such as `spec/fixtures/black_box`.
|
123
123
|
|
124
|
-
|
125
|
-
require "jet_black"
|
124
|
+
2. Configure the fixture path in `spec/support/jet_black.rb`:
|
126
125
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
```
|
126
|
+
```ruby
|
127
|
+
require "jet_black"
|
131
128
|
|
132
|
-
|
129
|
+
JetBlack.configure do |config|
|
130
|
+
config.fixture_directory = File.expand_path("../fixtures/black_box", __dir__)
|
131
|
+
end
|
132
|
+
```
|
133
133
|
|
134
|
-
|
135
|
-
session = JetBlack::Session.new
|
136
|
-
session.copy_fixture("src-config.json", "config.json")
|
134
|
+
3. Copy fixtures across into a session's temporary directory:
|
137
135
|
|
138
|
-
|
139
|
-
session
|
140
|
-
|
136
|
+
```ruby
|
137
|
+
session = JetBlack::Session.new
|
138
|
+
session.copy_fixture("src-config.json", "config.json")
|
139
|
+
|
140
|
+
# Destination subdirectories are created for you:
|
141
|
+
session.copy_fixture("src-config.json", "config/config.json")
|
142
|
+
```
|
141
143
|
|
142
144
|
### Environment variable overrides
|
143
145
|
|
@@ -148,6 +150,8 @@ result = subject.run("echo $FOO", env: { FOO: "bar" })
|
|
148
150
|
result.stdout # => "bar"
|
149
151
|
```
|
150
152
|
|
153
|
+
Provide a `nil` value to unset an environment variable.
|
154
|
+
|
151
155
|
### Clean Bundler environment
|
152
156
|
|
153
157
|
If your project's test suite is invoked with Bundler (e.g. `bundle exec rspec`)
|
@@ -179,7 +183,7 @@ Configure the `path_prefix` to the directory containing with your executable(s):
|
|
179
183
|
require "jet_black"
|
180
184
|
|
181
185
|
JetBlack.configure do |config|
|
182
|
-
config.path_prefix = File.
|
186
|
+
config.path_prefix = File.expand_path("../../bin", __dir__)
|
183
187
|
end
|
184
188
|
```
|
185
189
|
|
data/bin/docker_test
ADDED
data/bin/jet_black_bin_example
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JetBlack
|
4
|
+
class AnsiScrubber
|
5
|
+
ESCAPE_SEQUENCE = /
|
6
|
+
\x1B # ESC char - start of the sequence
|
7
|
+
(
|
8
|
+
[\x20-\x2F]*
|
9
|
+
[\x40-\x5A\x5C-\x7E]
|
10
|
+
|
|
11
|
+
\[ # Start CSI sequence
|
12
|
+
[\x30-\x3F]+ # CSI Parameter bytes
|
13
|
+
[\x20-\x2F]* # CSI Intermediate bytes
|
14
|
+
[\x40-\x7E] # CSI Finishing byte
|
15
|
+
)
|
16
|
+
/x
|
17
|
+
|
18
|
+
def self.call(string)
|
19
|
+
string.gsub(ESCAPE_SEQUENCE, "")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,11 +1,16 @@
|
|
1
|
+
require_relative "ansi_scrubber"
|
2
|
+
|
1
3
|
module JetBlack
|
2
4
|
class ExecutedCommand
|
3
|
-
attr_reader :raw_command, :
|
5
|
+
attr_reader :raw_command, :raw_stdout, :raw_stderr,
|
6
|
+
:stdout, :stderr, :exit_status
|
4
7
|
|
5
8
|
def initialize(raw_command:, stdout:, stderr:, exit_status:)
|
6
9
|
@raw_command = raw_command
|
7
|
-
@
|
8
|
-
@
|
10
|
+
@raw_stdout = stdout
|
11
|
+
@raw_stderr = stderr
|
12
|
+
@stdout = scrub(stdout)
|
13
|
+
@stderr = scrub(stderr)
|
9
14
|
@exit_status = exit_status.to_i
|
10
15
|
end
|
11
16
|
|
@@ -16,5 +21,11 @@ module JetBlack
|
|
16
21
|
def failure?
|
17
22
|
!success?
|
18
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def scrub(output_string)
|
28
|
+
AnsiScrubber.call(output_string.to_s.chomp)
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
data/lib/jet_black/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jet_black
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oli Peate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,15 +118,18 @@ files:
|
|
118
118
|
- ".gitignore"
|
119
119
|
- ".rspec"
|
120
120
|
- CHANGELOG.md
|
121
|
+
- Dockerfile
|
121
122
|
- Gemfile
|
122
123
|
- Gemfile.lock
|
123
124
|
- LICENSE.txt
|
124
125
|
- README.md
|
125
126
|
- Rakefile
|
127
|
+
- bin/docker_test
|
126
128
|
- bin/jet_black_bin_example
|
127
129
|
- bin/setup
|
128
130
|
- jet_black.gemspec
|
129
131
|
- lib/jet_black.rb
|
132
|
+
- lib/jet_black/ansi_scrubber.rb
|
130
133
|
- lib/jet_black/configuration.rb
|
131
134
|
- lib/jet_black/environment.rb
|
132
135
|
- lib/jet_black/errors.rb
|