rainbow 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/string_utils'
3
-
4
- module Rainbow
5
- RSpec.describe StringUtils do
6
- describe '.wrap_with_sgr' do
7
- subject { described_class.wrap_with_sgr(string, codes) }
8
-
9
- let(:string) { 'hello' }
10
- let(:codes) { [1] }
11
-
12
- it "doesn't mutate original string" do
13
- string.freeze
14
- expect(subject).to eq("\e[1mhello\e[0m")
15
- expect(string).to eq('hello')
16
- end
17
-
18
- context "when subclass of String class given" do
19
- class Stringgg < ::String; end
20
-
21
- let(:string) { Stringgg.new('hello') }
22
-
23
- it { should eq("\e[1mhello\e[0m") }
24
- end
25
-
26
- context "when no codes given" do
27
- let(:codes) { [] }
28
-
29
- it "doesn't wrap the given string with any sgr sequence" do
30
- expect(subject).to eq("hello")
31
- end
32
- end
33
-
34
- context "when single code given" do
35
- let(:codes) { [1] }
36
-
37
- it "wraps the given string with sgr sequence for given codes" do
38
- expect(subject).to eq("\e[1mhello\e[0m")
39
- end
40
- end
41
-
42
- context "when multiple codes given" do
43
- let(:codes) { [1, 2] }
44
-
45
- it "wraps the given string with sgr sequence for given codes" do
46
- expect(subject).to eq("\e[1;2mhello\e[0m")
47
- end
48
- end
49
-
50
- context "when wrapping an already wrapped string" do
51
- let(:string) { "\e[1;2mhello\e[0m" }
52
- let(:codes) { [3, 4] }
53
-
54
- it "wraps the given string with sgr sequence for given codes" do
55
- expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
56
- end
57
- end
58
- end
59
-
60
- describe '.uncolor' do
61
- subject { described_class.uncolor(string) }
62
-
63
- context "when string with ansi color escape is passed" do
64
- let(:string) do
65
- rainbow = Rainbow.new
66
- rainbow.enabled = true
67
- rainbow.wrap('hello').
68
- foreground(:red).
69
- bright.
70
- bold.
71
- italic.
72
- background('#ff8040').
73
- underline.
74
- color(:blue).
75
- blink.
76
- inverse.
77
- hide
78
- end
79
-
80
- it "removes ansi color codes" do
81
- expect(subject).to eq 'hello'
82
- end
83
- end
84
-
85
- context "when string with scroll down ansi escape is passed" do
86
- let(:string) { "\e[1Thello" }
87
-
88
- it "does not remove ansi scroll down escape" do
89
- expect(subject).to eq "\e[1Thello"
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/wrapper'
3
-
4
- module Rainbow
5
- RSpec.describe Wrapper do
6
- let(:wrapper) { described_class.new(enabled) }
7
-
8
- it "is enabled by default" do
9
- expect(described_class.new.enabled).to be(true)
10
- end
11
-
12
- describe '#wrap' do
13
- subject { wrapper.wrap(object) }
14
-
15
- let(:object) { Object.new }
16
-
17
- context "when wrapping is enabled" do
18
- let(:enabled) { true }
19
-
20
- it { should eq(object.to_s) }
21
- it { should be_kind_of(Rainbow::Presenter) }
22
- end
23
-
24
- context "when wrapping is disabled" do
25
- let(:enabled) { false }
26
-
27
- it { should eq(object.to_s) }
28
- it { should be_kind_of(Rainbow::NullPresenter) }
29
- end
30
- end
31
- end
32
- end