Skip to content

Commit

Permalink
refactored the UI/commands specs into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Nov 5, 2009
1 parent 24e7a13 commit 3a12586
Show file tree
Hide file tree
Showing 15 changed files with 587 additions and 524 deletions.
15 changes: 14 additions & 1 deletion Manifest
Expand Up @@ -16,9 +16,22 @@ lib/github/helper.rb
lib/github/ui.rb lib/github/ui.rb
setup.rb setup.rb
spec/command_spec.rb spec/command_spec.rb
spec/commands/command_browse_spec.rb
spec/commands/command_clone_spec.rb
spec/commands/command_create-from-local_spec.rb
spec/commands/command_fetch_spec.rb
spec/commands/command_fork_spec.rb
spec/commands/command_helper.rb
spec/commands/command_home_spec.rb
spec/commands/command_info_spec.rb
spec/commands/command_network_spec.rb
spec/commands/command_pull-request_spec.rb
spec/commands/command_pull_spec.rb
spec/commands/command_search_spec.rb
spec/commands/command_track_spec.rb
spec/commands_spec.rb
spec/extensions_spec.rb spec/extensions_spec.rb
spec/github_spec.rb spec/github_spec.rb
spec/helper_spec.rb spec/helper_spec.rb
spec/spec_helper.rb spec/spec_helper.rb
spec/ui_spec.rb
spec/windoze_spec.rb spec/windoze_spec.rb
36 changes: 36 additions & 0 deletions spec/commands/command_browse_spec.rb
@@ -0,0 +1,36 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github browse" do
include CommandHelper

specify "browse should open the project home page with the current branch" do
running :browse do
setup_url_for
setup_user_and_branch("user", "test-branch")
@helper.should_receive(:open).once.with("https://github.com/user/project/tree/test-branch")
end
end

specify "browse pending should open the project home page with the 'pending' branch" do
running :browse, "pending" do
setup_url_for
setup_user_and_branch("user", "test-branch")
@helper.should_receive(:open).once.with("https://github.com/user/project/tree/pending")
end
end

specify "browse defunkt pending should open the home page of defunkt's fork with the 'pending' branch" do
running :browse, "defunkt", "pending" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
end
end

specify "browse defunkt/pending should open the home page of defunkt's fork with the 'pending' branch" do
running :browse, "defunkt/pending" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
end
end
end
87 changes: 87 additions & 0 deletions spec/commands/command_clone_spec.rb
@@ -0,0 +1,87 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github clone" do
include CommandHelper

# -- clone --
specify "clone should die with no args" do
running :clone do
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
self.should raise_error(RuntimeError)
end
end

specify "clone should fall through with just one arg" do
running :clone, "git://git.kernel.org/linux.git" do
@command.should_receive(:git_exec).with("clone git://git.kernel.org/linux.git")
end
end

specify "clone defunkt github-gem should clone the repo" do
running :clone, "defunkt", "github-gem" do
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
end
end

specify "clone defunkt/github-gem should clone the repo" do
running :clone, "defunkt/github-gem" do
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
end
end

specify "clone --ssh defunkt github-gem should clone the repo using the private URL" do
running :clone, "--ssh", "defunkt", "github-gem" do
@command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git")
end
end

specify "clone defunkt github-gem repo should clone the repo into the dir 'repo'" do
running :clone, "defunkt", "github-gem", "repo" do
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
end
end

specify "clone defunkt/github-gem repo should clone the repo into the dir 'repo'" do
running :clone, "defunkt/github-gem", "repo" do
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
end
end

specify "clone --ssh defunkt github-gem repo should clone the repo using the private URL into the dir 'repo'" do
running :clone, "--ssh", "defunkt", "github-gem", "repo" do
@command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git repo")
end
end

specify "clone defunkt/github-gem repo should clone the repo into the dir 'repo'" do
running :clone, "defunkt/github-gem", "repo" do
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
end
end

specify "clone a selected repo after showing search results" do
running :clone, "--search", "github-gem" do
json = StringIO.new '{"repositories":[' +
'{"name":"github-gem","size":300,"followers":499,"username":"defunkt","language":"Ruby","fork":false,"id":"repo-1653","type":"repo","pushed":"2008-12-04T03:14:00Z","forks":59,"description":"The official `github` command line helper for simplifying your GitHub experience.","score":3.4152448,"created":"2008-02-28T09:35:34Z"},' +
'{"name":"github-gem-builder","size":76,"followers":26,"username":"pjhyett","language":"Ruby","fork":false,"id":"repo-67489","type":"repo","pushed":"2008-11-04T04:54:57Z","forks":3,"description":"The scripts used to build RubyGems on GitHub","score":3.4152448,"created":"2008-10-24T22:29:32Z"}' +
']}'
json.rewind
question_list = <<-LIST.gsub(/^ /, '').split("\n").compact
defunkt/github-gem # The official `github` command line helper for simplifying your GitHub experience.
pjhyett/github-gem-builder # The scripts used to build RubyGems on GitHub
LIST
@command.should_receive(:open).with("http://github.com/api/v1/json/search/github-gem").and_return(json)
GitHub::UI.should_receive(:display_select_list).with(question_list).
and_return("defunkt/github-gem")
@command.should_receive(:current_user?).and_return(nil)
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
end
end

end
7 changes: 7 additions & 0 deletions spec/commands/command_create-from-local_spec.rb
@@ -0,0 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github create-from-local" do
include CommandHelper

end
56 changes: 56 additions & 0 deletions spec/commands/command_fetch_spec.rb
@@ -0,0 +1,56 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github fetch" do
include CommandHelper

specify "fetch should die with no args" do
running :fetch do
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
self.should raise_error(RuntimeError)
end
end

specify "fetch defunkt should start tracking defunkt if they're not already tracked" do
running :fetch, "defunkt" do
setup_remote(:origin, :user => "user", :ssh => true)
setup_remote(:external, :url => "home:/path/to/project.git")
GitHub.should_receive(:invoke).with(:track, "defunkt").and_return { raise "Tracked" }
self.should raise_error("Tracked")
end
end

specify "fetch defunkt should create defunkt/master and fetch from the defunkt remote" do
running :fetch, "defunkt" do
setup_remote(:defunkt)
@helper.should_receive(:branch_dirty?).and_return false
@command.should_receive(:git).with("fetch defunkt master:refs/remotes/defunkt/master").ordered
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master refs/remotes/defunkt/master").ordered
@command.should_receive(:git_exec).with("checkout defunkt/master").ordered
stdout.should == "Fetching defunkt/master\n"
end
end

specify "fetch defunkt/wip should create defunkt/wip and fetch from wip branch on defunkt remote" do
running :fetch, "defunkt/wip" do
setup_remote(:defunkt, :remote_branches => ["master", "wip"])
@helper.should_receive(:branch_dirty?).and_return false
@command.should_receive(:git).with("fetch defunkt wip:refs/remotes/defunkt/wip").ordered
@command.should_receive(:git).with("update-ref refs/heads/defunkt/wip refs/remotes/defunkt/wip").ordered
@command.should_receive(:git_exec).with("checkout defunkt/wip").ordered
stdout.should == "Fetching defunkt/wip\n"
end
end

specify "fetch --merge defunkt should fetch from defunkt remote into current branch" do
running :fetch, "--merge", "defunkt" do
setup_remote(:defunkt)
@helper.should_receive(:branch_dirty?).and_return false
@command.should_receive(:git).with("fetch defunkt master:refs/remotes/defunkt/master").ordered
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master refs/remotes/defunkt/master").ordered
@command.should_receive(:git_exec).with("checkout defunkt/master").ordered
stdout.should == "Fetching defunkt/master\n"
end
end

end
44 changes: 44 additions & 0 deletions spec/commands/command_fork_spec.rb
@@ -0,0 +1,44 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github fork" do
include CommandHelper

specify "fork should print out help" do
running :fork do
@helper.should_receive(:remotes).and_return({})
@command.should_receive(:die).with("Specify a user/project to fork, or run from within a repo").and_return { raise "Died" }
self.should raise_error(RuntimeError)
end
end

specify "fork this repo should create github fork and replace origin remote" do
running :fork do
setup_github_token
setup_url_for "origin", "defunkt", "github-gem"
setup_remote "origin", :user => "defunkt", :project => "github-gem"
setup_user_and_branch
@command.should_receive(:sh).with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
@command.should_receive(:git, "config remote.origin.url git@github.com/drnic/github-gem.git")
stdout.should == "defunkt/github-gem forked\n"
end
end

specify "fork a user/project repo" do
running :fork, "defunkt/github-gem" do
setup_github_token
@command.should_receive(:sh).with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
@command.should_receive(:git_exec, "clone git://github.com/defunkt/github-gem.git")
stdout.should == "Giving GitHub a moment to create the fork...\n"
end
end

specify "fork a user project repo" do
running :fork, "defunkt", "github-gem" do
setup_github_token
@command.should_receive("sh").with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
@command.should_receive(:git_exec, "clone git://github.com/defunkt/github-gem.git")
stdout.should == "Giving GitHub a moment to create the fork...\n"
end
end
end
2 changes: 1 addition & 1 deletion spec/commands/command_home_spec.rb
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper' require File.dirname(__FILE__) + '/command_helper'


describe "github home" do describe "github home" do
Expand Down
23 changes: 23 additions & 0 deletions spec/commands/command_info_spec.rb
@@ -0,0 +1,23 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github info" do
include CommandHelper

specify "info should show info for this project" do
running :info do
setup_url_for
setup_remote(:origin, :user => "user", :ssh => true)
setup_remote(:defunkt)
setup_remote(:external, :url => "home:/path/to/project.git")
stdout.should == <<-EOF
== Info for project
You are user
Currently tracking:
- defunkt (as defunkt)
- home:/path/to/project.git (as external)
- user (as origin)
EOF
end
end
end
21 changes: 21 additions & 0 deletions spec/commands/command_network_spec.rb
@@ -0,0 +1,21 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github network" do
include CommandHelper

specify "network should open the network page for this repo" do
running :network, 'web' do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/user/project/network")
end
end

specify "network defunkt should open the network page for defunkt's fork" do
running :network, 'web', "defunkt" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/network")
end
end

end
51 changes: 51 additions & 0 deletions spec/commands/command_pull-request_spec.rb
@@ -0,0 +1,51 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.dirname(__FILE__) + '/command_helper'

describe "github pull-request" do
include CommandHelper

specify "pull-request should die with no args" do
running :'pull-request' do
setup_url_for
@command.should_receive(:die).with("Specify a user for the pull request").and_return { raise "Died" }
self.should raise_error(RuntimeError)
end
end

specify "pull-request user should track user if untracked" do
running :'pull-request', "user" do
setup_url_for
setup_remote :origin, :user => "kballard"
setup_remote :defunkt
GitHub.should_receive(:invoke).with(:track, "user").and_return { raise "Tracked" }
self.should raise_error("Tracked")
end
end

specify "pull-request user/branch should generate a pull request" do
running :'pull-request', "user/branch" do
setup_url_for
setup_remote :origin, :user => "kballard"
setup_remote :user
@command.should_receive(:git_exec).with("request-pull user/branch origin")
end
end

specify "pull-request user should generate a pull request with branch master" do
running :'pull-request', "user" do
setup_url_for
setup_remote :origin, :user => "kballard"
setup_remote :user
@command.should_receive(:git_exec).with("request-pull user/master origin")
end
end

specify "pull-request user branch should generate a pull request" do
running:'pull-request', "user", "branch" do
setup_url_for
setup_remote :origin, :user => "kballard"
setup_remote :user
@command.should_receive(:git_exec).with("request-pull user/branch origin")
end
end
end

0 comments on commit 3a12586

Please sign in to comment.