mothership 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ require "mothership"
2
+ require "./helpers"
3
+
4
+ describe Mothership::Parser do
5
+ describe "flags" do
6
+ describe "any" do
7
+ it "accepts --foo=bar and --foo bar" do
8
+ command(:foo => {}) do |c|
9
+ inputs(c, "--foo=bar").should == {:foo => "bar"}
10
+ inputs(c, "--foo", "bar").should == {:foo => "bar"}
11
+ end
12
+ end
13
+
14
+ it "accepts --foo-bar bar as :foo_bar => \"bar\"" do
15
+ command(:foo_bar => {}) do |c|
16
+ inputs(c, "--foo-bar", "bar").should == {:foo_bar => "bar"}
17
+ end
18
+ end
19
+
20
+ it "accepts --foo as :foo => \"\"" do
21
+ command(:foo => {}) do |c|
22
+ inputs(c, "--foo").should == {:foo => ""}
23
+ end
24
+ end
25
+ end
26
+
27
+ describe :integer do
28
+ it "interprets --foo 1 as :foo => 1" do
29
+ command(:foo => {:type => :integer}) do |c|
30
+ inputs(c, "--foo", "1").should == {:foo => 1}
31
+ end
32
+ end
33
+
34
+ it "fails with --foo bar" do
35
+ command(:foo => {:type => :integer}) do |c|
36
+ proc {
37
+ inputs(c, "--foo", "bar")
38
+ }.should raise_error(Mothership::TypeMismatch)
39
+ end
40
+ end
41
+
42
+ it "fails with --foo" do
43
+ command(:foo => {:type => :integer}) do |c|
44
+ proc {
45
+ inputs(c, "--foo")
46
+ }.should raise_error(Mothership::TypeMismatch)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe :float do
52
+ it "interprets --foo 1 as :foo => 1.0" do
53
+ command(:foo => {:type => :float}) do |c|
54
+ inputs(c, "--foo", "1").should == {:foo => 1.0}
55
+ end
56
+ end
57
+
58
+ it "interprets --foo 1. as :foo => 1.0" do
59
+ command(:foo => {:type => :float}) do |c|
60
+ inputs(c, "--foo", "1.").should == {:foo => 1.0}
61
+ end
62
+ end
63
+
64
+ it "interprets --foo 2.5 as :foo => 2.5" do
65
+ command(:foo => {:type => :float}) do |c|
66
+ inputs(c, "--foo", "2.5").should == {:foo => 2.5}
67
+ end
68
+ end
69
+
70
+ it "fails with --foo bar" do
71
+ command(:foo => {:type => :float}) do |c|
72
+ proc {
73
+ inputs(c, "--foo", "bar")
74
+ }.should raise_error(Mothership::TypeMismatch)
75
+ end
76
+ end
77
+
78
+ it "fails with --foo" do
79
+ command(:foo => {:type => :float}) do |c|
80
+ proc {
81
+ inputs(c, "--foo")
82
+ }.should raise_error(Mothership::TypeMismatch)
83
+ end
84
+ end
85
+ end
86
+
87
+ describe :boolean do
88
+ it "interprets --foo as :foo => true" do
89
+ command(:foo => {:type => :boolean}) do |c|
90
+ inputs(c, "--foo").should == {:foo => true}
91
+ end
92
+ end
93
+
94
+ it "interprets --no-foo as :foo => false" do
95
+ command(:foo => {:type => :boolean}) do |c|
96
+ inputs(c, "--no-foo").should == {:foo => false}
97
+ end
98
+ end
99
+ it "interprets --foo true as :foo => true" do
100
+ command(:foo => {:type => :boolean}) do |c|
101
+ inputs(c, "--foo", "true").should == {:foo => true}
102
+ end
103
+ end
104
+
105
+ it "interprets --no-foo true as :foo => false" do
106
+ command(:foo => {:type => :boolean}) do |c|
107
+ inputs(c, "--no-foo", "true").should == {:foo => false}
108
+ end
109
+ end
110
+ it "interprets --foo false as :foo => false" do
111
+ command(:foo => {:type => :boolean}) do |c|
112
+ inputs(c, "--foo", "false").should == {:foo => false}
113
+ end
114
+ end
115
+
116
+ it "interprets --no-foo false as :foo => true" do
117
+ command(:foo => {:type => :boolean}) do |c|
118
+ inputs(c, "--no-foo", "false").should == {:foo => true}
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
data/spec/helpers.rb ADDED
@@ -0,0 +1,23 @@
1
+ module MothershipHelpers
2
+ def command(inputs = {})
3
+ cmd = Mothership::Command.new(Mothership)
4
+
5
+ inputs.each do |name, opts|
6
+ cmd.add_input(name, opts)
7
+ end
8
+
9
+ if block_given?
10
+ yield cmd
11
+ else
12
+ cmd
13
+ end
14
+ end
15
+
16
+ def inputs(cmd, *argv)
17
+ Mothership::Parser.new(cmd).inputs(argv)
18
+ end
19
+ end
20
+
21
+ RSpec.configure do |c|
22
+ c.include MothershipHelpers
23
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mothership
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alex Suraci
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 5
43
+ segments:
44
+ - 2
45
+ - 3
46
+ version: "2.3"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description:
50
+ email:
51
+ - asuraci@vmware.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - LICENSE
60
+ - Rakefile
61
+ - lib/mothership/base.rb
62
+ - lib/mothership/callbacks.rb
63
+ - lib/mothership/command.rb
64
+ - lib/mothership/errors.rb
65
+ - lib/mothership/help.rb
66
+ - lib/mothership/inputs.rb
67
+ - lib/mothership/parser.rb
68
+ - lib/mothership/pretty.rb
69
+ - lib/mothership/progress.rb
70
+ - lib/mothership/version.rb
71
+ - lib/mothership.rb
72
+ - spec/arguments_spec.rb
73
+ - spec/combination_spec.rb
74
+ - spec/flags_spec.rb
75
+ - spec/helpers.rb
76
+ - spec/Rakefile
77
+ homepage: http://cloudfoundry.com/
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project: mothership
106
+ rubygems_version: 1.8.23
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Command-line library for big honkin' CLI apps.
110
+ test_files:
111
+ - spec/arguments_spec.rb
112
+ - spec/combination_spec.rb
113
+ - spec/flags_spec.rb
114
+ - spec/helpers.rb
115
+ - spec/Rakefile