jashmenn-git-style-binaries 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + "/../../lib")
3
+ require 'git-style-binary/command'
4
+
5
+ GitStyleBinary.command do
6
+ short_desc "list blog postings"
7
+ banner <<-EOS
8
+ SYNOPSIS
9
+ #{command.full_name} #{all_options_string}
10
+
11
+ Lists the posts on the blog
12
+
13
+ EOS
14
+ run do |command|
15
+ puts "listing blog posts"
16
+ end
17
+ end
18
+
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + "/../../lib")
3
+ require 'git-style-binary/command'
4
+
5
+ GitStyleBinary.command do
6
+ short_desc "create a blog post"
7
+ banner <<-EOS
8
+ SYNOPSIS
9
+ #{command.full_name} #{all_options_string} {content|STDIN}
10
+
11
+ EOS
12
+ opt :blog, "short name of the blog to use", :default => 'default'
13
+ opt :category, "tag/category. specify multiple times for multiple categories", :type => String, :multi => true
14
+ opt :title, "title for the post", :required => true, :type => String
15
+ opt :type, "type of the content [html|xhtml|text]", :default => 'html', :type => String
16
+
17
+ run do |command|
18
+ command.die :type, "type must be one of [html|xhtml|text]" unless command.opts[:type] =~ /^(x?html|text)$/i
19
+
20
+ puts "Subcommand name: #{command.name.inspect}"
21
+ puts "Options: #{command.opts.inspect}"
22
+ puts "Remaining arguments: #{command.argv.inspect}"
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/../test_helper.rb"
2
+ require 'git-style-binary/command'
3
+
4
+ class CommandTest < Test::Unit::TestCase
5
+ context "cmd" do
6
+ setup do
7
+ @c = GitStyleBinary::Command.new
8
+ end
9
+
10
+ should "be able to easily work with constraints" do
11
+ assert_equal @c.constraints, []
12
+ @c.constraints << "foo"
13
+ assert_equal @c.constraints, ["foo"]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class GitStyleBinariesTest < Test::Unit::TestCase
4
+ context "parsing basenames" do
5
+ should "accurately parse basenames" do
6
+ assert_equal "wordpress", GitStyleBinary.basename("bin/wordpress")
7
+ assert_equal "wordpress", GitStyleBinary.basename("bin/wordpress-post")
8
+ assert_equal "wordpress", GitStyleBinary.basename("wordpress-post")
9
+ end
10
+
11
+ should "get the current command name" do
12
+ # doesn't really apply any more b/c it calls 'current' which is never the
13
+ # current when your running rake_test_loader.rb
14
+ #
15
+ # assert_equal "wordpress", GitStyleBinary.current_command_name("bin/wordpress", ["--help"])
16
+ # assert_equal "post", GitStyleBinary.current_command_name("bin/wordpress-post", ["--help"])
17
+ # assert_equal "post", GitStyleBinary.current_command_name("bin/wordpress post", ["--help"])
18
+ #assert_equal "post", GitStyleBinary.current_command_name("bin/wordpress post", [])
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,185 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ THIS_YEAR=Time.now.year # todo
4
+
5
+ class RunningBinariesTest < Test::Unit::TestCase
6
+ include RunsBinaryFixtures
7
+
8
+ context "when running primary" do
9
+ ["wordpress -h", "wordpress help"].each do |format|
10
+ context "and getting help as a '#{format}'" do
11
+ setup { @stdout, @stderr = bin(format) }
12
+
13
+ should "have the command name and short description" do
14
+ unless format == "wordpress -h" # doesn't apply to wordpress -h
15
+ output_matches /NAME\n\s*wordpress\-help \- get help for a specific command/m
16
+ end
17
+ end
18
+
19
+ should "have a local (not default) version string" do
20
+ output_matches /0\.0\.1 \(c\) 2009 Nate Murray - local/
21
+ end
22
+
23
+ should "get a list of subcommands" do
24
+ output_matches /subcommands/mi
25
+ end
26
+
27
+ should "have subcommand short descriptions" do
28
+ output_matches /post\s*create a blog post/
29
+ output_matches /categories\s*do something with categories/
30
+ output_matches /help\s*get help for a specific command/
31
+ output_matches /list\s*list blog postings/
32
+ end
33
+
34
+ should "have a usage" do
35
+ output_matches /SYNOPSIS/i
36
+ output_matches /wordpress(\-help)? \[/
37
+ end
38
+
39
+ should "be able to ask for help about help"
40
+ end
41
+ end
42
+
43
+ context "and getting help as subcommand" do
44
+ # ["wordpress -h", "wordpress help"].each do |format|
45
+ ["wordpress help"].each do |format|
46
+ context "'#{format}'" do
47
+ should "get help on subcommand post"
48
+ end
49
+ end
50
+ end
51
+
52
+ context "with no options" do
53
+ setup { @stdout, @stderr = bin("wordpress") }
54
+
55
+ should "output the options" do
56
+ output_matches /Primary Options:/
57
+ end
58
+
59
+ should "have the test_primary option" do
60
+ output_matches /test_primary=>nil/
61
+ end
62
+ end
63
+ should "be able to require 'primary' and run just fine"
64
+ end
65
+
66
+ context "when running the subcommand" do
67
+ # should be the same for both formats
68
+ ["wordpress-post", "wordpress post"].each do |bin_format|
69
+ context "#{bin_format}" do
70
+
71
+ context "with no options" do
72
+ setup { @stdout, @stderr = bin("#{bin_format}") }
73
+ should "fail because title is required" do
74
+ output_matches /Error: option 'title' must be specified.\s*Try --help for help/m
75
+ end
76
+ end
77
+
78
+ context "with options" do
79
+ setup { @stdout, @stderr = bin("#{bin_format} --title='glendale'") }
80
+ should "be running the subcommand's run block" do
81
+ output_matches /Subcommand name/
82
+ end
83
+ should "have some default options" do
84
+ output_matches /version=>false/
85
+ output_matches /help=>false/
86
+ end
87
+ should "have some primary options" do
88
+ output_matches /test_primary=>nil/
89
+ end
90
+ should "have some local options" do
91
+ output_matches /title=>"glendale"/
92
+ output_matches /type=>"html"/
93
+ end
94
+ end
95
+
96
+ context "testing die statements" do
97
+ setup { @stdout, @stderr = bin("#{bin_format} --title='glendale' --type=yaml") }
98
+
99
+ should "die on invalid options" do
100
+ output_matches /argument \-\-type type must be one of \[html\|xhtml\|text\]/
101
+ end
102
+ end
103
+
104
+ end # end bin_format
105
+ end # end #each
106
+ end
107
+
108
+ ["wordpress help post", "wordpress post -h"].each do |format|
109
+ context "when calling '#{format}'" do
110
+
111
+ setup { @stdout, @stderr = bin(format) }
112
+ should "have a description" do
113
+ output_matches /create a blog post/
114
+ end
115
+
116
+ should "have the proper usage line" do
117
+ output_matches /SYNOPSIS\n\s*wordpress\-post/m
118
+ output_matches /\[--title\]/
119
+ end
120
+
121
+ should "have option flags" do
122
+ output_matches /\-\-title(.*)<s>/
123
+ end
124
+
125
+ should "have primary option flags" do
126
+ output_matches /\-\-test-primary(.*)<s>/
127
+ end
128
+
129
+ should "have default option flags" do
130
+ output_matches /\-\-verbose/
131
+ end
132
+
133
+ should "have trollop default option flags" do
134
+ output_matches /\-e, \-\-version/
135
+ end
136
+
137
+ should "have the correct binary name and short description" do
138
+ output_matches /NAME\n\s*wordpress\-post \- create a blog post/m
139
+ end
140
+
141
+ should "have a the primaries version string" do
142
+ output_matches /0\.0\.1 \(c\) 2009 Nate Murray - local/
143
+ end
144
+
145
+ should "have options" do
146
+ output_matches /Options/i
147
+
148
+ output_matches /\-b, \-\-blog=<s>/
149
+ output_matches /short name of the blog to use/
150
+
151
+ output_matches /-i, \-\-title=<s>/
152
+ output_matches /title for the post/
153
+ end
154
+
155
+ end
156
+ end
157
+
158
+ context "when running a bare primary" do
159
+ ["flickr -h", "flickr help"].each do |format|
160
+ context format do
161
+ setup { @stdout, @stderr = bin(format) }
162
+
163
+ should "have the name and short description" do
164
+ unless format == "flickr -h" # hmm
165
+ output_matches /NAME\n\s*flickr\-help \- get help for a specific command/m
166
+ end
167
+ end
168
+
169
+ should "have a local (not default) version string" do
170
+ output_matches /0\.0\.2 \(c\) 2009/
171
+ end
172
+ end
173
+ end
174
+ ["flickr-download -h", "flickr download -h"].each do |format|
175
+ context format do
176
+ setup { @stdout, @stderr = bin(format) }
177
+
178
+ should "match on usage" do
179
+ output_matches /SYNOPSIS\n\s*flickr\-download/m
180
+ end
181
+ end
182
+ end
183
+ end
184
+
185
+ end
@@ -0,0 +1,13 @@
1
+ class Test::Unit::TestCase
2
+ def output_should_match(regexp)
3
+ assert_match regexp, @stdout + @stderr
4
+ end
5
+ alias_method :output_matches, :output_should_match
6
+
7
+ def stdout_should_match(regexp)
8
+ assert_match regexp, @stdout
9
+ end
10
+ def stderr_should_match(regexp)
11
+ assert_match regexp, @stderr
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ begin require 'redgreen'; rescue LoadError; end
5
+ require 'open3'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ Dir[File.join(File.dirname(__FILE__), "shoulda_macros", "*.rb")].each {|f| require f}
10
+ ENV['NO_COLOR'] = "true"
11
+
12
+ require 'git-style-binary'
13
+ GitStyleBinary.run = true
14
+
15
+ class Test::Unit::TestCase
16
+ def fixtures_dir
17
+ File.join(File.dirname(__FILE__), "fixtures")
18
+ end
19
+ end
20
+
21
+ module RunsBinaryFixtures
22
+ # run the specified cmd returning the string values of [stdout,stderr]
23
+ def bin(cmd)
24
+ stdin, stdout, stderr = Open3.popen3("#{fixtures_dir}/#{cmd}")
25
+ [stdout.read, stderr.read]
26
+ end
27
+ end
28
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jashmenn-git-style-binaries
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Nate Murray
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: trollop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Ridiculously easy git-style binaries
36
+ email: nate@natemurray.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.markdown
43
+ files:
44
+ - README.markdown
45
+ - Rakefile
46
+ - VERSION.yml
47
+ - lib/ext/colorize.rb
48
+ - lib/ext/core.rb
49
+ - lib/git-style-binary.rb
50
+ - lib/git-style-binary/autorunner.rb
51
+ - lib/git-style-binary/command.rb
52
+ - lib/git-style-binary/commands/help.rb
53
+ - lib/git-style-binary/helpers/name_resolver.rb
54
+ - lib/git-style-binary/helpers/pager.rb
55
+ - lib/git-style-binary/parser.rb
56
+ - test/fixtures/flickr
57
+ - test/fixtures/flickr-download
58
+ - test/fixtures/wordpress
59
+ - test/fixtures/wordpress-categories
60
+ - test/fixtures/wordpress-list
61
+ - test/fixtures/wordpress-post
62
+ - test/git-style-binary/command_test.rb
63
+ - test/git_style_binary_test.rb
64
+ - test/running_binaries_test.rb
65
+ - test/shoulda_macros/matching_stdio.rb
66
+ - test/test_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/jashmenn/git-style-binaries
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.2.0
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Add git-style binaries to your project easily.
93
+ test_files:
94
+ - test/git-style-binary/command_test.rb
95
+ - test/git_style_binary_test.rb
96
+ - test/running_binaries_test.rb
97
+ - test/shoulda_macros/matching_stdio.rb
98
+ - test/test_helper.rb