Permalink
Browse files

cleanup/standardize key tests

  • Loading branch information...
1 parent efaa831 commit faf290ca3ba59c80589a5d197920463a9882ddeb @geemus geemus committed Apr 16, 2012
Showing with 49 additions and 21 deletions.
  1. +49 −21 spec/heroku/command/keys_spec.rb
@@ -8,31 +8,59 @@ module Heroku::Command
@keys.heroku.stub!(:user).and_return('joe')
end
- it "tries to find a key if no key filename is supplied" do
- Heroku::Auth.should_receive(:get_credentials)
- Heroku::Auth.should_receive(:associate_or_generate_ssh_key)
- @keys.add
- end
+ context("add") do
- it "adds a key from a specified keyfile path" do
- @keys.stub!(:args).and_return(['/my/key.pub'])
- @keys.should_not_receive(:find_key)
- File.should_receive(:read).with('/my/key.pub').and_return('ssh-rsa xyz')
- @keys.heroku.should_receive(:add_key).with('ssh-rsa xyz')
- @keys.add
- end
+ it "tries to find a key if no key filename is supplied" do
+ Heroku::Auth.should_receive(:get_credentials)
+ Heroku::Auth.should_receive(:ask).and_return("y")
+ Heroku::Auth.should_receive(:generate_ssh_key)
+ File.should_receive(:read).with('/.ssh/id_rsa.pub').and_return('ssh-rsa xyz')
+ stub_core.add_key("ssh-rsa xyz")
+ stderr, stdout = execute("keys:add")
+ stderr.should == ""
+ stdout.should == <<-STDOUT
+Could not find an existing public key.
+Would you like to generate one? [Yn] Generating new SSH public key.
+Uploading SSH public key /.ssh/id_rsa.pub
+STDOUT
+ end
+
+ it "adds a key from a specified keyfile path" do
+ stub_core.add_key('ssh-rsa xyz')
+ File.should_receive(:read).with('/my/key.pub').and_return('ssh-rsa xyz')
+ stderr, stdout = execute("keys:add /my/key.pub")
+ stderr.should == ""
+ stdout.should == <<-STDOUT
+Uploading SSH public key /my/key.pub
+STDOUT
+ end
- it "list keys, trimming the hex code for better display" do
- @keys.heroku.should_receive(:keys).and_return(["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pedro@heroku\n"])
- @keys.should_receive(:display).with('ssh-rsa AAAAB3NzaC...Fyoke4MQ== pedro@heroku')
- @keys.index
end
- it "list keys showing the whole key hex with --long" do
- @keys.stub(:options).and_return(:long => true)
- @keys.heroku.should_receive(:keys).and_return(["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pedro@heroku\n"])
- @keys.should_receive(:display).with("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pedro@heroku")
- @keys.index
+ context("index") do
+
+ before do
+ stub_core.keys.returns(["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pedro@heroku\n"])
+ end
+
+ it "list keys, trimming the hex code for better display" do
+ stderr, stdout = execute("keys")
+ stderr.should == ""
+ stdout.should == <<-STDOUT
+=== 1 key for user
+ssh-rsa AAAAB3NzaC...Fyoke4MQ== pedro@heroku
+STDOUT
+ end
+
+ it "list keys showing the whole key hex with --long" do
+ stderr, stdout = execute("keys --long")
+ stderr.should == ""
+ stdout.should == <<-STDOUT
+=== 1 key for user
+ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pedro@heroku
+STDOUT
+ end
+
end
end
end

0 comments on commit faf290c

Please sign in to comment.