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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 492919b04c06523b9dca80a4d30939272ae1d435ea83c183f94cae6ab7d11501
4
- data.tar.gz: c5157a559982f91bfe2560a6283b96229dade980b35fd52f9e446c4e339772e5
3
+ metadata.gz: 3cb06cc77894ad09aa2a5c00da5226227b6416624ac7c02a0d0c558e457667c1
4
+ data.tar.gz: 494d96406354c2d46fd34ea105830ee54f2b84da23fe43167446d9ab41d3cad9
5
5
  SHA512:
6
- metadata.gz: d2e3877e059b410b276486990e042722d134abb2c9a4111183a9fcfdd3f902bcd742ff426003fb4c44966e4f0d70ba651709f3833f1cc44048fd3ccddee6e764
7
- data.tar.gz: ed0f71a6940b5cde28e0c61bcdcbcd76db183a0808a0d7d97d56ba476aab4f885954ab24386f2329c167972430a04d0591105273a93ee4e63a005647ad38df17
6
+ metadata.gz: b27d58676baaa1ef5d3513b0515398798aa137461e5eb649a8cd598e51bd24e344db543e67d68c2a12449e44808a775abc769fcc0adffd5e7bc0c0a22404f463
7
+ data.tar.gz: 99451118f6c55638e989f41c8ef83773c5f9e6fa86d281ae0087282e2ea6694788eed7637d47e02f9e431c4472782f10007cc4fcd1d6a9ccbf7720268075679a
@@ -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
- working_directory: ~/repo
4
+ #-------------------------------------------------------------------------------
10
5
 
11
- steps:
12
- - checkout
6
+ base_job: &base_job
7
+ working_directory: ~/repo
8
+ steps:
9
+ - checkout
13
10
 
14
- - restore_cache:
15
- keys:
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
- - run:
21
- name: install dependencies
22
- command: |
23
- bundle install --jobs=4 --retry=3 --path vendor/bundle
24
-
25
- - save_cache:
26
- paths:
27
- - ./vendor/bundle
28
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
29
-
30
- - run:
31
- name: run tests
32
- command: |
33
- mkdir /tmp/test-results
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
- # collect reports
39
- - store_test_results:
40
- path: /tmp/test-results
41
- - store_artifacts:
42
- path: /tmp/test-results
43
- destination: test-results
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
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .ruby-version
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.0
4
+
5
+ - Scrub ANSI escape sequences in stdout and stderr
6
+ - Allow environment variables to be unset
7
+
3
8
  ## v0.3.0
4
9
 
5
10
  - Allows `stdin` data to be provided when running commands
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jet_black (0.3.0)
4
+ jet_black (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 the:
12
- - `stdout` / `stderr` content
13
- - exit status of the process
14
- - Conveniently manipulate files in the temporary directory:
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 modifying the parent test process:
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
- & modify files and run commands (like `git init`) without worrying about tidying
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 a large or non-readable file is best copied
118
- across.
119
+ for the reader, but sometimes it's better to copy across a large or
120
+ non-human-readable file.
119
121
 
120
- First create a fixture directory in your project, such as
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
- ```ruby
125
- require "jet_black"
124
+ 2. Configure the fixture path in `spec/support/jet_black.rb`:
126
125
 
127
- JetBlack.configure do |config|
128
- config.fixture_directory = File.expand_path("../fixtures/black_box", __dir__)
129
- end
130
- ```
126
+ ```ruby
127
+ require "jet_black"
131
128
 
132
- Now you can copy fixtures across into a session's temporary directory:
129
+ JetBlack.configure do |config|
130
+ config.fixture_directory = File.expand_path("../fixtures/black_box", __dir__)
131
+ end
132
+ ```
133
133
 
134
- ```ruby
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
- # Destination subdirectories are created for you:
139
- session.copy_fixture("src-config.json", "config/config.json")
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.expand("../../bin", __dir__)
186
+ config.path_prefix = File.expand_path("../../bin", __dir__)
183
187
  end
184
188
  ```
185
189
 
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ set -euo pipefail
4
+
5
+ docker build -t odlp/jet_black .
6
+ docker run odlp/jet_black bundle exec rspec --tty
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env bash
1
+ #!/bin/sh
2
2
 
3
3
  echo "Hello from example bin"
@@ -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
@@ -14,7 +14,7 @@ module JetBlack
14
14
 
15
15
  def stringify_env(env)
16
16
  env.map do |key, value|
17
- [key.to_s, value.to_s]
17
+ [key.to_s, value&.to_s]
18
18
  end.to_h
19
19
  end
20
20
 
@@ -1,11 +1,16 @@
1
+ require_relative "ansi_scrubber"
2
+
1
3
  module JetBlack
2
4
  class ExecutedCommand
3
- attr_reader :raw_command, :stdout, :stderr, :exit_status
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
- @stdout = stdout.chomp
8
- @stderr = stderr.chomp
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
@@ -1,3 +1,3 @@
1
1
  module JetBlack
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.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-06 00:00:00.000000000 Z
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