spec/command/init_spec.rb in conjur-cli-4.14.0 vs spec/command/init_spec.rb in conjur-cli-4.15.0
- old
+ new
@@ -47,32 +47,32 @@
end
end
context logged_in: false do
before {
- File.stub(:exists?).and_return false
+ allow(File).to receive(:exists?).and_return false
}
context "auto-fetching fingerprint" do
before {
- HighLine.any_instance.stub(:ask).with("Enter the hostname (and optional port) of your Conjur endpoint: ").and_return "the-host"
- Conjur::Command::Init.stub get_certificate: ["the-fingerprint", nil]
- HighLine.any_instance.stub(:ask).with(/^Trust this certificate/).and_return "yes"
+ allow_any_instance_of(HighLine).to receive(:ask).with("Enter the hostname (and optional port) of your Conjur endpoint: ").and_return "the-host"
+ allow(Conjur::Command::Init).to receive_messages get_certificate: ["the-fingerprint", nil]
+ allow_any_instance_of(HighLine).to receive(:ask).with(/^Trust this certificate/).and_return "yes"
}
describe_command 'init' do
it "fetches account and writes config file" do
# Stub hostname
- Conjur::Core::API.should_receive(:info).and_return "account" => "the-account"
- File.should_receive(:open)
+ expect(Conjur::Core::API).to receive(:info).and_return "account" => "the-account"
+ expect(File).to receive(:open)
invoke
end
end
describe_command 'init -a the-account' do
it "writes config file" do
- File.should_receive(:open)
+ expect(File).to receive(:open)
invoke
end
end
end
@@ -98,11 +98,11 @@
# end
# end
describe_command 'init -a the-account -h localhost -c the-cert' do
it "writes config and cert files" do
- File.should_receive(:open).twice
+ expect(File).to receive(:open).twice
invoke
end
end
context "in a temp dir" do
@@ -135,20 +135,29 @@
end
context "default behavior" do
describe_command "init -a the-account -h localhost -c the-cert" do
before(:each) {
- File.stub(:expand_path).and_call_original
- File.stub(:expand_path).with('~/.conjurrc').and_return("#{tmpdir}/.conjurrc")
+ allow(File).to receive(:expand_path).and_call_original
+ allow(File).to receive(:expand_path).with('~/.conjurrc').and_return("#{tmpdir}/.conjurrc")
}
include_examples "check config and cert files", "#{tmpdir}/.conjurrc"
+ it "prints the config file location" do
+ expect { invoke }.to write("Wrote configuration to #{tmpdir}/.conjurrc")
+ end
+ it "prints the cert location" do
+ expect { invoke }.to write("Wrote certificate to #{tmpdir}/conjur-the-account.pem")
+ end
end
end
context "explicit output file" do
describe_command "init -f #{tmpdir}/.conjurrc2 -a the-account -h localhost -c the-cert" do
include_examples "check config and cert files", File.join(tmpdir, ".conjurrc2")
+ it "prints the config file location" do
+ expect { invoke }.to write("Wrote configuration to #{tmpdir}/.conjurrc2")
+ end
end
end
context "to CONJURRC" do
describe_command "init -a the-account -h localhost -c the-cert" do