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.
@@ -1,11 +1,14 @@
1
- require File.join( File.dirname( __FILE__ ), "singleton_helper" )
2
- require File.join(File.dirname(__FILE__), "shared_helper")
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 test_app
23
- a = App.new
24
- yield a if block_given?
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 test_command
29
- c = CP::Command.new( :test )
30
- yield c if block_given?
31
- c
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: 6
5
- version: 0.0.1.pre1
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-06-08 00:00:00 Z
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/commands.rb
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/options.rb
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/options_spec.rb
58
+ - spec/options_struct_spec.rb
65
59
  - spec/runners/cmd_parse_spec.rb
66
- - spec/support/shared_helper.rb
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: 1.3.1
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/options_spec.rb
100
+ - spec/options_struct_spec.rb
102
101
  - spec/runners/cmd_parse_spec.rb
103
- - spec/support/shared_helper.rb
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
@@ -1,15 +0,0 @@
1
- module CP
2
- module Commands
3
- def commands
4
- @commands ||= []
5
- @commands
6
- end
7
-
8
- def command( *args )
9
- cmd = CP::Command.new( *args )
10
- yield cmd if block_given?
11
- commands << cmd
12
- cmd
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module CP
2
- module Options
3
- def options
4
- @options ||= []
5
- @options
6
- end
7
-
8
- def option( *args )
9
- opt = CP::Option.new( *args )
10
- yield opt if block_given?
11
- options << opt
12
- opt
13
- end
14
- end
15
- end
@@ -1,10 +0,0 @@
1
- require File.join( File.dirname( __FILE__ ), "support", "spec_helper" )
2
-
3
- describe CP::Options do
4
- before( :each ) do
5
- class Target; include CP::Options; end
6
- @target = Target.new
7
- end
8
-
9
- it_should_behave_like "it accepts options"
10
- end
@@ -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