tty 0.5.0 → 0.6.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -9
  3. data/CHANGELOG.md +27 -10
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/Gemfile +2 -2
  6. data/README.md +40 -182
  7. data/appveyor.yml +23 -0
  8. data/lib/tty.rb +2 -65
  9. data/lib/tty/plugins.rb +46 -19
  10. data/lib/tty/plugins/plugin.rb +4 -9
  11. data/lib/tty/version.rb +1 -1
  12. data/spec/fixtures/foo-0.0.1.gemspec +17 -0
  13. data/spec/spec_helper.rb +12 -0
  14. data/spec/tty/plugins/find_spec.rb +11 -19
  15. data/spec/tty/plugins/load_spec.rb +6 -10
  16. data/spec/tty/plugins/plugin/load_spec.rb +15 -5
  17. data/spec/tty/plugins/plugin/new_spec.rb +3 -6
  18. data/spec/tty/tty_spec.rb +1 -7
  19. data/tty.gemspec +11 -9
  20. metadata +89 -94
  21. data/lib/tty/logger.rb +0 -85
  22. data/lib/tty/support/coercion.rb +0 -30
  23. data/lib/tty/support/delegatable.rb +0 -44
  24. data/lib/tty/support/unicode.rb +0 -35
  25. data/lib/tty/system.rb +0 -14
  26. data/lib/tty/system/editor.rb +0 -114
  27. data/lib/tty/terminal.rb +0 -21
  28. data/lib/tty/terminal/home.rb +0 -42
  29. data/lib/tty/vector.rb +0 -116
  30. data/spec/tty/logger/log_spec.rb +0 -23
  31. data/spec/tty/logger/new_spec.rb +0 -36
  32. data/spec/tty/logger/valid_level_spec.rb +0 -33
  33. data/spec/tty/support/coercion_spec.rb +0 -41
  34. data/spec/tty/support/delegatable_spec.rb +0 -28
  35. data/spec/tty/support/fixtures/classes.rb +0 -19
  36. data/spec/tty/system/editor/available_spec.rb +0 -40
  37. data/spec/tty/system/editor/build_spec.rb +0 -32
  38. data/spec/tty/system/editor/command_spec.rb +0 -17
  39. data/spec/tty/system/editor/executables_spec.rb +0 -13
  40. data/spec/tty/system/editor/invoke_spec.rb +0 -34
  41. data/spec/tty/system/editor/open_spec.rb +0 -29
  42. data/spec/tty/terminal/home_spec.rb +0 -27
  43. data/spec/tty/vector/new_spec.rb +0 -48
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Logger, '#new' do
6
- let(:object) { described_class }
7
- let(:output) { StringIO.new }
8
-
9
- subject(:logger) { object.new(options) }
10
-
11
- context 'when default' do
12
- let(:options) { {namespace: ''} }
13
-
14
- it { expect(logger.level).to eq(object::ALL) }
15
-
16
- it { expect(logger.output).to eq($stderr) }
17
-
18
- it { expect(logger.timestamp_format).to eq('%Y-%m-%d %T') }
19
- end
20
-
21
- context 'when custom' do
22
- let(:options) { {
23
- namespace: 'tty::color',
24
- level: 2,
25
- output: output,
26
- timestamp_format: "%dd" } }
27
-
28
- it { expect(logger.namespace).to eq('tty::color') }
29
-
30
- it { expect(logger.level).to eq(2) }
31
-
32
- it { expect(logger.output).to eq(output) }
33
-
34
- it { expect(logger.timestamp_format).to eq('%dd') }
35
- end
36
- end
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Logger, '#valid_level?' do
6
- let(:object) { described_class }
7
-
8
- subject { object.valid_level?(level) }
9
-
10
- context 'when level is nil' do
11
- let(:level) { nil }
12
-
13
- it { is_expected.to eq(false) }
14
- end
15
-
16
- context 'when level is non numeric' do
17
- let(:level) { 'a' }
18
-
19
- it { is_expected.to eq(false) }
20
- end
21
-
22
- context 'when level is not a valid number' do
23
- let(:level) { -1 }
24
-
25
- it { is_expected.to eq(false) }
26
- end
27
-
28
- context 'when level is valid number' do
29
- let(:level) { 0 }
30
-
31
- it { is_expected.to eq(true) }
32
- end
33
- end
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Coercion do
6
- let(:described_class) { Class.new { include TTY::Coercion } }
7
- let(:object) { described_class.new }
8
- let(:value) { [] }
9
- let(:coercible) { [ value, Array, :to_a] }
10
-
11
- subject { object.coerce_to( *coercible ) }
12
-
13
- it { is_expected.to eq(value) }
14
-
15
- context 'coerces into integer' do
16
- let(:value) { '123' }
17
- let(:coercible) { [ value, Integer, :to_i] }
18
-
19
- it { is_expected.to be_kind_of(Integer) }
20
-
21
- it { is_expected.to eq(value.to_i) }
22
- end
23
-
24
- context 'coerces into symbol' do
25
- let(:value) { 'argument' }
26
- let(:coercible) { [value, Symbol, :to_sym]}
27
-
28
- it { is_expected.to be_kind_of(Symbol) }
29
-
30
- it { is_expected.to eq(value.to_sym) }
31
- end
32
-
33
- context 'coerces into string' do
34
- let(:value) { true }
35
- let(:coercible) { [value, String, :to_s] }
36
-
37
- it { is_expected.to be_kind_of(String) }
38
-
39
- it { is_expected.to eq(value.to_s) }
40
- end
41
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require File.expand_path('../fixtures/classes', __FILE__)
5
-
6
- describe TTY::Delegatable do
7
- let(:target) { :test }
8
- let(:methods) { [:output] }
9
- let(:object) { Class.new(DelegetableSpec::Object)}
10
- let(:delegatable) { object.new }
11
-
12
- subject { object.delegatable_method target, *methods }
13
-
14
- it 'creates a method #output' do
15
- expect { subject }.to change { delegatable.respond_to?(:output) }.
16
- from(false).
17
- to(true)
18
- end
19
-
20
- it 'delegates #output to target' do
21
- subject
22
- instance = spy(:target_spec)
23
- allow(TargetSpec::Object).to receive(:new).and_return(instance)
24
-
25
- delegatable.output
26
- expect(instance).to have_received(:output)
27
- end
28
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module TargetSpec
4
- class Object
5
- def output
6
- true
7
- end
8
- end
9
- end
10
-
11
- module DelegetableSpec
12
- class Object
13
- extend TTY::Delegatable
14
-
15
- def test
16
- TargetSpec::Object.new
17
- end
18
- end
19
- end
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#available' do
6
- let(:execs) { ['vi', 'emacs'] }
7
- let(:name) { 'sublime' }
8
- let(:system) { TTY::System }
9
-
10
- subject(:editor) { described_class }
11
-
12
- before { allow(editor).to receive(:executables).and_return(execs) }
13
-
14
- context 'when editor exists' do
15
- before {
16
- allow(system).to receive(:exists?).with('vi').and_return(true)
17
- allow(system).to receive(:exists?).with('emacs').and_return(false)
18
- }
19
-
20
- it 'finds single command' do
21
- expect(editor.available).to eql('vi')
22
- end
23
- end
24
-
25
- context 'when no command exists' do
26
- before { allow(system).to receive(:exists?).and_return(false) }
27
-
28
- it "doesn't find command" do
29
- expect(editor.available).to be_nil
30
- end
31
- end
32
-
33
- context 'when custom command' do
34
- before { allow(system).to receive(:exists?).with(name).and_return(true) }
35
-
36
- it "takes precedence over other commands" do
37
- expect(editor.available(name)).to eql(name)
38
- end
39
- end
40
- end
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#build' do
6
- let(:file) { "/users/piotr/hello world.rb" }
7
- let(:name) { "vim" }
8
- let(:object) { described_class }
9
-
10
- subject(:editor) { object.new(file) }
11
-
12
- before { allow(object).to receive(:command).and_return(name) }
13
-
14
- context 'when on windows' do
15
- before {
16
- allow(TTY::System).to receive(:unix?).and_return(false)
17
- allow(TTY::System).to receive(:windows?).and_return(true)
18
- }
19
-
20
- it "doesn't shell escape" do
21
- expect(subject.build).to eql("vim \\users\\piotr\\hello world.rb")
22
- end
23
- end
24
-
25
- context 'when on unix' do
26
- before { allow(TTY::System).to receive(:unix?).and_return(true) }
27
-
28
- it 'escapes shell' do
29
- expect(editor.build).to eql("vim /users/piotr/hello\\ world.rb")
30
- end
31
- end
32
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#command' do
6
- let(:editor) { 'vim' }
7
-
8
- subject { described_class }
9
-
10
- context 'when custom command' do
11
- it 'searches available commands' do
12
- allow(subject).to receive(:available)
13
- subject.command(editor)
14
- expect(subject).to have_received(:available).with(editor)
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#executables' do
6
- let(:object) { described_class }
7
-
8
- subject { object.executables }
9
-
10
- it { is_expected.to be_an Array }
11
-
12
- it { is_expected.to include('vi') }
13
- end
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#invoke' do
6
- let(:file) { "hello.rb" }
7
- let(:name) { "vim" }
8
- let(:object) { described_class }
9
-
10
- subject(:editor) { object.new(file) }
11
-
12
- before {
13
- allow(object).to receive(:command).and_return(name)
14
- allow(TTY::System).to receive(:unix?).and_return(true)
15
- }
16
-
17
- context 'when invokes' do
18
- before { allow(editor).to receive(:system).and_return(true) }
19
-
20
- it 'executes editor command' do
21
- editor.invoke
22
- expect(editor).to have_received(:system).with(name, file)
23
- end
24
- end
25
-
26
- context 'when fails to invoke' do
27
-
28
- before { allow(editor).to receive(:system).and_return(false) }
29
-
30
- it 'raises an error' do
31
- expect { editor.invoke }.to raise_error(TTY::CommandInvocationError)
32
- end
33
- end
34
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::System::Editor, '#open' do
6
- let(:file) { "hello.rb" }
7
-
8
- subject(:editor) { described_class }
9
-
10
- context 'when no editor' do
11
- before { allow(editor).to receive(:command).and_return(nil) }
12
-
13
- it 'raises error' do
14
- expect {
15
- editor.open(file)
16
- }.to raise_error(TTY::CommandInvocationError)
17
- end
18
- end
19
-
20
- context 'when editor' do
21
- before { allow(editor).to receive(:command).and_return('vim') }
22
-
23
- it 'invokes editor' do
24
- invocable = double(:invocable, invoke: nil)
25
- expect(subject).to receive(:new).with(file).and_return(invocable)
26
- editor.open(file)
27
- end
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Terminal::Home, '#find_home' do
6
- context 'on unix' do
7
- it "finds home" do
8
- platform = spy(:windows? => false)
9
- home = described_class.new(platform)
10
- allow(home).to receive(:unix_home).and_return('/users/piotr')
11
- allow(File).to receive(:expand_path).and_return('/users/piotr')
12
- expect(home.find_home).to eq('/users/piotr')
13
- expect(home).to have_received(:unix_home)
14
- end
15
- end
16
-
17
- context 'on windows' do
18
- it "finds home" do
19
- platform = spy(:windows? => true)
20
- home = described_class.new(platform)
21
- allow(home).to receive(:windows_home).and_return('C:\Users\Piotr')
22
- allow(File).to receive(:expand_path).and_return('C:\Users\Piotr')
23
- expect(home.find_home).to eq('C:\Users\Piotr')
24
- expect(home).to have_received(:windows_home)
25
- end
26
- end
27
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Vector, '#new' do
6
- let(:object) { described_class }
7
-
8
- subject(:vector) { object.new(argument) }
9
-
10
- context 'with no arguments' do
11
- subject(:vector) { object.new }
12
-
13
- it 'sets elements to empty array' do
14
- expect(vector.to_a).to eq([])
15
- end
16
- end
17
-
18
- context 'with nil argument' do
19
- let(:argument) { nil }
20
-
21
- it 'throws type error' do
22
- expect(vector.to_a).to eq([])
23
- end
24
- end
25
-
26
- context 'with an argument that is a hash' do
27
- let(:argument) { {value: 'Piotr'} }
28
-
29
- it 'sets elements' do
30
- expect(vector.to_a).to eq([[:value, 'Piotr']])
31
- end
32
- end
33
-
34
- context 'with an argument that respond to #to_ary' do
35
- let(:argument) {
36
- Custom = Class.new do
37
- def to_ary
38
- ['Piotr']
39
- end
40
- end
41
- Custom.new
42
- }
43
-
44
- it 'sets elements' do
45
- expect(vector.to_a).to eq(['Piotr'])
46
- end
47
- end
48
- end