Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix hub browse, rewrite its tests as cukes

Fixes #187
  • Loading branch information...
commit 18628f8f2ffd165e19ee52ebe21bca64bf9b4f20 1 parent ba23473
Mislav Marohnić mislav authored
95 features/browse.feature
View
@@ -0,0 +1,95 @@
+Feature: hub browse
+ Scenario: Project with owner
+ When I successfully run `hub browse mislav/dotfiles`
+ Then there should be no output
+ And "open https://github.com/mislav/dotfiles" should be run
+
+ Scenario: Project without owner
+ Given I am "mislav" on github.com
+ When I successfully run `hub browse dotfiles`
+ Then "open https://github.com/mislav/dotfiles" should be run
+
+ Scenario: Explicit project overrides current
+ Given I am in "git://github.com/josh/rails-behaviors.git" git repo
+ And I am "mislav" on github.com
+ When I successfully run `hub browse dotfiles`
+ Then "open https://github.com/mislav/dotfiles" should be run
+
+ Scenario: Project issues
+ When I successfully run `hub browse mislav/dotfiles issues`
+ Then "open https://github.com/mislav/dotfiles/issues" should be run
+
+ Scenario: Project wiki
+ When I successfully run `hub browse mislav/dotfiles wiki`
+ Then "open https://github.com/mislav/dotfiles/wiki" should be run
+
+ Scenario: Project commits on master
+ When I successfully run `hub browse mislav/dotfiles commits`
+ Then "open https://github.com/mislav/dotfiles/commits/master" should be run
+
+ Scenario: Specific commit in project
+ When I successfully run `hub browse mislav/dotfiles commit/4173c3b`
+ Then "open https://github.com/mislav/dotfiles/commit/4173c3b" should be run
+
+ Scenario: Output the URL instead of browse
+ When I successfully run `hub browse -u mislav/dotfiles`
+ Then the output should contain exactly "https://github.com/mislav/dotfiles\n"
+ But "open https://github.com/mislav/dotfiles" should not be run
+
+ Scenario: Current project
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ When I successfully run `hub browse`
+ Then there should be no output
+ And "open https://github.com/mislav/dotfiles" should be run
+
+ Scenario: Commit in current project
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ When I successfully run `hub browse -- commit/abcd1234`
+ Then "open https://github.com/mislav/dotfiles/commit/abcd1234" should be run
+
+ Scenario: Current branch
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ And I am on the "feature" branch with upstream "origin/experimental"
+ When I successfully run `hub browse`
+ Then "open https://github.com/mislav/dotfiles/tree/experimental" should be run
+
+ Scenario: Current branch, no tracking
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ And I am on the "feature" branch
+ When I successfully run `hub browse`
+ Then "open https://github.com/mislav/dotfiles" should be run
+
+ Scenario: Commits on current branch
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ And I am on the "feature" branch with upstream "origin/experimental"
+ When I successfully run `hub browse -- commits`
+ Then "open https://github.com/mislav/dotfiles/commits/experimental" should be run
+
+ Scenario: Complex branch
+ Given I am in "git://github.com/mislav/dotfiles.git" git repo
+ And I am on the "foo/bar" branch with upstream "origin/baz/qux"
+ When I successfully run `hub browse`
+ Then "open https://github.com/mislav/dotfiles/tree/baz/qux" should be run
+
+ Scenario: Wiki repo
+ Given I am in "git://github.com/defunkt/hub.wiki.git" git repo
+ When I successfully run `hub browse`
+ Then "open https://github.com/defunkt/hub/wiki" should be run
+
+ Scenario: Wiki commits
+ Given I am in "git://github.com/defunkt/hub.wiki.git" git repo
+ When I successfully run `hub browse -- commits`
+ Then "open https://github.com/defunkt/hub/wiki/_history" should be run
+
+ Scenario: Wiki pages
+ Given I am in "git://github.com/defunkt/hub.wiki.git" git repo
+ When I successfully run `hub browse -- pages`
+ Then "open https://github.com/defunkt/hub/wiki/_pages" should be run
+
+ Scenario: Deprecated -p flag
+ When I successfully run `hub browse -p defunkt/hub`
+ Then the stderr should contain exactly:
+ """
+ Warning: the `-p` flag has no effect anymore\n
+ """
+ But "open https://github.com/defunkt/hub" should be run
23 features/steps.rb
View
@@ -34,8 +34,13 @@
end
Given /^I am in "([^"]*)" git repo$/ do |dir_name|
+ if dir_name.include? '://'
+ origin_url = dir_name
+ dir_name = File.basename origin_url, '.git'
+ end
step %(a git repo in "#{dir_name}")
step %(I cd to "#{dir_name}")
+ step %(the "origin" remote has url "#{origin_url}") if origin_url
end
Given /^a git repo in "([^"]*)"$/ do |dir_name|
@@ -52,6 +57,18 @@
run_silent %(git reset --quiet --hard HEAD^)
end
+Given /^I am on the "([^"]+)" branch(?: with upstream "([^"]+)")?$/ do |name, upstream|
+ run_silent %(git commit --quiet --allow-empty --allow-empty-message -m '')
+ if upstream
+ full_upstream = ".git/refs/remotes/#{upstream}"
+ in_current_dir do
+ FileUtils.mkdir_p File.dirname(full_upstream)
+ FileUtils.cp '.git/refs/heads/master', full_upstream
+ end
+ end
+ run_silent %(git checkout --quiet -B #{name} --track #{upstream})
+end
+
Given /^the current dir is not a repo$/ do
in_current_dir do
FileUtils.rm_rf '.git'
@@ -66,6 +83,12 @@
set_env 'HUB_TEST_HOST', "127.0.0.1:#{@server.port}"
end
+Then /^shell$/ do
+ in_current_dir do
+ system '/bin/bash -i'
+ end
+end
+
Then /^"([^"]*)" should be run$/ do |cmd|
assert_command_run cmd
end
2  features/support/fakebin/open
View
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo open "$@" >> "$HOME"/.history
11 lib/hub/context.rb
View
@@ -98,7 +98,7 @@ def local_repo(fatal = true)
end
repo_methods = [
- :current_branch, :master_branch,
+ :current_branch,
:current_project, :upstream_project,
:repo_owner, :repo_host,
:remotes, :remotes_group, :origin_remote
@@ -107,6 +107,15 @@ def local_repo(fatal = true)
def_delegators :local_repo, *repo_methods
private :repo_name, *repo_methods
+ def master_branch
+ if local_repo(false)
+ local_repo.master_branch
+ else
+ # FIXME: duplicates functionality of LocalRepo#master_branch
+ Branch.new nil, 'refs/heads/master'
+ end
+ end
+
class LocalRepo < Struct.new(:git_reader, :dir)
include GitReaderMethods
106 test/hub_test.rb
View
@@ -572,112 +572,6 @@ def test_hub_compare_url
"echo https://github.com/defunkt/hub/compare/1.0...1.1"
end
- def test_hub_browse
- assert_command "browse mojombo/bert", "open https://github.com/mojombo/bert"
- end
-
- def test_hub_browse_commit
- assert_command "browse mojombo/bert commit/5d5582", "open https://github.com/mojombo/bert/commit/5d5582"
- end
-
- def test_hub_browse_tracking_nothing
- stub_tracking_nothing
- assert_command "browse mojombo/bert", "open https://github.com/mojombo/bert"
- end
-
- def test_hub_browse_url
- assert_command "browse -u mojombo/bert", "echo https://github.com/mojombo/bert"
- end
-
- def test_hub_browse_self
- assert_command "browse resque", "open https://github.com/tpw/resque"
- end
-
- def test_hub_browse_subpage
- assert_command "browse resque commits",
- "open https://github.com/tpw/resque/commits/master"
- assert_command "browse resque issues",
- "open https://github.com/tpw/resque/issues"
- assert_command "browse resque wiki",
- "open https://github.com/tpw/resque/wiki"
- end
-
- def test_hub_browse_on_branch
- stub_branch('refs/heads/feature')
- stub_tracking('feature', 'mislav', 'experimental')
-
- assert_command "browse resque", "open https://github.com/tpw/resque"
- assert_command "browse resque commits",
- "open https://github.com/tpw/resque/commits/master"
-
- assert_command "browse",
- "open https://github.com/mislav/hub/tree/experimental"
- assert_command "browse -- tree",
- "open https://github.com/mislav/hub/tree/experimental"
- assert_command "browse -- commits",
- "open https://github.com/mislav/hub/commits/experimental"
- end
-
- def test_hub_browse_on_complex_branch
- stub_branch('refs/heads/feature/foo')
- stub_tracking('feature/foo', 'mislav', 'feature/bar')
-
- assert_command 'browse',
- 'open https://github.com/mislav/hub/tree/feature/bar'
- end
-
- def test_hub_browse_no_branch
- stub_branch(nil)
- assert_command 'browse', 'open https://github.com/defunkt/hub'
- end
-
- def test_hub_browse_current
- assert_command "browse", "open https://github.com/defunkt/hub"
- assert_command "browse --", "open https://github.com/defunkt/hub"
- end
-
- def test_hub_browse_current_https_uri
- stub_repo_url "https://github.com/defunkt/hub"
- assert_command "browse", "open https://github.com/defunkt/hub"
- end
-
- def test_hub_browse_commit_from_current
- assert_command "browse -- commit/6616e4", "open https://github.com/defunkt/hub/commit/6616e4"
- end
-
- def test_hub_browse_no_tracking
- stub_tracking_nothing
- assert_command "browse", "open https://github.com/defunkt/hub"
- end
-
- def test_hub_browse_no_tracking_on_branch
- stub_branch('refs/heads/feature')
- stub_tracking_nothing('feature')
- assert_command "browse", "open https://github.com/defunkt/hub"
- end
-
- def test_hub_browse_current_wiki
- stub_repo_url 'git://github.com/defunkt/hub.wiki.git'
-
- assert_command "browse", "open https://github.com/defunkt/hub/wiki"
- assert_command "browse -- wiki", "open https://github.com/defunkt/hub/wiki"
- assert_command "browse -- commits", "open https://github.com/defunkt/hub/wiki/_history"
- assert_command "browse -- pages", "open https://github.com/defunkt/hub/wiki/_pages"
- end
-
- def test_hub_browse_current_subpage
- assert_command "browse -- network",
- "open https://github.com/defunkt/hub/network"
- assert_command "browse -- anything/everything",
- "open https://github.com/defunkt/hub/anything/everything"
- end
-
- def test_hub_browse_deprecated_private
- with_browser_env('echo') do
- assert_includes "Warning: the `-p` flag has no effect anymore\n", hub("browse -p defunkt/hub")
- end
- end
-
def test_hub_browse_no_repo
stub_repo_url(nil)
assert_equal "Usage: hub browse [<USER>/]<REPOSITORY>\n", hub("browse")
Please sign in to comment.
Something went wrong with that request. Please try again.