spec/shelly/cli/main_spec.rb in shelly-0.4.21 vs spec/shelly/cli/main_spec.rb in shelly-0.4.22
- old
+ new
@@ -152,17 +152,16 @@
}.should raise_error(SystemExit)
end
end
end
- describe "#login" do
- let(:key_path) { File.expand_path("~/.ssh/id_rsa.pub") }
-
+ shared_examples "login" do
before do
- user.ssh_key.stub(:upload => nil, :uploaded? => false)
+ Shelly::SshKey.any_instance.stub(:upload => nil, :uploaded? => false)
FileUtils.mkdir_p("~/.ssh")
File.open(key_path, "w") { |f| f << "ssh-rsa AAAAB3NzaC1" }
+ @main.options = main_options
@client.stub(:apps).and_return([
{"code_name" => "abc", "state" => "running",
"state_description" => "running"},
{"code_name" => "fooo", "state" => "no_code",
"state_description" => "turned off (no code pushed)"},])
@@ -185,12 +184,19 @@
fake_stdin(["secret"]) do
invoke(@main, :login, "megan@example.com")
end
end
+ it "should accept given path to specific key as parameter" do
+ $stdout.should_receive(:puts).with(green "Login successful")
+ fake_stdin(["secret"]) do
+ invoke(@main, :login, "megan@example.com")
+ end
+ end
+
it "should upload user's public SSH key" do
- user.ssh_key.should_receive(:upload)
+ Shelly::SshKey.any_instance.should_receive(:upload)
$stdout.should_receive(:puts).with("Uploading your public SSH key from #{key_path}")
fake_stdin(["megan@example.com", "secret"]) do
invoke(@main, :login)
end
end
@@ -204,11 +210,11 @@
end
end
context "SSH key already uploaded" do
it "should display message to user" do
- user.ssh_key.stub(:uploaded? => true)
+ Shelly::SshKey.any_instance.stub(:uploaded? => true)
$stdout.should_receive(:puts).with("Your SSH key from #{key_path} is already uploaded")
fake_stdin(["megan@example.com", "secret"]) do
invoke(@main, :login)
end
end
@@ -217,11 +223,11 @@
context "SSH key taken by other user" do
it "should logout user" do
body = {"message" => "Validation Failed",
"errors" => [["fingerprint", "already exists. This SSH key is already in use"]]}
ex = Shelly::Client::ValidationException.new(body)
- user.ssh_key.stub(:upload).and_raise(ex)
+ Shelly::SshKey.any_instance.stub(:upload).and_raise(ex)
user.should_receive(:logout)
$stdout.should_receive(:puts).with(red "Fingerprint already exists. This SSH key is already in use")
lambda {
fake_stdin(["megan@example.com", "secret"]) do
invoke(@main, :login)
@@ -271,9 +277,25 @@
fake_stdin(["megan@example.com", "secret"]) do
invoke(@main, :login)
end
}.should raise_error(SystemExit)
end
+ end
+ end
+
+ describe "#login" do
+ context "with default keys in place" do
+ let(:key_path) { File.expand_path("~/.ssh/id_rsa.pub") }
+ let(:main_options) { {} }
+
+ it_behaves_like "login"
+ end
+
+ context "with given path to specific key" do
+ let(:key_path) { File.expand_path("~/.ssh/specific.pub") }
+ let(:main_options) { {:key => "~/.ssh/specific.pub"} }
+
+ it_behaves_like "login"
end
end
describe "#add" do
before do