pastel 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe Pastel, 'coloring dsl' do
4
+ subject(:pastel) { described_class.new(enabled: true) }
5
+
6
+ it "doesn't apply styles to empty string" do
7
+ expect(pastel.red('')).to eq('')
8
+ end
9
+
10
+ it "colors string" do
11
+ expect(pastel.red("unicorn")).to eq("\e[31municorn\e[0m")
12
+ end
13
+
14
+ it "allows to specify variable number of arguments" do
15
+ expect(pastel.red("unicorn", "running")).to eq("\e[31municornrunning\e[0m")
16
+ end
17
+
18
+ it "combines colored strings with regular ones" do
19
+ expect(pastel.red("Unicorns") + ' will rule ' + pastel.green('the World!')).
20
+ to eq("\e[31mUnicorns\e[0m will rule \e[32mthe World!\e[0m")
21
+ end
22
+
23
+ it "composes two color strings " do
24
+ expect(pastel.red.on_green("unicorn")).to eq("\e[31;42municorn\e[0m")
25
+ end
26
+
27
+ it "composes three color strings" do
28
+ expect(pastel.red.on_green.underline("unicorn")).
29
+ to eq("\e[31;42;4municorn\e[0m")
30
+ end
31
+
32
+ it "combines colored composed strings with regular ones" do
33
+ expect(pastel.red.on_green("Unicorns") + ' will rule ' +
34
+ pastel.green.on_red('the World!')).
35
+ to eq("\e[31;42mUnicorns\e[0m will rule \e[32;41mthe World!\e[0m")
36
+ end
37
+
38
+ it "allows one level nesting" do
39
+ expect(pastel.red("Unicorn" + pastel.blue("rule!"))).
40
+ to eq("\e[31mUnicorn\e[34mrule!\e[0m\e[0m")
41
+ end
42
+
43
+ it "allows to nest mixed styles" do
44
+ expect(pastel.red("Unicorn" + pastel.green.on_yellow.underline('running') + '!')).
45
+ to eq("\e[31mUnicorn\e[32;43;4mrunning\e[0m\e[31m!\e[0m")
46
+ end
47
+
48
+ it "allows for deep nesting" do
49
+ expect(pastel.red('r' + pastel.green('g' + pastel.yellow('y') + 'g') + 'r')).
50
+ to eq("\e[31mr\e[32mg\e[33my\e[0m\e[32mg\e[0m\e[31mr\e[0m")
51
+ end
52
+
53
+ it "allows for variable nested arguments" do
54
+ expect(pastel.red('r', pastel.green('g'), 'r')).
55
+ to eq("\e[31mr\e[32mg\e[0m\e[31mr\e[0m")
56
+ end
57
+
58
+ it "nests color foreground & background" do
59
+ expect(pastel.on_red('foo', pastel.green('bar'), 'foo')).
60
+ to eq("\e[41mfoo\e[32mbar\e[0m\e[41mfoo\e[0m")
61
+ end
62
+
63
+ it "allows to nest styles within block" do
64
+ string = pastel.red.on_green('Unicorns' +
65
+ pastel.green.on_red('will ', 'dominate' + pastel.yellow('the world!')))
66
+
67
+ expect(pastel.red.on_green('Unicorns') do
68
+ green.on_red('will ', 'dominate') do
69
+ yellow('the world!')
70
+ end
71
+ end).to eq(string)
72
+ end
73
+
74
+ it "raises error when chained with unrecognized color" do
75
+ expect {
76
+ pastel.unknown.on_red('unicorn')
77
+ }.to raise_error(Pastel::InvalidAttributeNameError)
78
+ end
79
+
80
+ it "raises error when doesn't recognize color" do
81
+ expect {
82
+ pastel.unknown('unicorn')
83
+ }.to raise_error(Pastel::InvalidAttributeNameError)
84
+ end
85
+ end
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe Pastel::DecoratorChain do
6
4
  it "is enumerable" do
7
5
  expect(described_class.new).to be_a(Enumerable)
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe Pastel::Delegator do
6
4
 
7
5
  it "returns delegator for color without argument" do
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe Pastel, '.detach' do
6
4
 
7
5
  subject(:pastel) { described_class.new(enabled: true) }
@@ -1,89 +1,18 @@
1
- # coding: utf-8
1
+ # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
- RSpec.describe Pastel do
3
+ RSpec.describe Pastel, '#new' do
6
4
 
7
5
  subject(:pastel) { described_class.new(enabled: true) }
8
6
 
9
- describe 'coloring string' do
10
- it "doesn't apply styles to empty string" do
11
- expect(pastel.red('')).to eq('')
12
- end
13
-
14
- it "colors string" do
15
- expect(pastel.red("unicorn")).to eq("\e[31municorn\e[0m")
16
- end
17
-
18
- it "allows to specify variable number of arguments" do
19
- expect(pastel.red("unicorn", "running")).to eq("\e[31municornrunning\e[0m")
20
- end
21
-
22
- it "combines colored strings with regular ones" do
23
- expect(pastel.red("Unicorns") + ' will rule ' + pastel.green('the World!')).
24
- to eq("\e[31mUnicorns\e[0m will rule \e[32mthe World!\e[0m")
25
- end
26
-
27
- it "composes two color strings " do
28
- expect(pastel.red.on_green("unicorn")).to eq("\e[31;42municorn\e[0m")
29
- end
30
-
31
- it "composes three color strings" do
32
- expect(pastel.red.on_green.underline("unicorn")).
33
- to eq("\e[31;42;4municorn\e[0m")
34
- end
7
+ it { is_expected.to respond_to(:lookup) }
35
8
 
36
- it "combines colored composed strings with regular ones" do
37
- expect(pastel.red.on_green("Unicorns") + ' will rule ' +
38
- pastel.green.on_red('the World!')).
39
- to eq("\e[31;42mUnicorns\e[0m will rule \e[32;41mthe World!\e[0m")
40
- end
9
+ it { is_expected.to respond_to(:decorate) }
41
10
 
42
- it "allows one level nesting" do
43
- expect(pastel.red("Unicorn" + pastel.blue("rule!"))).
44
- to eq("\e[31mUnicorn\e[34mrule!\e[0m")
45
- end
11
+ it { is_expected.to respond_to(:undecorate) }
46
12
 
47
- it "allows to nest mixed styles" do
48
- expect(pastel.red("Unicorn" + pastel.green.on_yellow.underline('running') + '!')).
49
- to eq("\e[31mUnicorn\e[32;43;4mrunning\e[31m!\e[0m")
50
- end
13
+ it { is_expected.to respond_to(:strip) }
51
14
 
52
- it "allows for deep nesting" do
53
- expect(pastel.red('r' + pastel.green('g' + pastel.yellow('y') + 'g') + 'r')).
54
- to eq("\e[31mr\e[32mg\e[33my\e[32mg\e[31mr\e[0m")
55
- end
56
-
57
- it "allows for variable nested arguments" do
58
- expect(pastel.red('r', pastel.green('g'), 'r')).
59
- to eq("\e[31mr\e[32mg\e[31mr\e[0m")
60
- end
61
-
62
- it "allows to nest styles within block" do
63
- string = pastel.red.on_green('Unicorns' +
64
- pastel.green.on_red('will ', 'dominate' + pastel.yellow('the world!')))
65
-
66
- expect(pastel.red.on_green('Unicorns') do
67
- green.on_red('will ', 'dominate') do
68
- yellow('the world!')
69
- end
70
- end).to eq(string)
71
- end
72
-
73
- it "raises error when chained with unrecognized color" do
74
- expect {
75
- pastel.unknown.on_red('unicorn')
76
- }.to raise_error(Pastel::InvalidAttributeNameError)
77
- end
78
-
79
- it "raises error when doesn't recognize color" do
80
- expect {
81
- pastel.unknown('unicorn')
82
- }.to raise_error(Pastel::InvalidAttributeNameError)
83
- end
84
- end
85
-
86
- describe '.valid?' do
15
+ describe '#valid?' do
87
16
  it "when valid returns true" do
88
17
  expect(pastel.valid?(:red)).to eq(true)
89
18
  end
@@ -93,14 +22,23 @@ RSpec.describe Pastel do
93
22
  end
94
23
  end
95
24
 
96
- describe '.colored?' do
25
+ describe '#colored?' do
97
26
  it "checks if string is colored" do
98
27
  expect(pastel.colored?("\e[31mfoo\e[0m")).to eq(true)
99
28
  end
100
29
  end
101
30
 
102
31
  describe 'options passed in' do
103
- it "receives enabled option" do
32
+ it 'defaults enabled to color detection' do
33
+ allow(TTY::Color).to receive(:color?).and_return(true)
34
+
35
+ pastel = described_class.new
36
+
37
+ expect(pastel.enabled?).to eq(true)
38
+ expect(TTY::Color).to have_received(:color?)
39
+ end
40
+
41
+ it "sets enabled option" do
104
42
  pastel = described_class.new(enabled: false)
105
43
  expect(pastel.enabled?).to eq(false)
106
44
  expect(pastel.red('Unicorn', pastel.green('!'))).to eq('Unicorn!')
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe Pastel, '.respond_to?' do
6
4
  subject(:pastel) { described_class.new(enabled: true) }
7
5
 
@@ -0,0 +1,12 @@
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
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.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equatable
@@ -25,33 +25,53 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: tty-screen
28
+ name: tty-color
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.3
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.3
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.0
48
+ - - <
46
49
  - !ruby/object:Gem::Version
47
- version: '1.6'
50
+ version: '2.0'
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - ~>
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 1.5.0
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
53
73
  - !ruby/object:Gem::Version
54
- version: '1.6'
74
+ version: '0'
55
75
  description: Terminal strings styling with intuitive and clean API.
56
76
  email:
57
77
  - ''
@@ -61,7 +81,6 @@ extra_rdoc_files: []
61
81
  files:
62
82
  - .gitignore
63
83
  - .rspec
64
- - .ruby-gemset
65
84
  - .ruby-version
66
85
  - .travis.yml
67
86
  - CHANGELOG.md
@@ -78,6 +97,7 @@ files:
78
97
  - lib/pastel/alias_importer.rb
79
98
  - lib/pastel/ansi.rb
80
99
  - lib/pastel/color.rb
100
+ - lib/pastel/color_parser.rb
81
101
  - lib/pastel/color_resolver.rb
82
102
  - lib/pastel/decorator_chain.rb
83
103
  - lib/pastel/delegator.rb
@@ -92,15 +112,19 @@ files:
92
112
  - spec/unit/color/colored_spec.rb
93
113
  - spec/unit/color/decorate_spec.rb
94
114
  - spec/unit/color/equal_spec.rb
115
+ - spec/unit/color/lookup_spec.rb
95
116
  - spec/unit/color/new_spec.rb
96
117
  - spec/unit/color/strip_spec.rb
97
118
  - spec/unit/color/styles_spec.rb
98
119
  - spec/unit/color/valid_spec.rb
120
+ - spec/unit/color_parser_spec.rb
121
+ - spec/unit/decorate_dsl_spec.rb
99
122
  - spec/unit/decorator_chain_spec.rb
100
123
  - spec/unit/delegator_spec.rb
101
124
  - spec/unit/detach_spec.rb
102
125
  - spec/unit/new_spec.rb
103
126
  - spec/unit/respond_to_spec.rb
127
+ - spec/unit/undecorate_spec.rb
104
128
  - tasks/console.rake
105
129
  - tasks/coverage.rake
106
130
  - tasks/spec.rake
@@ -137,13 +161,17 @@ test_files:
137
161
  - spec/unit/color/colored_spec.rb
138
162
  - spec/unit/color/decorate_spec.rb
139
163
  - spec/unit/color/equal_spec.rb
164
+ - spec/unit/color/lookup_spec.rb
140
165
  - spec/unit/color/new_spec.rb
141
166
  - spec/unit/color/strip_spec.rb
142
167
  - spec/unit/color/styles_spec.rb
143
168
  - spec/unit/color/valid_spec.rb
169
+ - spec/unit/color_parser_spec.rb
170
+ - spec/unit/decorate_dsl_spec.rb
144
171
  - spec/unit/decorator_chain_spec.rb
145
172
  - spec/unit/delegator_spec.rb
146
173
  - spec/unit/detach_spec.rb
147
174
  - spec/unit/new_spec.rb
148
175
  - spec/unit/respond_to_spec.rb
176
+ - spec/unit/undecorate_spec.rb
149
177
  has_rdoc:
@@ -1 +0,0 @@
1
- pastel