From 5d26288b2c9cfd5ce6cb92fd0363621fba87d6a3 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 25 Jul 2014 14:24:07 -0600 Subject: add a usage command. --- lib/tfa.rb | 1 + lib/tfa/console.rb | 2 ++ lib/tfa/usage_command.rb | 15 +++++++++++++++ spec/lib/console_spec.rb | 26 +++++++++++++++++++------- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 lib/tfa/usage_command.rb diff --git a/lib/tfa.rb b/lib/tfa.rb index 17a6f02..5138e7b 100644 --- a/lib/tfa.rb +++ b/lib/tfa.rb @@ -4,4 +4,5 @@ require "tfa/version" require "tfa/add_command" require "tfa/show_command" require "tfa/totp_command" +require "tfa/usage_command" require "tfa/console" diff --git a/lib/tfa/console.rb b/lib/tfa/console.rb index 3d42985..f0bf3eb 100644 --- a/lib/tfa/console.rb +++ b/lib/tfa/console.rb @@ -19,6 +19,8 @@ module TFA ShowCommand.new(@storage) when "totp" TotpCommand.new(@storage) + else + UsageCommand.new(@storage) end end end diff --git a/lib/tfa/usage_command.rb b/lib/tfa/usage_command.rb new file mode 100644 index 0000000..3dd5abd --- /dev/null +++ b/lib/tfa/usage_command.rb @@ -0,0 +1,15 @@ +module TFA + class UsageCommand + def initialize(storage) + end + + def run(arguments) + <<-MESSAGE +Try: + - tfa add develoment + - tfa show development + - tfa totp development + MESSAGE + end + end +end diff --git a/spec/lib/console_spec.rb b/spec/lib/console_spec.rb index 90098d0..966ca9a 100644 --- a/spec/lib/console_spec.rb +++ b/spec/lib/console_spec.rb @@ -3,14 +3,26 @@ module TFA subject { Console.new('testing') } let(:secret) { ::ROTP::Base32.random_base32 } - it "saves a new secret" do - subject.run(["add", "development", secret]) - expect(subject.run(["show", "development"])).to eql(secret) - end + describe "#run" do + context "when adding a key" do + it "saves a new secret" do + subject.run(["add", "development", secret]) + expect(subject.run(["show", "development"])).to eql(secret) + end + end + + context "when getting a one time password" do + it "creates a totp for a certain key" do + subject.run(["add", "development", secret]) + expect(subject.run(["totp", "development"])).to_not be_nil + end + end - it "creates a totp for a certain key" do - subject.run(["add", "development", secret]) - expect(subject.run(["totp", "development"])).to_not be_nil + context "when running an unknown command" do + it "returns the usage" do + expect(subject.run([])).to_not be_nil + end + end end end end -- cgit v1.2.3