cp 0.0.1.pre1 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +55 -0
- data/cp.gemspec +1 -2
- data/examples/net.rb +12 -9
- data/lib/cp.rb +23 -9
- data/lib/cp/app.rb +18 -4
- data/lib/cp/command.rb +38 -7
- data/lib/cp/errors.rb +4 -0
- data/lib/cp/has/commands.rb +34 -0
- data/lib/cp/has/options.rb +17 -0
- data/lib/cp/option.rb +22 -2
- data/lib/cp/options_struct.rb +7 -0
- data/lib/cp/runners/cmd_parse.rb +32 -11
- data/lib/cp/version.rb +1 -1
- data/spec/app_spec.rb +29 -16
- data/spec/command_spec.rb +10 -4
- data/spec/cp_spec.rb +1 -1
- data/spec/has/commands_spec.rb +10 -0
- data/spec/has/options_spec.rb +10 -0
- data/spec/option_spec.rb +43 -15
- data/spec/options_struct_spec.rb +7 -0
- data/spec/runners/cmd_parse_spec.rb +6 -38
- data/spec/support/lib/test_app_runner.rb +16 -0
- data/spec/support/shared_examples/commands_examples.rb +52 -0
- data/spec/support/shared_examples/options_examples.rb +23 -0
- data/spec/support/shared_examples/runner_examples.rb +173 -0
- data/spec/support/spec_helper.rb +38 -12
- metadata +25 -23
- data/lib/cp/commands.rb +0 -15
- data/lib/cp/options.rb +0 -15
- data/spec/options_spec.rb +0 -10
- data/spec/support/shared_helper.rb +0 -47
data/spec/support/spec_helper.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
# require support files
|
2
|
+
Dir[File.join( File.dirname( __FILE__ ), "**", "*" )].each do |f|
|
3
|
+
require f if File.file?( f ) && f != __FILE__
|
4
|
+
end
|
3
5
|
|
4
6
|
# ensure we're at the front of the load path
|
5
7
|
$:.unshift( File.join( File.dirname( __FILE__ ), "..", "lib" ) )
|
6
8
|
|
7
9
|
# include the gem
|
8
10
|
require "cp"
|
11
|
+
require "stringio"
|
9
12
|
|
10
13
|
# reset the App singleton before each test
|
11
14
|
RSpec.configure do |config|
|
@@ -14,19 +17,42 @@ RSpec.configure do |config|
|
|
14
17
|
}
|
15
18
|
end
|
16
19
|
|
17
|
-
|
18
|
-
class App
|
20
|
+
class TestApp
|
19
21
|
include CP
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
a =
|
24
|
-
|
25
|
-
a
|
24
|
+
def create_test_app
|
25
|
+
a = TestApp
|
26
|
+
|
27
|
+
a.app :name, "test app"
|
28
|
+
a.app :version, "0.1"
|
29
|
+
|
30
|
+
a.command( :test ) do |c|
|
31
|
+
c.summary = "test summary"
|
32
|
+
c.option "-v", "--verbose", "verbose description"
|
33
|
+
c.execute do |args|
|
34
|
+
"test #{args.join( ", " )}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
yield TestApp if block_given?
|
39
|
+
|
40
|
+
CP::App.instance
|
41
|
+
end
|
42
|
+
|
43
|
+
def run *args, &block
|
44
|
+
runner = TestAppRunner.new
|
45
|
+
runner.run( *args, &block )
|
46
|
+
runner
|
26
47
|
end
|
27
48
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
def trap_output
|
50
|
+
orig_stdout, orig_stderr = $stdout, $stderr
|
51
|
+
$stdout, $stderr = StringIO.new, StringIO.new
|
52
|
+
|
53
|
+
yield
|
54
|
+
|
55
|
+
errors, output = $stderr.string, $stdout.string
|
56
|
+
$stdout, $stderr = orig_stdout, orig_stderr
|
57
|
+
[errors, output]
|
32
58
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.0.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rick Fletcher
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-09 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cmdparse
|
@@ -23,17 +23,6 @@ dependencies:
|
|
23
23
|
version: 2.0.2
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: cmdparse
|
28
|
-
prerelease: false
|
29
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 2.0.2
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
26
|
description: CP provides a less verbose API for the CmdParse gem.
|
38
27
|
email:
|
39
28
|
- fletch@pobox.com
|
@@ -46,27 +35,35 @@ extra_rdoc_files: []
|
|
46
35
|
files:
|
47
36
|
- .gitignore
|
48
37
|
- Gemfile
|
38
|
+
- README.md
|
49
39
|
- Rakefile
|
50
40
|
- cp.gemspec
|
51
41
|
- examples/net.rb
|
52
42
|
- lib/cp.rb
|
53
43
|
- lib/cp/app.rb
|
54
44
|
- lib/cp/command.rb
|
55
|
-
- lib/cp/
|
45
|
+
- lib/cp/errors.rb
|
46
|
+
- lib/cp/has/commands.rb
|
47
|
+
- lib/cp/has/options.rb
|
56
48
|
- lib/cp/option.rb
|
57
|
-
- lib/cp/
|
49
|
+
- lib/cp/options_struct.rb
|
58
50
|
- lib/cp/runners/cmd_parse.rb
|
59
51
|
- lib/cp/version.rb
|
60
52
|
- spec/app_spec.rb
|
61
53
|
- spec/command_spec.rb
|
62
54
|
- spec/cp_spec.rb
|
55
|
+
- spec/has/commands_spec.rb
|
56
|
+
- spec/has/options_spec.rb
|
63
57
|
- spec/option_spec.rb
|
64
|
-
- spec/
|
58
|
+
- spec/options_struct_spec.rb
|
65
59
|
- spec/runners/cmd_parse_spec.rb
|
66
|
-
- spec/support/
|
60
|
+
- spec/support/lib/test_app_runner.rb
|
61
|
+
- spec/support/shared_examples/commands_examples.rb
|
62
|
+
- spec/support/shared_examples/options_examples.rb
|
63
|
+
- spec/support/shared_examples/runner_examples.rb
|
67
64
|
- spec/support/singleton_helper.rb
|
68
65
|
- spec/support/spec_helper.rb
|
69
|
-
homepage:
|
66
|
+
homepage: https://github.com/baseballdb/cp
|
70
67
|
licenses: []
|
71
68
|
|
72
69
|
post_install_message:
|
@@ -83,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
81
|
none: false
|
85
82
|
requirements:
|
86
|
-
- - "
|
83
|
+
- - ">="
|
87
84
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
85
|
+
version: "0"
|
89
86
|
requirements: []
|
90
87
|
|
91
88
|
rubyforge_project:
|
@@ -97,9 +94,14 @@ test_files:
|
|
97
94
|
- spec/app_spec.rb
|
98
95
|
- spec/command_spec.rb
|
99
96
|
- spec/cp_spec.rb
|
97
|
+
- spec/has/commands_spec.rb
|
98
|
+
- spec/has/options_spec.rb
|
100
99
|
- spec/option_spec.rb
|
101
|
-
- spec/
|
100
|
+
- spec/options_struct_spec.rb
|
102
101
|
- spec/runners/cmd_parse_spec.rb
|
103
|
-
- spec/support/
|
102
|
+
- spec/support/lib/test_app_runner.rb
|
103
|
+
- spec/support/shared_examples/commands_examples.rb
|
104
|
+
- spec/support/shared_examples/options_examples.rb
|
105
|
+
- spec/support/shared_examples/runner_examples.rb
|
104
106
|
- spec/support/singleton_helper.rb
|
105
107
|
- spec/support/spec_helper.rb
|
data/lib/cp/commands.rb
DELETED
data/lib/cp/options.rb
DELETED
data/spec/options_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
shared_examples_for "it accepts commands" do
|
2
|
-
describe "#command" do
|
3
|
-
it "should return a Command" do
|
4
|
-
@target.command( :test ).should be_an_instance_of( CP::Command )
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#commands" do
|
9
|
-
it "should return an array" do
|
10
|
-
@target.commands.should be_an_instance_of( Array )
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should increase with each defined command" do
|
14
|
-
lambda {
|
15
|
-
@target.command( :test )
|
16
|
-
}.should change(){ @target.commands.length}.by( 1 )
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should include each defined command" do
|
20
|
-
@target.commands.include?( @target.command( :test ) ).should be_true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
shared_examples_for "it accepts options" do
|
26
|
-
describe "#option" do
|
27
|
-
it "should return an Option" do
|
28
|
-
@target.option( "-s" ).should be_an_instance_of( CP::Option )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#options" do
|
33
|
-
it "should return an array" do
|
34
|
-
@target.options.should be_an_instance_of( Array )
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should increase with each defined option" do
|
38
|
-
lambda {
|
39
|
-
@target.option( "-s" )
|
40
|
-
}.should change(){ @target.options.length}.by( 1 )
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should include each defined option" do
|
44
|
-
@target.options.include?( @target.option( "-s" ) ).should be_true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|