Permalink
Browse files

login! accepts credentials as params

  • Loading branch information...
1 parent aa42c12 commit 69969e81da4eed2594d50442858b612a2d51f33b @weilu weilu committed May 19, 2013
Showing with 14 additions and 3 deletions.
  1. +3 −3 lib/gist.rb
  2. +11 −0 spec/ghe_spec.rb
View
@@ -138,12 +138,12 @@ def shorten(url)
#
# @raise [Gist::Error] if something went wrong
# @see http://developer.github.com/v3/oauth/
- def login!
+ def login! credentials={}
puts "Obtaining OAuth2 access_token from github."
print "GitHub username: "
- username = $stdin.gets.strip
+ username = credentials[:username] || $stdin.gets.strip
print "GitHub password: "
- password = begin
+ password = credentials[:password] || begin
`stty -echo` rescue nil
$stdin.gets.strip
ensure
View
@@ -58,6 +58,17 @@
assert_requested(:post, /#{MOCK_AUTHZ_GHE_URL}authorizations/)
end
+
+ context "when credentials are passed in" do
+
+ it "uses them" do
+ $stdin = StringIO.new "#{MOCK_USER}_wrong\n#{MOCK_PASSWORD}_wrong\n"
+ Gist.login! username: MOCK_USER, password: MOCK_PASSWORD
+
+ assert_requested(:post, /#{MOCK_AUTHZ_GITHUB_URL}authorizations/)
+ end
+
+ end
end
describe :gist do

0 comments on commit 69969e8

Please sign in to comment.