Commit 5d26288
Changed files (4)
lib
spec
lib
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
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 <secret>
+ - tfa show development
+ - tfa totp development
+ MESSAGE
+ end
+ end
+end
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"
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