Commit 9669351

mo <mo.khan@gmail.com>
2018-03-04 20:41:39
extract shared context for shell execution.
1 parent af77815
Changed files (4)
spec/saml/kit/cli/commands/certificate_spec.rb
@@ -1,15 +1,4 @@
 RSpec.describe Saml::Kit::Cli::Commands::Certificate do
-  let(:because) { execute(command) }
-  let(:status) { because[0] }
-  let(:output) { because[1] }
-
-  def execute(command)
-    full_command = "bundle exec ruby ./exe/saml-kit #{command} 2>&1"
-    puts full_command
-    output = `#{full_command}`
-    [$?, output]
-  end
-
   describe "keypair" do
     let(:passphrase) { "password" }
 
spec/saml/kit/cli/commands/decode_spec.rb
@@ -0,0 +1,12 @@
+RSpec.describe Saml::Kit::Cli::Commands::Certificate do
+  describe "#redirect" do
+    let(:command) { "decode redirect #{saml}" }
+    let(:saml) do
+      binding = Saml::Kit::Bindings::HttpRedirect.new(location: '')
+      document = Saml::Kit::AuthenticationRequest.builder
+      binding.serialize(document)
+    end
+
+    specify { expect(status).to be_success }
+  end
+end
spec/support/shell_helpers.rb
@@ -0,0 +1,16 @@
+RSpec.shared_context "shell execution" do
+  subject { execute(command) }
+  let(:status) { subject[0] }
+  let(:output) { subject[1] }
+
+  def execute(command, mute: false)
+    full_command = "bundle exec ruby ./exe/saml-kit #{command} 2>&1"
+    puts full_command unless mute
+    output = `#{full_command}`
+    [$?, output]
+  end
+end
+
+RSpec.configure do |config|
+  config.include_context "shell execution"
+end
spec/spec_helper.rb
@@ -1,5 +1,6 @@
 require 'bundler/setup'
 require 'saml/kit/cli'
+require_relative 'support/shell_helpers.rb'
 
 RSpec.configure do |config|
   # Enable flags like --only-failures and --next-failure