rainbow 3.0.0 → 3.1.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 +5 -5
- data/Changelog.md +10 -2
- data/README.markdown +3 -0
- data/lib/rainbow/color.rb +15 -8
- data/lib/rainbow/ext/string.rb +11 -1
- data/lib/rainbow/global.rb +2 -0
- data/lib/rainbow/null_presenter.rb +7 -0
- data/lib/rainbow/presenter.rb +16 -7
- data/lib/rainbow/refinement.rb +2 -0
- data/lib/rainbow/string_utils.rb +6 -5
- data/lib/rainbow/version.rb +3 -1
- data/lib/rainbow/wrapper.rb +2 -0
- data/lib/rainbow/x11_color_names.rb +2 -0
- data/lib/rainbow.rb +2 -0
- metadata +16 -44
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -20
- data/.rubocop_todo.yml +0 -29
- data/.travis.yml +0 -24
- data/Gemfile +0 -28
- data/Guardfile +0 -8
- data/Rakefile +0 -9
- data/appveyor.yml +0 -40
- data/rainbow.gemspec +0 -22
- data/spec/integration/instance_spec.rb +0 -33
- data/spec/integration/rainbow_spec.rb +0 -157
- data/spec/integration/refinement_spec.rb +0 -36
- data/spec/integration/string_spec.rb +0 -81
- data/spec/integration/uncolor_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -10
- data/spec/support/presenter_shared_examples.rb +0 -9
- data/spec/unit/color_spec.rb +0 -296
- data/spec/unit/null_presenter_spec.rb +0 -110
- data/spec/unit/presenter_spec.rb +0 -199
- data/spec/unit/string_utils_spec.rb +0 -94
- data/spec/unit/wrapper_spec.rb +0 -32
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow'
|
3
|
-
|
4
|
-
RSpec.describe 'Rainbow() wrapper' do
|
5
|
-
before do
|
6
|
-
Rainbow.enabled = true
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'allows foreground coloring by color number' do
|
10
|
-
result = Rainbow('hello').foreground(5)
|
11
|
-
expect(result).to eq("\e[35mhello\e[0m")
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'allows foreground coloring by color name' do
|
15
|
-
result = Rainbow('hello').foreground(:red)
|
16
|
-
expect(result).to eq("\e[31mhello\e[0m")
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'allows foreground coloring directly by ANSI method name' do
|
20
|
-
result = Rainbow('hello').red
|
21
|
-
expect(result).to eq("\e[31mhello\e[0m")
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows foreground coloring directly by X11 method name' do
|
25
|
-
result = Rainbow('hello').midnightblue
|
26
|
-
expect(result).to eq("\e[38;5;18mhello\e[0m")
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'allows foreground coloring by ANSI color name (color alias)' do
|
30
|
-
result = Rainbow('hello').color(:red)
|
31
|
-
expect(result).to eq("\e[31mhello\e[0m")
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'allows foreground coloring by color name (colour alias)' do
|
35
|
-
result = Rainbow('hello').colour(:red)
|
36
|
-
expect(result).to eq("\e[31mhello\e[0m")
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'allows foreground coloring by X11 color name' do
|
40
|
-
result = Rainbow('hello').foreground(:midnightblue)
|
41
|
-
expect(result).to eq("\e[38;5;18mhello\e[0m")
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'allows foreground coloring by color rgb' do
|
45
|
-
result = Rainbow('hello').foreground(255, 128, 64)
|
46
|
-
expect(result).to eq("\e[38;5;215mhello\e[0m")
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'allows foreground coloring by color rgb (hex string)' do
|
50
|
-
result = Rainbow('hello').foreground('ff8040')
|
51
|
-
expect(result).to eq("\e[38;5;215mhello\e[0m")
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'allows background coloring by color number' do
|
55
|
-
result = Rainbow('hello').background(3)
|
56
|
-
expect(result).to eq("\e[43mhello\e[0m")
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'allows background coloring by ANSI color name' do
|
60
|
-
result = Rainbow('hello').background(:green)
|
61
|
-
expect(result).to eq("\e[42mhello\e[0m")
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'allows background coloring by X11 color name' do
|
65
|
-
result = Rainbow('hello').background(:midnightblue)
|
66
|
-
expect(result).to eq("\e[48;5;18mhello\e[0m")
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'allows background coloring by color rgb' do
|
70
|
-
result = Rainbow('hello').background(255, 128, 64)
|
71
|
-
expect(result).to eq("\e[48;5;215mhello\e[0m")
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'allows making text bright' do
|
75
|
-
result = Rainbow('hello').bright
|
76
|
-
expect(result).to eq("\e[1mhello\e[0m")
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'allows making text faint' do
|
80
|
-
result = Rainbow('hello').faint
|
81
|
-
expect(result).to eq("\e[2mhello\e[0m")
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'allows making text italic' do
|
85
|
-
result = Rainbow('hello').italic
|
86
|
-
expect(result).to eq("\e[3mhello\e[0m")
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'allows making text underlined' do
|
90
|
-
result = Rainbow('hello').underline
|
91
|
-
expect(result).to eq("\e[4mhello\e[0m")
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'allows making text blinking' do
|
95
|
-
result = Rainbow('hello').blink
|
96
|
-
expect(result).to eq("\e[5mhello\e[0m")
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'allows making text inversed' do
|
100
|
-
result = Rainbow('hello').inverse
|
101
|
-
expect(result).to eq("\e[7mhello\e[0m")
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'allows making text hidden' do
|
105
|
-
result = Rainbow('hello').hide
|
106
|
-
expect(result).to eq("\e[8mhello\e[0m")
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'allows resetting all the attributes' do
|
110
|
-
result = Rainbow('hello').reset
|
111
|
-
expect(result).to eq("\e[0mhello\e[0m")
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'allows chaining' do
|
115
|
-
result = Rainbow('hello')
|
116
|
-
.foreground(:red)
|
117
|
-
.bright
|
118
|
-
.bold
|
119
|
-
.faint
|
120
|
-
.dark
|
121
|
-
.italic
|
122
|
-
.background('#ff8040')
|
123
|
-
.underline
|
124
|
-
.color(:blue)
|
125
|
-
.blink
|
126
|
-
.inverse
|
127
|
-
.hide
|
128
|
-
|
129
|
-
expect(result).to eq(
|
130
|
-
"\e[31m\e[1m\e[1m\e[2m\e[2m\e[3m\e[48;5;215m\e[4m\e[34m\e[5m\e[7m\e[8mhello\e[0m"
|
131
|
-
)
|
132
|
-
end
|
133
|
-
|
134
|
-
context "when Rainbow is disabled" do
|
135
|
-
before do
|
136
|
-
Rainbow.enabled = false
|
137
|
-
end
|
138
|
-
|
139
|
-
it "allows chaining but doesn't wrap with escape codes" do
|
140
|
-
result = Rainbow('hello')
|
141
|
-
.foreground(:red)
|
142
|
-
.bright
|
143
|
-
.bold
|
144
|
-
.faint
|
145
|
-
.dark
|
146
|
-
.italic
|
147
|
-
.background('#ff8040')
|
148
|
-
.underline
|
149
|
-
.color(:blue)
|
150
|
-
.blink
|
151
|
-
.inverse
|
152
|
-
.hide
|
153
|
-
|
154
|
-
expect(result).to eq('hello')
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow'
|
3
|
-
|
4
|
-
RSpec.describe 'Rainbow refinement' do
|
5
|
-
before do
|
6
|
-
require 'rainbow/refinement'
|
7
|
-
|
8
|
-
class ScopeNotIncluded
|
9
|
-
def self.red_hello
|
10
|
-
'hello'.red
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class ScopeIncluded
|
15
|
-
using Rainbow
|
16
|
-
def self.red_hello
|
17
|
-
'hello'.red
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'is not active by default' do
|
23
|
-
expect do
|
24
|
-
ScopeNotIncluded.red_hello
|
25
|
-
end.to raise_error(NoMethodError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'is available when used' do
|
29
|
-
expect(ScopeIncluded.red_hello).to eq(Rainbow('hello').red)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'respects disabled state' do
|
33
|
-
Rainbow.enabled = false
|
34
|
-
expect(ScopeIncluded.red_hello).to eq('hello')
|
35
|
-
end
|
36
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow/ext/string'
|
3
|
-
|
4
|
-
RSpec.describe 'String mixin' do
|
5
|
-
before do
|
6
|
-
Rainbow.enabled = true
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'proxies foreground to Rainbow().foreground' do
|
10
|
-
expect('hello'.foreground(:red)).to eq(Rainbow('hello').foreground(:red))
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'proxies color to Rainbow().color' do
|
14
|
-
expect('hello'.color(:red)).to eq(Rainbow('hello').color(:red))
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'proxies x11 color to Rainbow().color' do
|
18
|
-
expect('hello'.color(:midnightblue)).to eq(Rainbow('hello').color(:midnightblue))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'proxies colour to Rainbow().colour' do
|
22
|
-
expect('hello'.colour(:red)).to eq(Rainbow('hello').colour(:red))
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'proxies background to Rainbow().background' do
|
26
|
-
expect('hello'.background(:red)).to eq(Rainbow('hello').background(:red))
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'proxies bright to Rainbow().bright' do
|
30
|
-
expect('hello'.bright).to eq(Rainbow('hello').bright)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'proxies faint to Rainbow().faint' do
|
34
|
-
expect('hello'.faint).to eq(Rainbow('hello').faint)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'proxies italic to Rainbow().italic' do
|
38
|
-
expect('hello'.italic).to eq(Rainbow('hello').italic)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'proxies underline to Rainbow().underline' do
|
42
|
-
expect('hello'.underline).to eq(Rainbow('hello').underline)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'proxies blink to Rainbow().blink' do
|
46
|
-
expect('hello'.blink).to eq(Rainbow('hello').blink)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'proxies inverse to Rainbow().inverse' do
|
50
|
-
expect('hello'.inverse).to eq(Rainbow('hello').inverse)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'proxies hide to Rainbow().hide' do
|
54
|
-
expect('hello'.hide).to eq(Rainbow('hello').hide)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'proxies reset to Rainbow().reset' do
|
58
|
-
expect('hello'.reset).to eq(Rainbow('hello').reset)
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when Rainbow is disabled" do
|
62
|
-
before do
|
63
|
-
Rainbow.enabled = false
|
64
|
-
end
|
65
|
-
|
66
|
-
it "allows chaining but doesn't wrap with escape codes" do
|
67
|
-
result = 'hello'
|
68
|
-
.foreground(:red)
|
69
|
-
.bright
|
70
|
-
.italic
|
71
|
-
.background('#ff8040')
|
72
|
-
.underline
|
73
|
-
.color(:blue)
|
74
|
-
.blink
|
75
|
-
.inverse
|
76
|
-
.hide
|
77
|
-
|
78
|
-
expect(result).to eq('hello')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow'
|
3
|
-
|
4
|
-
RSpec.describe 'uncolor method' do
|
5
|
-
|
6
|
-
it 'strips ansi color escape code' do
|
7
|
-
expect(Rainbow.uncolor("\e[35mhello\e[0mm")).to eq 'hellom'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'does not strip scroll down escape code' do
|
11
|
-
expect(Rainbow.uncolor("\e[1Thello")).to eq "\e[1Thello"
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
|
2
|
-
require 'coveralls'
|
3
|
-
Coveralls.wear!
|
4
|
-
end
|
5
|
-
|
6
|
-
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file }
|
7
|
-
|
8
|
-
RSpec.configure do |config|
|
9
|
-
config.disable_monkey_patching!
|
10
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
RSpec.shared_examples_for "presenter with shortcut color methods" do
|
2
|
-
%i[black red green yellow blue magenta cyan white aqua].each do |name|
|
3
|
-
describe "##{name}" do
|
4
|
-
subject { presenter.public_send(name) }
|
5
|
-
|
6
|
-
it { should eq(presenter.color(name)) }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
data/spec/unit/color_spec.rb
DELETED
@@ -1,296 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow/color'
|
3
|
-
|
4
|
-
module Rainbow
|
5
|
-
RSpec.describe Color do
|
6
|
-
describe '.build' do
|
7
|
-
subject { described_class.build(ground, values) }
|
8
|
-
|
9
|
-
let(:ground) { :foreground }
|
10
|
-
|
11
|
-
context "when single fixnum given" do
|
12
|
-
let(:values) { [1] }
|
13
|
-
|
14
|
-
it { should be_instance_of(Color::Indexed) }
|
15
|
-
|
16
|
-
specify { expect(subject.ground).to eq(ground) }
|
17
|
-
specify { expect(subject.num).to eq(1) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when single ansi symbol given" do
|
21
|
-
let(:values) { [:red] }
|
22
|
-
|
23
|
-
it { should be_instance_of(Color::Named) }
|
24
|
-
|
25
|
-
specify { expect(subject.ground).to eq(ground) }
|
26
|
-
specify { expect(subject.num).to eq(1) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when single x11 symbol given" do
|
30
|
-
let(:values) { [:midnightblue] }
|
31
|
-
|
32
|
-
it { should be_instance_of(Color::X11Named) }
|
33
|
-
|
34
|
-
specify { expect(subject.ground).to eq(ground) }
|
35
|
-
specify { expect(subject.r).to eq(25) }
|
36
|
-
specify { expect(subject.g).to eq(25) }
|
37
|
-
specify { expect(subject.b).to eq(112) }
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when single string given" do
|
41
|
-
let(:values) { ['#deadcc'] }
|
42
|
-
|
43
|
-
it { should be_instance_of(Color::RGB) }
|
44
|
-
|
45
|
-
specify { expect(subject.ground).to eq(ground) }
|
46
|
-
specify { expect(subject.r).to eq(222) }
|
47
|
-
specify { expect(subject.g).to eq(173) }
|
48
|
-
specify { expect(subject.b).to eq(204) }
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when 2 elements" do
|
52
|
-
let(:values) { [1, 2] }
|
53
|
-
|
54
|
-
it 'raises ArgumentError' do
|
55
|
-
expect { subject }.to raise_error(ArgumentError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when 3 elements given" do
|
60
|
-
let(:values) { [1, 2, 3] }
|
61
|
-
|
62
|
-
it { should be_instance_of(Color::RGB) }
|
63
|
-
|
64
|
-
specify { expect(subject.ground).to eq(ground) }
|
65
|
-
specify { expect(subject.r).to eq(1) }
|
66
|
-
specify { expect(subject.g).to eq(2) }
|
67
|
-
specify { expect(subject.b).to eq(3) }
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when 4 elements" do
|
71
|
-
let(:values) { [1, 2, 3, 4] }
|
72
|
-
|
73
|
-
it 'raises ArgumentError' do
|
74
|
-
expect { subject }.to raise_error(ArgumentError)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
RSpec.describe Color::Indexed do
|
81
|
-
let(:color) { described_class.new(ground, 5) }
|
82
|
-
|
83
|
-
describe '#codes' do
|
84
|
-
subject { color.codes }
|
85
|
-
|
86
|
-
context "when ground is :foreground" do
|
87
|
-
let(:ground) { :foreground }
|
88
|
-
|
89
|
-
it { should eq([35]) }
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when ground is :background" do
|
93
|
-
let(:ground) { :background }
|
94
|
-
|
95
|
-
it { should eq([45]) }
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
RSpec.describe Color::Named do
|
101
|
-
let(:color) { described_class.new(ground, name) }
|
102
|
-
|
103
|
-
describe '#codes' do
|
104
|
-
subject { color.codes }
|
105
|
-
|
106
|
-
context "when ground is :foreground" do
|
107
|
-
let(:ground) { :foreground }
|
108
|
-
|
109
|
-
context "and name is :black" do
|
110
|
-
let(:name) { :black }
|
111
|
-
|
112
|
-
it { should eq([30]) }
|
113
|
-
end
|
114
|
-
|
115
|
-
context "and name is :red" do
|
116
|
-
let(:name) { :red }
|
117
|
-
|
118
|
-
it { should eq([31]) }
|
119
|
-
end
|
120
|
-
|
121
|
-
context "and name is :green" do
|
122
|
-
let(:name) { :green }
|
123
|
-
|
124
|
-
it { should eq([32]) }
|
125
|
-
end
|
126
|
-
|
127
|
-
context "and name is :yellow" do
|
128
|
-
let(:name) { :yellow }
|
129
|
-
|
130
|
-
it { should eq([33]) }
|
131
|
-
end
|
132
|
-
|
133
|
-
context "and name is :blue" do
|
134
|
-
let(:name) { :blue }
|
135
|
-
|
136
|
-
it { should eq([34]) }
|
137
|
-
end
|
138
|
-
|
139
|
-
context "and name is :magenta" do
|
140
|
-
let(:name) { :magenta }
|
141
|
-
|
142
|
-
it { should eq([35]) }
|
143
|
-
end
|
144
|
-
|
145
|
-
context "and name is :cyan" do
|
146
|
-
let(:name) { :cyan }
|
147
|
-
|
148
|
-
it { should eq([36]) }
|
149
|
-
end
|
150
|
-
|
151
|
-
context "and name is :white" do
|
152
|
-
let(:name) { :white }
|
153
|
-
|
154
|
-
it { should eq([37]) }
|
155
|
-
end
|
156
|
-
|
157
|
-
context "and name is invalid" do
|
158
|
-
let(:name) { :foo }
|
159
|
-
|
160
|
-
it 'raises ArgumentError' do
|
161
|
-
expect { subject }.to raise_error(ArgumentError)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "when ground is :background" do
|
167
|
-
let(:ground) { :background }
|
168
|
-
|
169
|
-
context "and name is :black" do
|
170
|
-
let(:name) { :black }
|
171
|
-
|
172
|
-
it { should eq([40]) }
|
173
|
-
end
|
174
|
-
|
175
|
-
context "and name is :red" do
|
176
|
-
let(:name) { :red }
|
177
|
-
|
178
|
-
it { should eq([41]) }
|
179
|
-
end
|
180
|
-
|
181
|
-
context "and name is :green" do
|
182
|
-
let(:name) { :green }
|
183
|
-
|
184
|
-
it { should eq([42]) }
|
185
|
-
end
|
186
|
-
|
187
|
-
context "and name is :yellow" do
|
188
|
-
let(:name) { :yellow }
|
189
|
-
|
190
|
-
it { should eq([43]) }
|
191
|
-
end
|
192
|
-
|
193
|
-
context "and name is :blue" do
|
194
|
-
let(:name) { :blue }
|
195
|
-
|
196
|
-
it { should eq([44]) }
|
197
|
-
end
|
198
|
-
|
199
|
-
context "and name is :magenta" do
|
200
|
-
let(:name) { :magenta }
|
201
|
-
|
202
|
-
it { should eq([45]) }
|
203
|
-
end
|
204
|
-
|
205
|
-
context "and name is :cyan" do
|
206
|
-
let(:name) { :cyan }
|
207
|
-
|
208
|
-
it { should eq([46]) }
|
209
|
-
end
|
210
|
-
|
211
|
-
context "and name is :white" do
|
212
|
-
let(:name) { :white }
|
213
|
-
|
214
|
-
it { should eq([47]) }
|
215
|
-
end
|
216
|
-
|
217
|
-
context "and name is invalid" do
|
218
|
-
let(:name) { :foo }
|
219
|
-
|
220
|
-
it 'raises ArgumentError' do
|
221
|
-
expect { subject }.to raise_error(ArgumentError)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
RSpec.describe Color::RGB do
|
229
|
-
let(:color) { described_class.new(ground, r, g, b) }
|
230
|
-
|
231
|
-
describe '#codes' do
|
232
|
-
subject { color.codes }
|
233
|
-
|
234
|
-
let(:ground) { :foreground }
|
235
|
-
let(:r) { 0 }
|
236
|
-
let(:g) { 128 }
|
237
|
-
let(:b) { 255 }
|
238
|
-
|
239
|
-
context "when ground is :foreground" do
|
240
|
-
let(:ground) { :foreground }
|
241
|
-
|
242
|
-
it { should eq([38, 5, 39]) }
|
243
|
-
end
|
244
|
-
|
245
|
-
context "when ground is :background" do
|
246
|
-
let(:ground) { :background }
|
247
|
-
|
248
|
-
it { should eq([48, 5, 39]) }
|
249
|
-
end
|
250
|
-
|
251
|
-
context "when a component is lower than 0" do
|
252
|
-
let(:r) { -1 }
|
253
|
-
|
254
|
-
it 'raises ArgumentError' do
|
255
|
-
expect { subject }.to raise_error(ArgumentError)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
context "when a component is greater than 255" do
|
260
|
-
let(:b) { 256 }
|
261
|
-
|
262
|
-
it 'raises ArgumentError' do
|
263
|
-
expect { subject }.to raise_error(ArgumentError)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
RSpec.describe Color::X11Named do
|
270
|
-
let(:color) { described_class.new(ground, name) }
|
271
|
-
|
272
|
-
describe '#codes' do
|
273
|
-
subject { color.codes }
|
274
|
-
|
275
|
-
context "when ground is :foreground" do
|
276
|
-
let(:name) { :midnightblue }
|
277
|
-
let(:ground) { :foreground }
|
278
|
-
it { should eq([38, 5, 18]) }
|
279
|
-
end
|
280
|
-
|
281
|
-
context "when ground is :background" do
|
282
|
-
let(:name) { :midnightblue }
|
283
|
-
let(:ground) { :background }
|
284
|
-
it { should eq([48, 5, 18]) }
|
285
|
-
end
|
286
|
-
|
287
|
-
context "when name is invalid" do
|
288
|
-
let(:name) { :foo }
|
289
|
-
let(:ground) { :background }
|
290
|
-
it 'raises ArgumentError' do
|
291
|
-
expect { subject }.to raise_error(ArgumentError)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|