Permalink
Browse files

Add gist binary

Implement home command and homepage/homepage_for helper methods
  • Loading branch information...
1 parent c1a6f99 commit 9582b9b59efe1c0cf4ceb71766596c08cabb845c @kballard kballard committed Jul 21, 2008
Showing with 85 additions and 0 deletions.
  1. +7 −0 Manifest
  2. +1 −0 Rakefile
  3. +6 −0 bin/gist
  4. +9 −0 commands/gist/commands.rb
  5. +7 −0 commands/gist/helpers.rb
  6. +18 −0 spec/gist/command_spec.rb
  7. +26 −0 spec/gist/helper_spec.rb
  8. +11 −0 spec/gist/spec_helper.rb
View
@@ -1,6 +1,10 @@
+bin/gist
bin/github
+commands/gist/commands.rb
+commands/gist/helpers.rb
commands/github/commands.rb
commands/github/helpers.rb
+commands/helpers.rb
github-gem.gemspec
lib/extensions.rb
lib/github/command.rb
@@ -9,6 +13,9 @@ lib/github.rb
LICENSE
Manifest
README
+spec/gist/command_spec.rb
+spec/gist/helper_spec.rb
+spec/gist/spec_helper.rb
spec/github/command_spec.rb
spec/github/helper_spec.rb
spec/github/spec_helper.rb
View
@@ -49,4 +49,5 @@ begin
spec_task
spec_task 'github'
+ spec_task 'gist'
end
View
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../lib/github'
+
+GitHub.command_name = 'gist'
+GitHub.activate ARGV
@@ -0,0 +1,9 @@
+desc "Open the given user's gist.github.com homepage in the web browser"
+command :home do |user|
+ if user
+ url = helper.homepage_for(user)
+ else
+ url = helper.homepage
+ end
+ helper.open url
+end
View
@@ -0,0 +1,7 @@
+helper :homepage_for do |user|
+ "http://gist.github.com/#{user}"
+end
+
+helper :homepage do
+ "http://gist.github.com"
+end
View
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "github" do
+ include CommandRunner
+
+ # -- home --
+ specify "home should open the gist homepage" do
+ running :home do
+ @helper.should_receive(:open).with("http://gist.github.com")
+ end
+ end
+
+ specify "home defunkt should open defunkt's gist homepage" do
+ running :home, "defunkt" do
+ @helper.should_receive(:open).with("http://gist.github.com/defunkt")
+ end
+ end
+end
View
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe GitHub::Helper do
+ include SetupMethods
+
+ def self.helper(name, &block)
+ HelperRunner.new(self, name).run(&block)
+ end
+
+ before(:each) do
+ @helper = GitHub::Helper.new
+ end
+
+ helper :homepage do
+ it "should return the gist homepage" do
+ @helper.homepage.should == "http://gist.github.com"
+ end
+ end
+
+ helper :homepage_for do
+ it "should return the gist homepage for the given user" do
+ @helper.homepage_for("kballard").should == "http://gist.github.com/kballard"
+ @helper.homepage_for("defunkt").should == "http://gist.github.com/defunkt"
+ end
+ end
+end
View
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + "/../spec_helper"
+
+Spec::Runner.configure do |configuration|
+ configuration.append_before(:all) do
+ GitHub.command_name = 'gist'
+ module GitHub
+ load 'helpers.rb'
+ load 'commands.rb'
+ end
+ end
+end

0 comments on commit 9582b9b

Please sign in to comment.