diff options
| author | mokha <mokha@cisco.com> | 2018-03-06 09:24:55 -0700 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-03-06 09:24:55 -0700 |
| commit | f817feb86752f5de7c3d02d48a0ea5aca0506d80 (patch) | |
| tree | 05f5e0f9c19c7eea99e8ba8ac5d7683091210967 | |
| parent | 2213fa732a8a45b187fbae1299fd515c2edde478 (diff) | |
add specs for some error cases.
| -rw-r--r-- | lib/saml/kit/cli/commands/metadata.rb | 3 | ||||
| -rw-r--r-- | spec/saml/kit/cli/commands/metadata_spec.rb | 44 |
2 files changed, 29 insertions, 18 deletions
diff --git a/lib/saml/kit/cli/commands/metadata.rb b/lib/saml/kit/cli/commands/metadata.rb index 826e39d..6701d70 100644 --- a/lib/saml/kit/cli/commands/metadata.rb +++ b/lib/saml/kit/cli/commands/metadata.rb @@ -10,6 +10,9 @@ module Saml desc 'list', "List each of the registered entityId's" def list + if registry.count.zero? + say "Please register metadata using `saml-kit metadata register <url>`" + end registry.each do |x| say x.entity_id, :green end diff --git a/spec/saml/kit/cli/commands/metadata_spec.rb b/spec/saml/kit/cli/commands/metadata_spec.rb index 44c6bf8..a654922 100644 --- a/spec/saml/kit/cli/commands/metadata_spec.rb +++ b/spec/saml/kit/cli/commands/metadata_spec.rb @@ -1,13 +1,13 @@ RSpec.describe Saml::Kit::Cli::Commands::Metadata do let(:entity_id) { 'https://saml-kit-proof.herokuapp.com/metadata' } + let(:env) { "SAMLKITRC=#{tempfile}" } + let(:tempfile) { Tempfile.new('saml-kit').path } + + after { File.unlink(tempfile) if File.exist?(tempfile) } describe "#register" do - let(:env) { "SAMLKITRC=#{tempfile}" } - let(:tempfile) { Tempfile.new('saml-kit').path } let(:command) { "metadata register #{entity_id}" } - after { File.unlink(tempfile) } - specify { expect(status).to be_success } specify { expect(output).to include(entity_id) } specify { expect(output).to match(/EntityDescriptor/) } @@ -15,26 +15,34 @@ RSpec.describe Saml::Kit::Cli::Commands::Metadata do end describe "#show" do - before :each do - env = "SAMLKITRC=#{Tempfile.new('saml-kit').path}" - execute("metadata register #{entity_id}", env: env) - end - let(:command) { "metadata show #{entity_id}" } - specify { expect(status).to be_success } - specify { expect(output).to include(entity_id) } - end + context "when the entity_id is registered" do + before { execute("metadata register #{entity_id}") } - describe "#list" do - before :each do - env = "SAMLKITRC=#{Tempfile.new('saml-kit').path}" - execute("metadata register #{entity_id}", env: env) + specify { expect(status).to be_success } + specify { expect(output).to include(entity_id) } + end + + context "when the entity_id is not registered" do + specify { expect(status).to be_success } + specify { expect(output).to include("`#{entity_id}` is not registered") } end + end + describe "#list" do let(:command) { "metadata list" } - specify { expect(status).to be_success } - specify { expect(output).to include(entity_id) } + context "when a metadata is registered" do + before { execute("metadata register #{entity_id}") } + + specify { expect(status).to be_success } + specify { expect(output).to include(entity_id) } + end + + context "when zero metadata is registered" do + specify { expect(status).to be_success } + specify { expect(output).to include("Please register metadata using `saml-kit metadata register <url>`") } + end end end |
