pastel 0.7.3 → 0.7.4
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/CHANGELOG.md +21 -15
- data/README.md +1 -1
- data/lib/pastel/color_parser.rb +2 -0
- data/lib/pastel/version.rb +1 -1
- metadata +17 -76
- data/Rakefile +0 -8
- data/examples/palette.rb +0 -14
- data/pastel.gemspec +0 -37
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/alias_color_spec.rb +0 -24
- data/spec/unit/alias_importer_spec.rb +0 -29
- data/spec/unit/color/alias_color_spec.rb +0 -40
- data/spec/unit/color/code_spec.rb +0 -24
- data/spec/unit/color/colored_spec.rb +0 -15
- data/spec/unit/color/decorate_spec.rb +0 -79
- data/spec/unit/color/equal_spec.rb +0 -22
- data/spec/unit/color/lookup_spec.rb +0 -17
- data/spec/unit/color/new_spec.rb +0 -10
- data/spec/unit/color/strip_spec.rb +0 -56
- data/spec/unit/color/styles_spec.rb +0 -10
- data/spec/unit/color/valid_spec.rb +0 -19
- data/spec/unit/color_parser_spec.rb +0 -67
- data/spec/unit/decorate_dsl_spec.rb +0 -98
- data/spec/unit/decorator_chain_spec.rb +0 -47
- data/spec/unit/delegator_spec.rb +0 -38
- data/spec/unit/detach_spec.rb +0 -48
- data/spec/unit/new_spec.rb +0 -63
- data/spec/unit/respond_to_spec.rb +0 -17
- data/spec/unit/undecorate_spec.rb +0 -12
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27ae640e6ef241eef25aa65ca531e0bf2b77242c3575c217a50c6679146ca7a
|
4
|
+
data.tar.gz: 87d9af402543b3094c16c233aecaaeea8bf9e418bf1b5b3f04d09998e576c69c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1b38a5b8437adf408d6308b96389a846a81e1a13e34446db4b75ce06b37f54f08d05706e8a2505916a29d8e6ee025ca58528676ad978eaee30bd3af0a0eee04
|
7
|
+
data.tar.gz: b43aad885a8d33ff9e9f2ec5abcfbee59dfef0fce1f62c54628190e8196881ca7bbcad76a2af99fdb5d16a02cb161f1045da5763db6825c1f53a8c152bc8e663
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.7.4] - 2020-05-08
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
* Fix ColorParser#undecorate to require direct dependency by Nick Pezza(@npezza93)
|
7
|
+
|
3
8
|
## [v0.7.3] - 2019-06-16
|
4
9
|
|
5
10
|
### Changed
|
@@ -117,18 +122,19 @@
|
|
117
122
|
* Change gemspec to include equatable as dependency
|
118
123
|
* Change Delegator to stop creating instances and improve performance
|
119
124
|
|
120
|
-
[v0.7.
|
121
|
-
[v0.7.
|
122
|
-
[v0.7.
|
123
|
-
[v0.7.
|
124
|
-
[v0.
|
125
|
-
[v0.6.
|
126
|
-
[v0.
|
127
|
-
[v0.5.
|
128
|
-
[v0.5.
|
129
|
-
[v0.5.
|
130
|
-
[v0.
|
131
|
-
[v0.
|
132
|
-
[v0.
|
133
|
-
[v0.2.
|
134
|
-
[v0.
|
125
|
+
[v0.7.4]: https://github.com/piotrmurach/pastel/compare/v0.7.3...v0.7.4
|
126
|
+
[v0.7.3]: https://github.com/piotrmurach/pastel/compare/v0.7.2...v0.7.3
|
127
|
+
[v0.7.2]: https://github.com/piotrmurach/pastel/compare/v0.7.1...v0.7.2
|
128
|
+
[v0.7.1]: https://github.com/piotrmurach/pastel/compare/v0.7.0...v0.7.1
|
129
|
+
[v0.7.0]: https://github.com/piotrmurach/pastel/compare/v0.6.1...v0.7.0
|
130
|
+
[v0.6.1]: https://github.com/piotrmurach/pastel/compare/v0.6.0...v0.6.1
|
131
|
+
[v0.6.0]: https://github.com/piotrmurach/pastel/compare/v0.5.3...v0.6.0
|
132
|
+
[v0.5.3]: https://github.com/piotrmurach/pastel/compare/v0.5.2...v0.5.3
|
133
|
+
[v0.5.2]: https://github.com/piotrmurach/pastel/compare/v0.5.1...v0.5.2
|
134
|
+
[v0.5.1]: https://github.com/piotrmurach/pastel/compare/v0.5.0...v0.5.1
|
135
|
+
[v0.5.0]: https://github.com/piotrmurach/pastel/compare/v0.4.0...v0.5.0
|
136
|
+
[v0.4.0]: https://github.com/piotrmurach/pastel/compare/v0.3.0...v0.4.0
|
137
|
+
[v0.3.0]: https://github.com/piotrmurach/pastel/compare/v0.2.1...v0.3.0
|
138
|
+
[v0.2.1]: https://github.com/piotrmurach/pastel/compare/v0.2.0...v0.2.1
|
139
|
+
[v0.2.0]: https://github.com/piotrmurach/pastel/compare/v0.1.0...v0.2.0
|
140
|
+
[v0.1.0]: https://github.com/piotrmurach/pastel/compare/v0.1.0
|
data/README.md
CHANGED
data/lib/pastel/color_parser.rb
CHANGED
data/lib/pastel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equatable
|
@@ -39,59 +39,46 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.1'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.1'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
61
|
+
version: '3.0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
68
|
+
version: '3.0'
|
83
69
|
description: Terminal strings styling with intuitive and clean API.
|
84
70
|
email:
|
85
|
-
-
|
71
|
+
- piotr@piotrmurach.com
|
86
72
|
executables: []
|
87
73
|
extensions: []
|
88
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- CHANGELOG.md
|
77
|
+
- LICENSE.txt
|
89
78
|
files:
|
90
79
|
- CHANGELOG.md
|
91
80
|
- LICENSE.txt
|
92
81
|
- README.md
|
93
|
-
- Rakefile
|
94
|
-
- examples/palette.rb
|
95
82
|
- lib/pastel.rb
|
96
83
|
- lib/pastel/alias_importer.rb
|
97
84
|
- lib/pastel/ansi.rb
|
@@ -102,32 +89,7 @@ files:
|
|
102
89
|
- lib/pastel/delegator.rb
|
103
90
|
- lib/pastel/detached.rb
|
104
91
|
- lib/pastel/version.rb
|
105
|
-
|
106
|
-
- spec/spec_helper.rb
|
107
|
-
- spec/unit/alias_color_spec.rb
|
108
|
-
- spec/unit/alias_importer_spec.rb
|
109
|
-
- spec/unit/color/alias_color_spec.rb
|
110
|
-
- spec/unit/color/code_spec.rb
|
111
|
-
- spec/unit/color/colored_spec.rb
|
112
|
-
- spec/unit/color/decorate_spec.rb
|
113
|
-
- spec/unit/color/equal_spec.rb
|
114
|
-
- spec/unit/color/lookup_spec.rb
|
115
|
-
- spec/unit/color/new_spec.rb
|
116
|
-
- spec/unit/color/strip_spec.rb
|
117
|
-
- spec/unit/color/styles_spec.rb
|
118
|
-
- spec/unit/color/valid_spec.rb
|
119
|
-
- spec/unit/color_parser_spec.rb
|
120
|
-
- spec/unit/decorate_dsl_spec.rb
|
121
|
-
- spec/unit/decorator_chain_spec.rb
|
122
|
-
- spec/unit/delegator_spec.rb
|
123
|
-
- spec/unit/detach_spec.rb
|
124
|
-
- spec/unit/new_spec.rb
|
125
|
-
- spec/unit/respond_to_spec.rb
|
126
|
-
- spec/unit/undecorate_spec.rb
|
127
|
-
- tasks/console.rake
|
128
|
-
- tasks/coverage.rake
|
129
|
-
- tasks/spec.rake
|
130
|
-
homepage: https://piotrmurach.github.io/tty/
|
92
|
+
homepage: https://ttytoolkit.org
|
131
93
|
licenses:
|
132
94
|
- MIT
|
133
95
|
metadata:
|
@@ -135,7 +97,7 @@ metadata:
|
|
135
97
|
bug_tracker_uri: https://github.com/piotrmurach/pastel/issues
|
136
98
|
changelog_uri: https://github.com/piotrmurach/pastel/blob/master/CHANGELOG.md
|
137
99
|
documentation_uri: https://www.rubydoc.info/gems/pastel
|
138
|
-
homepage_uri: https://
|
100
|
+
homepage_uri: https://ttytoolkit.org
|
139
101
|
source_code_uri: https://github.com/piotrmurach/pastel
|
140
102
|
post_install_message:
|
141
103
|
rdoc_options: []
|
@@ -152,29 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
114
|
- !ruby/object:Gem::Version
|
153
115
|
version: '0'
|
154
116
|
requirements: []
|
155
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.1.2
|
156
118
|
signing_key:
|
157
119
|
specification_version: 4
|
158
120
|
summary: Terminal strings styling with intuitive and clean API.
|
159
|
-
test_files:
|
160
|
-
- spec/spec_helper.rb
|
161
|
-
- spec/unit/alias_color_spec.rb
|
162
|
-
- spec/unit/alias_importer_spec.rb
|
163
|
-
- spec/unit/color/alias_color_spec.rb
|
164
|
-
- spec/unit/color/code_spec.rb
|
165
|
-
- spec/unit/color/colored_spec.rb
|
166
|
-
- spec/unit/color/decorate_spec.rb
|
167
|
-
- spec/unit/color/equal_spec.rb
|
168
|
-
- spec/unit/color/lookup_spec.rb
|
169
|
-
- spec/unit/color/new_spec.rb
|
170
|
-
- spec/unit/color/strip_spec.rb
|
171
|
-
- spec/unit/color/styles_spec.rb
|
172
|
-
- spec/unit/color/valid_spec.rb
|
173
|
-
- spec/unit/color_parser_spec.rb
|
174
|
-
- spec/unit/decorate_dsl_spec.rb
|
175
|
-
- spec/unit/decorator_chain_spec.rb
|
176
|
-
- spec/unit/delegator_spec.rb
|
177
|
-
- spec/unit/detach_spec.rb
|
178
|
-
- spec/unit/new_spec.rb
|
179
|
-
- spec/unit/respond_to_spec.rb
|
180
|
-
- spec/unit/undecorate_spec.rb
|
121
|
+
test_files: []
|
data/Rakefile
DELETED
data/examples/palette.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require_relative '../lib/pastel'
|
2
|
-
|
3
|
-
pastel = Pastel.new
|
4
|
-
|
5
|
-
puts pastel.bold('bold ') + ' ' + pastel.dim('dim ') + ' ' + pastel.italic('italic ') + ' ' + pastel.underline('underline') + ' ' + pastel.inverse('inverse ') + ' ' + pastel.strikethrough('strikethrough')
|
6
|
-
|
7
|
-
puts pastel.red('red ') + ' ' + pastel.green('green ') + ' ' + pastel.yellow('yellow ') + ' ' + pastel.blue('blue ') + ' ' + pastel.magenta('magenta ') + ' ' + pastel.cyan('cyan ') + ' ' + pastel.white('white')
|
8
|
-
|
9
|
-
puts pastel.bright_red('red ') + ' ' + pastel.bright_green('green ') + ' ' + pastel.bright_yellow('yellow ') + ' ' + pastel.bright_blue('blue ') + ' ' + pastel.bright_magenta('magenta ') + ' ' + pastel.bright_cyan('cyan ') + ' ' + pastel.bright_white('white')
|
10
|
-
|
11
|
-
|
12
|
-
puts pastel.on_red('on_red') + ' ' + pastel.on_green('on_green') + ' ' + pastel.on_yellow('on_yellow') + ' ' + pastel.on_blue('on_blue') + ' ' + pastel.on_magenta('on_magenta') + ' ' + pastel.on_cyan('on_cyan') + ' ' + pastel.on_white('on_white')
|
13
|
-
|
14
|
-
puts pastel.on_bright_red('on_red') + ' ' + pastel.on_bright_green('on_green') + ' ' + pastel.on_bright_yellow('on_yellow') + ' ' + pastel.on_bright_blue('on_blue') + ' ' + pastel.on_bright_magenta('on_magenta') + ' ' + pastel.on_bright_cyan('on_cyan') + ' ' + pastel.on_bright_white('on_white')
|
data/pastel.gemspec
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'pastel/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "pastel"
|
7
|
-
spec.version = Pastel::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
spec.summary = %q{Terminal strings styling with intuitive and clean API.}
|
11
|
-
spec.description = %q{Terminal strings styling with intuitive and clean API.}
|
12
|
-
spec.homepage = "https://piotrmurach.github.io/tty/"
|
13
|
-
spec.license = "MIT"
|
14
|
-
if spec.respond_to?(:metadata=)
|
15
|
-
spec.metadata = {
|
16
|
-
"allowed_push_host" => "https://rubygems.org",
|
17
|
-
"bug_tracker_uri" => "https://github.com/piotrmurach/pastel/issues",
|
18
|
-
"changelog_uri" => "https://github.com/piotrmurach/pastel/blob/master/CHANGELOG.md",
|
19
|
-
"documentation_uri" => "https://www.rubydoc.info/gems/pastel",
|
20
|
-
"homepage_uri" => spec.homepage,
|
21
|
-
"source_code_uri" => "https://github.com/piotrmurach/pastel"
|
22
|
-
}
|
23
|
-
end
|
24
|
-
spec.files = Dir['{lib,spec,examples}/**/*.rb']
|
25
|
-
spec.files += Dir['tasks/*', 'pastel.gemspec']
|
26
|
-
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
27
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
28
|
-
spec.test_files = spec.files.grep(%r{^spec/})
|
29
|
-
spec.require_paths = ["lib"]
|
30
|
-
|
31
|
-
spec.add_dependency 'equatable', '~> 0.6'
|
32
|
-
spec.add_dependency 'tty-color', '~> 0.5'
|
33
|
-
|
34
|
-
spec.add_development_dependency 'bundler', '>= 1.5.0'
|
35
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
36
|
-
spec.add_development_dependency 'rake'
|
37
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'pastel'
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.expect_with :rspec do |expectations|
|
22
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
-
end
|
24
|
-
|
25
|
-
config.mock_with :rspec do |mocks|
|
26
|
-
mocks.verify_partial_doubles = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
30
|
-
config.disable_monkey_patching!
|
31
|
-
|
32
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
33
|
-
# be too noisy due to issues in dependencies.
|
34
|
-
config.warnings = true
|
35
|
-
|
36
|
-
if config.files_to_run.one?
|
37
|
-
config.default_formatter = 'doc'
|
38
|
-
end
|
39
|
-
|
40
|
-
config.profile_examples = 2
|
41
|
-
|
42
|
-
config.order = :random
|
43
|
-
|
44
|
-
Kernel.srand config.seed
|
45
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, '#alias_color' do
|
4
|
-
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it "aliases color" do
|
8
|
-
pastel.alias_color(:funky, :red, :bold)
|
9
|
-
expect(pastel.funky('unicorn')).to eq("\e[31;1municorn\e[0m")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "aliases color and combines with regular ones" do
|
13
|
-
pastel.alias_color(:funky, :red, :bold)
|
14
|
-
expect(pastel.funky.on_green('unicorn')).to eq("\e[31;1;42municorn\e[0m")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "reads aliases from the environment" do
|
18
|
-
color_aliases = "funky=red"
|
19
|
-
allow(ENV).to receive(:[]).with('PASTEL_COLORS_ALIASES').
|
20
|
-
and_return(color_aliases)
|
21
|
-
described_class.new(enabled: true)
|
22
|
-
expect(pastel.valid?(:funky)).to eq(true)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::AliasImporter, '#import' do
|
4
|
-
let(:color) { spy(:color, alias_color: true) }
|
5
|
-
let(:output) { StringIO.new }
|
6
|
-
|
7
|
-
it "imports aliases from environment" do
|
8
|
-
color_aliases = "funky=red.bold,base=bright_yellow"
|
9
|
-
env = {'PASTEL_COLORS_ALIASES' => color_aliases}
|
10
|
-
importer = described_class.new(color, env)
|
11
|
-
|
12
|
-
importer.import
|
13
|
-
|
14
|
-
expect(color).to have_received(:alias_color).with(:funky, :red, :bold)
|
15
|
-
expect(color).to have_received(:alias_color).with(:base, :bright_yellow)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "fails to import incorrectly formatted colors" do
|
19
|
-
color_aliases = "funky red,base=bright_yellow"
|
20
|
-
env = {'PASTEL_COLORS_ALIASES' => color_aliases}
|
21
|
-
importer = described_class.new(color, env, output)
|
22
|
-
output.rewind
|
23
|
-
|
24
|
-
importer.import
|
25
|
-
|
26
|
-
expect(output.string).to eq("Bad color mapping `funky red`\n")
|
27
|
-
expect(color).to have_received(:alias_color).with(:base, :bright_yellow)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '.alias_color' do
|
4
|
-
|
5
|
-
subject(:color) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it 'aliases non existent color' do
|
8
|
-
expect {
|
9
|
-
color.alias_color(:funky, :unknown)
|
10
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'aliases color with invalid name' do
|
14
|
-
expect {
|
15
|
-
color.alias_color('some name', :red)
|
16
|
-
}.to raise_error(Pastel::InvalidAliasNameError, /Invalid alias name/)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'aliases standard color' do
|
20
|
-
expect {
|
21
|
-
color.alias_color(:red, :red)
|
22
|
-
}.to raise_error(Pastel::InvalidAliasNameError, /alias standard color/)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'aliases color :red to :funky' do
|
26
|
-
color.alias_color(:funky, :red, :bold)
|
27
|
-
expect(color.valid?(:funky)).to eq(true)
|
28
|
-
expect(color.code(:funky)).to eq([[31, 1]])
|
29
|
-
expect(color.lookup(:funky)).to eq("\e[31;1m")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has global aliases" do
|
33
|
-
color_foo = described_class.new(enabled: true)
|
34
|
-
color_bar = described_class.new(enabled: true)
|
35
|
-
color_foo.alias_color(:foo, :red)
|
36
|
-
color_bar.alias_color(:bar, :red)
|
37
|
-
expect(color_foo.valid?(:foo)).to eq(true)
|
38
|
-
expect(color_foo.valid?(:bar)).to eq(true)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '#code' do
|
4
|
-
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
5
|
-
|
6
|
-
subject(:color) { described_class.new(enabled: true) }
|
7
|
-
|
8
|
-
it 'finds single code' do
|
9
|
-
expect(color.code(:black)).to eq([30])
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'finds more than one code' do
|
13
|
-
expect(color.code(:black, :green)).to eq([30, 32])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "doesn't find code" do
|
17
|
-
expect { color.code(:unkown) }.to raise_error(ArgumentError)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "finds alias code" do
|
21
|
-
color.alias_color(:funky, :red, :bold)
|
22
|
-
expect(color.code(:funky)).to eq([color.code(:red) + color.code(:bold)])
|
23
|
-
end
|
24
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '#colored?' do
|
4
|
-
subject(:color) { described_class.new(enabled: true) }
|
5
|
-
|
6
|
-
it "checks if string has color codes" do
|
7
|
-
string = "foo\e[31mbar\e[0m"
|
8
|
-
expect(color.colored?(string)).to eq(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "checks that string doesn't contain color codes" do
|
12
|
-
string = "foo\nbar"
|
13
|
-
expect(color.colored?(string)).to eq(false)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '.decorate' do
|
4
|
-
let(:string) { 'string' }
|
5
|
-
|
6
|
-
subject(:color) { described_class.new(enabled: true) }
|
7
|
-
|
8
|
-
it "doesn't output styling when disabled" do
|
9
|
-
color = described_class.new(enabled: false)
|
10
|
-
expect(color.decorate('foo', :red)).to eq('foo')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "doesn't apply styling to empty string" do
|
14
|
-
expect(color.decorate('')).to eq('')
|
15
|
-
end
|
16
|
-
|
17
|
-
it "doesn't decorate without color" do
|
18
|
-
expect(color.decorate(string)).to eq(string)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'applies green text to string' do
|
22
|
-
expect(color.decorate(string, :green)).to eq("\e[32m#{string}\e[0m")
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'applies red text background to string' do
|
26
|
-
expect(color.decorate(string, :on_red)).to eq("\e[41m#{string}\e[0m")
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'applies style and color to string' do
|
30
|
-
expect(color.decorate(string, :bold, :green)).to eq("\e[1;32m#{string}\e[0m")
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'applies style, color and background to string' do
|
34
|
-
text = color.decorate(string, :bold, :green, :on_blue)
|
35
|
-
expect(text).to eq("\e[1;32;44m#{string}\e[0m")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "applies styles to nested text" do
|
39
|
-
decorated = color.decorate(string + color.decorate(string, :red) + string, :green)
|
40
|
-
expect(decorated).to eq("\e[32m#{string}\e[31m#{string}\e[0m\e[32m#{string}\e[0m")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "decorates multiline string as regular by default" do
|
44
|
-
string = "foo\nbar\nbaz"
|
45
|
-
expect(color.decorate(string, :red)).to eq("\e[31mfoo\nbar\nbaz\e[0m")
|
46
|
-
end
|
47
|
-
|
48
|
-
it "allows to decorate each line separately" do
|
49
|
-
string = "foo\nbar\nbaz"
|
50
|
-
color = described_class.new(enabled: true, eachline: "\n")
|
51
|
-
expect(color.decorate(string, :red)).to eq([
|
52
|
-
"\e[31mfoo\e[0m",
|
53
|
-
"\e[31mbar\e[0m",
|
54
|
-
"\e[31mbaz\e[0m"
|
55
|
-
].join("\n"))
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'errors for unknown color' do
|
59
|
-
expect {
|
60
|
-
color.decorate(string, :crimson)
|
61
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "doesn't decorate non-string instance" do
|
65
|
-
expect(color.decorate({}, :red)).to eq({})
|
66
|
-
end
|
67
|
-
|
68
|
-
it "doesn't decorate nil" do
|
69
|
-
expect(color.decorate(nil, :red)).to eq(nil)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "doesn't decorate zero length string" do
|
73
|
-
expect(color.decorate('', :red)).to eq('')
|
74
|
-
end
|
75
|
-
|
76
|
-
it "doesn't decorate non-zero length string" do
|
77
|
-
expect(color.decorate(' ', :red)).to eq("\e[31m \e[0m")
|
78
|
-
end
|
79
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '#==' do
|
4
|
-
it "is true with the same enabled and eachline attributes" do
|
5
|
-
expect(Pastel::Color.new(enabled: false, eachline: "\n")).
|
6
|
-
to eq(Pastel::Color.new(enabled: false, eachline: "\n"))
|
7
|
-
end
|
8
|
-
|
9
|
-
it "is false with different enabled attribute" do
|
10
|
-
expect(Pastel::Color.new(enabled: true, eachline: "\n")).
|
11
|
-
not_to eq(Pastel::Color.new(enabled: false, eachline: "\n"))
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is false with different eachline attribute" do
|
15
|
-
expect(Pastel::Color.new(enabled: false, eachline: "\n")).
|
16
|
-
not_to eq(Pastel::Color.new(enabled: false, eachline: "\r\n"))
|
17
|
-
end
|
18
|
-
|
19
|
-
it "is false with non-color" do
|
20
|
-
expect(Pastel::Color.new(enabled: true)).not_to eq(:other)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '#lookup' do
|
4
|
-
it "looksup colors" do
|
5
|
-
color = described_class.new(enabled: true)
|
6
|
-
expect(color.lookup(:red, :on_green, :bold)).to eq("\e[31;42;1m")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "caches color lookups" do
|
10
|
-
color = described_class.new(enabled: true)
|
11
|
-
allow(color).to receive(:code).and_return([31])
|
12
|
-
color.lookup(:red, :on_green)
|
13
|
-
color.lookup(:red, :on_green)
|
14
|
-
color.lookup(:red, :on_green)
|
15
|
-
expect(color).to have_received(:code).once
|
16
|
-
end
|
17
|
-
end
|
data/spec/unit/color/new_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '.strip' do
|
4
|
-
|
5
|
-
subject(:color) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it 'strips ansi color from string' do
|
8
|
-
string = "This is a \e[1m\e[34mbold blue text\e[0m"
|
9
|
-
expect(color.strip(string)).to eq('This is a bold blue text')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "strips partial ansi color" do
|
13
|
-
string = "foo\e[1mbar"
|
14
|
-
expect(color.strip(string)).to eq('foobar')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'preserves movement characters' do
|
18
|
-
# [176A - move cursor up n lines
|
19
|
-
expect(color.strip("foo\e[176Abar")).to eq("foo\e[176Abar")
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'strips reset/setfg/setbg/italics/strike/underline sequence' do
|
23
|
-
string = "\x1b[0;33;49;3;9;4mfoo\x1b[0m"
|
24
|
-
expect(color.strip(string)).to eq("foo")
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'strips octal in encapsulating brackets' do
|
28
|
-
string = "\[\033[01;32m\]u@h \[\033[01;34m\]W $ \[\033[00m\]"
|
29
|
-
expect(color.strip(string)).to eq('[]u@h []W $ []')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'strips octal codes without brackets' do
|
33
|
-
string = "\033[01;32mu@h \033[01;34mW $ \033[00m"
|
34
|
-
expect(color.strip(string)).to eq('u@h W $ ')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'strips octal with multiple colors' do
|
38
|
-
string = "\e[3;0;0;mfoo\e[8;50;0m"
|
39
|
-
expect(color.strip(string)).to eq('foo')
|
40
|
-
end
|
41
|
-
|
42
|
-
it "strips multiple colors delimited by :" do
|
43
|
-
string = "\e[31:44:4mfoo\e[0m"
|
44
|
-
expect(color.strip(string)).to eq('foo')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'strips control codes' do
|
48
|
-
string = "WARN. \x1b[1m&\x1b[0m ERR. \x1b[7m&\x1b[0m"
|
49
|
-
expect(color.strip(string)).to eq('WARN. & ERR. &')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'strips escape bytes' do
|
53
|
-
string = "This is a \e[1m\e[34mbold blue text\e[0m"
|
54
|
-
expect(color.strip(string)).to eq("This is a bold blue text")
|
55
|
-
end
|
56
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Color, '.valid?' do
|
4
|
-
it "detects valid colors" do
|
5
|
-
color = described_class.new
|
6
|
-
expect(color.valid?(:red, :on_green, :bold)).to eq(true)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "detects valid color aliases" do
|
10
|
-
color = described_class.new
|
11
|
-
color.alias_color(:funky, :red)
|
12
|
-
expect(color.valid?(:funky)).to eq(true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "detects invalid color" do
|
16
|
-
color = described_class.new
|
17
|
-
expect(color.valid?(:red, :unknown)).to eq(false)
|
18
|
-
end
|
19
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::ColorParser, '::parse' do
|
4
|
-
subject(:parser) { described_class }
|
5
|
-
|
6
|
-
it "parses string with no color" do
|
7
|
-
expect(parser.parse("foo")).to eq([{text: 'foo'}])
|
8
|
-
end
|
9
|
-
|
10
|
-
it "parses simple color" do
|
11
|
-
expect(parser.parse("\e[32mfoo\e[0m")).to eq([
|
12
|
-
{foreground: :green, text: 'foo'}
|
13
|
-
])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "parses simple color and style" do
|
17
|
-
expect(parser.parse("\e[32;1mfoo\e[0m")).to eq([
|
18
|
-
{foreground: :green, style: :bold, text: 'foo'}
|
19
|
-
])
|
20
|
-
end
|
21
|
-
|
22
|
-
it "parses chained colors in shorthand syntax" do
|
23
|
-
expect(parser.parse("\e[32;44mfoo\e[0m")).to eq([
|
24
|
-
{foreground: :green, background: :on_blue, text: 'foo'}
|
25
|
-
])
|
26
|
-
end
|
27
|
-
|
28
|
-
it "parses chained colors in regular syntax" do
|
29
|
-
expect(parser.parse("\e[32m\e[44mfoo\e[0m")).to eq([
|
30
|
-
{foreground: :green, background: :on_blue, text: 'foo'}
|
31
|
-
])
|
32
|
-
end
|
33
|
-
|
34
|
-
it "parses many colors" do
|
35
|
-
expect(parser.parse("\e[32mfoo\e[0m \e[31mbar\e[0m")).to eq([
|
36
|
-
{foreground: :green, text: 'foo'},
|
37
|
-
{text: ' '},
|
38
|
-
{foreground: :red, text: 'bar'}
|
39
|
-
])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "parses nested colors with one reset" do
|
43
|
-
expect(parser.parse("\e[32mfoo\e[31mbar\e[0m")).to eq([
|
44
|
-
{foreground: :green, text: 'foo'},
|
45
|
-
{foreground: :red, text: 'bar'}
|
46
|
-
])
|
47
|
-
end
|
48
|
-
|
49
|
-
it "parses nested colors with two resets" do
|
50
|
-
expect(parser.parse("\e[32mfoo\e[31mbar\e[0m\e[0m")).to eq([
|
51
|
-
{foreground: :green, text: 'foo'},
|
52
|
-
{foreground: :red, text: 'bar'}
|
53
|
-
])
|
54
|
-
end
|
55
|
-
|
56
|
-
it "parses unrest color" do
|
57
|
-
expect(parser.parse("\e[32mfoo")).to eq([
|
58
|
-
{foreground: :green, text: 'foo'}
|
59
|
-
])
|
60
|
-
end
|
61
|
-
|
62
|
-
it "parses malformed control sequence" do
|
63
|
-
expect(parser.parse("\eA foo bar ESC\e")).to eq([
|
64
|
-
{text: "\eA foo bar ESC\e"}
|
65
|
-
])
|
66
|
-
end
|
67
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, 'coloring dsl' do
|
4
|
-
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it "colors string" do
|
8
|
-
expect(pastel.red("unicorn")).to eq("\e[31municorn\e[0m")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "allows to specify variable number of arguments" do
|
12
|
-
expect(pastel.red("unicorn", "running")).to eq("\e[31municornrunning\e[0m")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "combines colored strings with regular ones" do
|
16
|
-
expect(pastel.red("Unicorns") + ' will rule ' + pastel.green('the World!')).
|
17
|
-
to eq("\e[31mUnicorns\e[0m will rule \e[32mthe World!\e[0m")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "composes two color strings " do
|
21
|
-
expect(pastel.red.on_green("unicorn")).to eq("\e[31;42municorn\e[0m")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "composes three color strings" do
|
25
|
-
expect(pastel.red.on_green.underline("unicorn")).
|
26
|
-
to eq("\e[31;42;4municorn\e[0m")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "combines colored composed strings with regular ones" do
|
30
|
-
expect(pastel.red.on_green("Unicorns") + ' will rule ' +
|
31
|
-
pastel.green.on_red('the World!')).
|
32
|
-
to eq("\e[31;42mUnicorns\e[0m will rule \e[32;41mthe World!\e[0m")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "allows one level nesting" do
|
36
|
-
expect(pastel.red("Unicorn" + pastel.blue("rule!"))).
|
37
|
-
to eq("\e[31mUnicorn\e[34mrule!\e[0m\e[0m")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to nest mixed styles" do
|
41
|
-
expect(pastel.red("Unicorn" + pastel.green.on_yellow.underline('running') + '!')).
|
42
|
-
to eq("\e[31mUnicorn\e[32;43;4mrunning\e[0m\e[31m!\e[0m")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "allows for deep nesting" do
|
46
|
-
expect(pastel.red('r' + pastel.green('g' + pastel.yellow('y') + 'g') + 'r')).
|
47
|
-
to eq("\e[31mr\e[32mg\e[33my\e[0m\e[32mg\e[0m\e[31mr\e[0m")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "allows for variable nested arguments" do
|
51
|
-
expect(pastel.red('r', pastel.green('g'), 'r')).
|
52
|
-
to eq("\e[31mr\e[32mg\e[0m\e[31mr\e[0m")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "nests color foreground & background" do
|
56
|
-
expect(pastel.on_red('foo', pastel.green('bar'), 'foo')).
|
57
|
-
to eq("\e[41mfoo\e[32mbar\e[0m\e[41mfoo\e[0m")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "allows to nest styles within block" do
|
61
|
-
string = pastel.red.on_green('Unicorns' +
|
62
|
-
pastel.green.on_red('will ', 'dominate' + pastel.yellow('the world!')))
|
63
|
-
|
64
|
-
expect(pastel.red.on_green('Unicorns') do
|
65
|
-
green.on_red('will ', 'dominate') do
|
66
|
-
yellow('the world!')
|
67
|
-
end
|
68
|
-
end).to eq(string)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "doesn't decorate nil" do
|
72
|
-
expect(pastel.red(nil)).to eq('')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "doesn't apply styles to empty string" do
|
76
|
-
expect(pastel.red('')).to eq('')
|
77
|
-
end
|
78
|
-
|
79
|
-
it "applies styles to empty with width more than 1" do
|
80
|
-
expect(pastel.red(' ')).to eq("\e[31m \e[0m")
|
81
|
-
end
|
82
|
-
|
83
|
-
it "applies color only once" do
|
84
|
-
expect(pastel.red.red.red("unicorn")).to eq(pastel.red("unicorn"))
|
85
|
-
end
|
86
|
-
|
87
|
-
it "raises error when chained with unrecognized color" do
|
88
|
-
expect {
|
89
|
-
pastel.unknown.on_red('unicorn')
|
90
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "raises error when doesn't recognize color" do
|
94
|
-
expect {
|
95
|
-
pastel.unknown('unicorn')
|
96
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
97
|
-
end
|
98
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::DecoratorChain do
|
4
|
-
it "is enumerable" do
|
5
|
-
expect(described_class.new).to be_a(Enumerable)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "is equatable" do
|
9
|
-
expect(described_class.new).to be_a(Equatable)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe ".each" do
|
13
|
-
it "yields each decorator" do
|
14
|
-
first = double('first')
|
15
|
-
second = double('second')
|
16
|
-
chain = described_class.new.add(first).add(second)
|
17
|
-
yielded = []
|
18
|
-
|
19
|
-
expect {
|
20
|
-
chain.each { |decorator| yielded << decorator }
|
21
|
-
}.to change { yielded }.from([]).to([first, second])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".==" do
|
26
|
-
it "is equivalent with the same decorator" do
|
27
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
28
|
-
to eq(described_class.new.add(:foo).add(:bar))
|
29
|
-
end
|
30
|
-
|
31
|
-
it "is not equivalent with different decorator" do
|
32
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
33
|
-
not_to eq(described_class.new.add(:foo).add(:baz))
|
34
|
-
end
|
35
|
-
|
36
|
-
it "is not equivalent to another type" do
|
37
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
38
|
-
not_to eq(:other)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe ".inspect" do
|
43
|
-
it "displays object information" do
|
44
|
-
expect(described_class.new.inspect).to match(/decorators=\[\]/)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/spec/unit/delegator_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel::Delegator do
|
4
|
-
|
5
|
-
it "returns delegator for color without argument" do
|
6
|
-
pastel = Pastel.new(enabled: true)
|
7
|
-
expect(pastel.red).to be_a(Pastel::Delegator)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe ".inspect" do
|
11
|
-
it "inspects delegator styles chain" do
|
12
|
-
chain = ['red', 'on_green']
|
13
|
-
delegator = described_class.new(:resolver, chain)
|
14
|
-
allow(delegator).to receive(:styles).and_return({red: 31, on_green: 42})
|
15
|
-
expect(delegator.inspect).to eq("#<Pastel @styles=[\"red\", \"on_green\"]>")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe ".respond_to_missing?" do
|
20
|
-
context 'for a method defined on' do
|
21
|
-
it "returns true" do
|
22
|
-
resolver = double(:resolver)
|
23
|
-
chain = double(:chain)
|
24
|
-
decorator = described_class.new(resolver, chain)
|
25
|
-
expect(decorator.method(:styles)).not_to be_nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "for an undefined method " do
|
30
|
-
it "returns false" do
|
31
|
-
resolver = double(:resolver, color: true)
|
32
|
-
chain = double(:chain)
|
33
|
-
decorator = described_class.new(resolver, chain)
|
34
|
-
expect { decorator.method(:unknown) }.to raise_error(NameError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/unit/detach_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, '.detach' do
|
4
|
-
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it "creates detached instance" do
|
8
|
-
error = pastel.red.bold.detach
|
9
|
-
expect(error).to be_a(Pastel::Detached)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "ensures instance is immutable" do
|
13
|
-
error = pastel.red.detach
|
14
|
-
expect(error.frozen?).to be(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "detaches colors combination" do
|
18
|
-
error = pastel.red.bold.detach
|
19
|
-
expect(error.call('unicorn')).to eq("\e[31;1municorn\e[0m")
|
20
|
-
expect(error.call('error')).to eq("\e[31;1merror\e[0m")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "allows array like access" do
|
24
|
-
error = pastel.red.bold.detach
|
25
|
-
expect(error['unicorn']).to eq("\e[31;1municorn\e[0m")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "allows alternative call invocation" do
|
29
|
-
error = pastel.red.bold.detach
|
30
|
-
expect(error.('unicorn')).to eq("\e[31;1municorn\e[0m")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "calls detached colors with no arguments" do
|
34
|
-
warning = pastel.yellow.detach
|
35
|
-
expect(warning.call('')).to eq('')
|
36
|
-
end
|
37
|
-
|
38
|
-
it "inspects detached colors" do
|
39
|
-
warning = pastel.yellow.bold.detach
|
40
|
-
expect(warning.inspect).to eq('#<Pastel::Detached styles=[:yellow, :bold]>')
|
41
|
-
end
|
42
|
-
|
43
|
-
it "accepts multiple strings" do
|
44
|
-
error = pastel.red.bold.detach
|
45
|
-
expect(error.call('Unicorns', ' run ', 'wild')).
|
46
|
-
to eq("\e[31;1mUnicorns run wild\e[0m")
|
47
|
-
end
|
48
|
-
end
|
data/spec/unit/new_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, '#new' do
|
4
|
-
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
6
|
-
|
7
|
-
it { is_expected.to respond_to(:lookup) }
|
8
|
-
|
9
|
-
it { is_expected.to respond_to(:decorate) }
|
10
|
-
|
11
|
-
it { is_expected.to respond_to(:undecorate) }
|
12
|
-
|
13
|
-
it { is_expected.to respond_to(:strip) }
|
14
|
-
|
15
|
-
describe '#valid?' do
|
16
|
-
it "when valid returns true" do
|
17
|
-
expect(pastel.valid?(:red)).to eq(true)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns false when invalid" do
|
21
|
-
expect(pastel.valid?(:unknown)).to eq(false)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#colored?' do
|
26
|
-
it "checks if string is colored" do
|
27
|
-
expect(pastel.colored?("\e[31mfoo\e[0m")).to eq(true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'options passed in' do
|
32
|
-
it 'defaults enabled to color detection' do
|
33
|
-
allow(TTY::Color).to receive(:color?).and_return(true)
|
34
|
-
allow(TTY::Color).to receive(:windows?).and_return(false)
|
35
|
-
|
36
|
-
pastel = described_class.new
|
37
|
-
|
38
|
-
expect(pastel.enabled?).to eq(true)
|
39
|
-
expect(TTY::Color).to have_received(:color?)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "defaults to enabled on Windows" do
|
43
|
-
allow(TTY::Color).to receive(:color?).and_return(false)
|
44
|
-
allow(TTY::Color).to receive(:windows?).and_return(true)
|
45
|
-
|
46
|
-
pastel = described_class.new
|
47
|
-
|
48
|
-
expect(pastel.enabled?).to eq(true)
|
49
|
-
expect(TTY::Color).to_not have_received(:color?)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "sets enabled option" do
|
53
|
-
pastel = described_class.new(enabled: false)
|
54
|
-
expect(pastel.enabled?).to eq(false)
|
55
|
-
expect(pastel.red('Unicorn', pastel.green('!'))).to eq('Unicorn!')
|
56
|
-
end
|
57
|
-
|
58
|
-
it "sets eachline option" do
|
59
|
-
pastel = described_class.new(enabled: true, eachline: "\n")
|
60
|
-
expect(pastel.red("foo\nbar")).to eq("\e[31mfoo\e[0m\n\e[31mbar\e[0m")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, '.respond_to?' do
|
4
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
5
|
-
|
6
|
-
it "responds correctly to color method" do
|
7
|
-
expect(pastel.respond_to?(:decorate)).to eq(true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "responds correctly to color property" do
|
11
|
-
expect(pastel.respond_to?(:red)).to eq(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "responds correctly to unkown method" do
|
15
|
-
expect(pastel.respond_to?(:unknown)).to eq(false)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Pastel, '#undecorate' do
|
4
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
5
|
-
|
6
|
-
it "undecorates string detecting color escape codes" do
|
7
|
-
string = pastel.red.on_green('foo')
|
8
|
-
expect(pastel.undecorate(string)).to eq([
|
9
|
-
{foreground: :red, background: :on_green, text: 'foo'}
|
10
|
-
])
|
11
|
-
end
|
12
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|