simple_commander 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/.byebug_history +15 -0
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +77 -0
- data/.travis.yml +6 -0
- data/Gemfile +1 -0
- data/History.rdoc +3 -0
- data/bin/simple_commander +1 -1
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +1660 -0
- data/coverage/.resultset.json.lock +0 -0
- data/dir_glob.rb +7 -8
- data/ember_c +7 -38
- data/helper.rb +5 -0
- data/helpers/http_helper.rb +5 -0
- data/lib/simple_commander/command.rb +3 -3
- data/lib/simple_commander/configure.rb +2 -2
- data/lib/simple_commander/core_ext.rb +2 -2
- data/lib/simple_commander/delegates.rb +4 -3
- data/lib/simple_commander/help_formatters/base.rb +1 -1
- data/lib/simple_commander/help_formatters/terminal.rb +1 -1
- data/lib/simple_commander/help_formatters/terminal_compact.rb +1 -1
- data/lib/simple_commander/help_formatters.rb +4 -4
- data/lib/simple_commander/helpers/io.rb +128 -0
- data/lib/simple_commander/helpers.rb +1 -0
- data/lib/simple_commander/import.rb +1 -1
- data/lib/simple_commander/methods.rb +4 -4
- data/lib/simple_commander/platform.rb +1 -1
- data/lib/simple_commander/runner.rb +28 -6
- data/lib/simple_commander/user_interaction.rb +2 -2
- data/lib/simple_commander/version.rb +2 -2
- data/lib/simple_commander.rb +1 -0
- data/simple_commander.gemspec +2 -1
- data/spec/command_spec.rb +157 -0
- data/spec/configure_spec.rb +37 -0
- data/spec/core_ext/array_spec.rb +18 -0
- data/spec/core_ext/object_spec.rb +19 -0
- data/spec/help_formatters/terminal_compact_spec.rb +69 -0
- data/spec/help_formatters/terminal_spec.rb +67 -0
- data/spec/methods_spec.rb +20 -0
- data/spec/runner_spec.rb +659 -0
- data/spec/spec_helper.rb +82 -0
- data/spec/ui_spec.rb +30 -0
- data/test.rb +24 -0
- data/todo.yml +16 -4
- metadata +37 -2
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simple_commander/configure'
|
3
|
+
|
4
|
+
describe SimpleCommander do
|
5
|
+
describe '.configure' do
|
6
|
+
it 'calls the given block' do
|
7
|
+
expect { SimpleCommander.configure { throw :block_called } }.to throw_symbol(:block_called)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'called block' do
|
11
|
+
before(:each) do
|
12
|
+
allow(SimpleCommander::Runner.instance).to receive(:run!)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'provides Commander configuration methods' do
|
16
|
+
SimpleCommander.configure do
|
17
|
+
program :name, 'test'
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(SimpleCommander::Runner.instance.program(:name)).to eq('test')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'passes all arguments to the block' do
|
24
|
+
SimpleCommander.configure('foo') do |first_arg|
|
25
|
+
program :name, first_arg
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(SimpleCommander::Runner.instance.program(:name)).to eq('foo')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'calls Runner#run! after calling the configuration block' do
|
33
|
+
expect(SimpleCommander::Runner.instance).to receive(:run!)
|
34
|
+
SimpleCommander.configure {}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe '#parse' do
|
5
|
+
it 'should seperate a list of words into an array' do
|
6
|
+
expect(Array.parse('just a test')).to eq(%w(just a test))
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should preserve escaped whitespace' do
|
10
|
+
expect(Array.parse('just a\ test')).to eq(['just', 'a test'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should match %w behavior with multiple backslashes' do
|
14
|
+
str = 'just a\\ test'
|
15
|
+
expect(Array.parse(str)).to eq(eval("%w(#{str})"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
describe '#get_binding' do
|
5
|
+
it 'should return the objects binding' do
|
6
|
+
expect(-> {}.get_binding).to be_instance_of(Binding)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#method_missing' do
|
11
|
+
it 'should preserve its original behavior for missing methods' do
|
12
|
+
expect { send(:i_am_a_missing_method) }.to raise_error(NoMethodError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should preserve its original behavior for missing variables' do
|
16
|
+
expect { i_am_a_missing_variable }.to raise_error(NameError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleCommander::HelpFormatter::TerminalCompact do
|
4
|
+
include SimpleCommander::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
mock_terminal
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'global help' do
|
11
|
+
before :each do
|
12
|
+
new_command_runner 'help' do
|
13
|
+
program :help_formatter, :compact
|
14
|
+
command :'install gem' do |c|
|
15
|
+
c.syntax = 'foo install gem [options]'
|
16
|
+
c.summary = 'Install some gem'
|
17
|
+
end
|
18
|
+
end.run!
|
19
|
+
@global_help = @output.string
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'should display' do
|
23
|
+
it 'the command name' do
|
24
|
+
expect(@global_help).to include('install gem')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'the summary' do
|
28
|
+
expect(@global_help).to include('Install some gem')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'command help' do
|
34
|
+
before :each do
|
35
|
+
new_command_runner 'help', 'install', 'gem' do
|
36
|
+
program :help_formatter, :compact
|
37
|
+
command :'install gem' do |c|
|
38
|
+
c.syntax = 'foo install gem [options]'
|
39
|
+
c.summary = 'Install some gem'
|
40
|
+
c.description = 'Install some gem, blah blah blah'
|
41
|
+
c.example 'one', 'two'
|
42
|
+
c.example 'three', 'four'
|
43
|
+
end
|
44
|
+
end.run!
|
45
|
+
@command_help = @output.string
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'should display' do
|
49
|
+
it 'the command name' do
|
50
|
+
expect(@command_help).to include('install gem')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'the description' do
|
54
|
+
expect(@command_help).to include('Install some gem, blah blah blah')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'all examples' do
|
58
|
+
expect(@command_help).to include('# one')
|
59
|
+
expect(@command_help).to include('two')
|
60
|
+
expect(@command_help).to include('# three')
|
61
|
+
expect(@command_help).to include('four')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'the syntax' do
|
65
|
+
expect(@command_help).to include('foo install gem [options]')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleCommander::HelpFormatter::Terminal do
|
4
|
+
include SimpleCommander::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
mock_terminal
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'global help' do
|
11
|
+
before :each do
|
12
|
+
new_command_runner 'help' do
|
13
|
+
command :'install gem' do |c|
|
14
|
+
c.syntax = 'foo install gem [options]'
|
15
|
+
c.summary = 'Install some gem'
|
16
|
+
end
|
17
|
+
end.run!
|
18
|
+
@global_help = @output.string
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'should display' do
|
22
|
+
it 'the command name' do
|
23
|
+
expect(@global_help).to include('install gem')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'the summary' do
|
27
|
+
expect(@global_help).to include('Install some gem')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'command help' do
|
33
|
+
before :each do
|
34
|
+
new_command_runner 'help', 'install', 'gem' do
|
35
|
+
command :'install gem' do |c|
|
36
|
+
c.syntax = 'foo install gem [options]'
|
37
|
+
c.summary = 'Install some gem'
|
38
|
+
c.description = 'Install some gem, blah blah blah'
|
39
|
+
c.example 'one', 'two'
|
40
|
+
c.example 'three', 'four'
|
41
|
+
end
|
42
|
+
end.run!
|
43
|
+
@command_help = @output.string
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'should display' do
|
47
|
+
it 'the command name' do
|
48
|
+
expect(@command_help).to include('install gem')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'the description' do
|
52
|
+
expect(@command_help).to include('Install some gem, blah blah blah')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'all examples' do
|
56
|
+
expect(@command_help).to include('# one')
|
57
|
+
expect(@command_help).to include('two')
|
58
|
+
expect(@command_help).to include('# three')
|
59
|
+
expect(@command_help).to include('four')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'the syntax' do
|
63
|
+
expect(@command_help).to include('foo install gem [options]')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simple_commander/methods'
|
3
|
+
|
4
|
+
describe SimpleCommander::Methods do
|
5
|
+
it 'includes SimpleCommander::UI' do
|
6
|
+
expect(subject.ancestors).to include(SimpleCommander::UI)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'includes SimpleCommander::UI::AskForClass' do
|
10
|
+
expect(subject.ancestors).to include(SimpleCommander::UI::AskForClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'includes SimpleCommander::Delegates' do
|
14
|
+
expect(subject.ancestors).to include(SimpleCommander::Delegates)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not change the Object ancestors' do
|
18
|
+
expect(Object.ancestors).not_to include(SimpleCommander::UI)
|
19
|
+
end
|
20
|
+
end
|