Sha256: 9263c273c45f3beec62352362bb9f8a769109e23557434ce549fafde21e0da5c

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

require 'certmeister/response'

describe Certmeister::Response do

  let(:pem) { File.read('fixtures/client.crt') }

  it "cannot be created with pem and error" do
    expect { Certmeister::Response.new(pem, "silly") }.to raise_error(ArgumentError)
  end

  describe "on error" do

    subject { Certmeister::Response.new(nil, "something went wrong") }

    it "provides the error" do
      expect(subject.error).to eql "something went wrong"
    end

    it "doesn't provide the PEM-encoded X509 certificate as a string" do
      expect(subject.pem).to be_nil
    end

    it "offers appropriate boolean flags" do
      expect(subject.hit?).to be_false
      expect(subject.miss?).to be_false
      expect(subject.error?).to be_true
    end

  end

  describe "on miss (i.e. not found)" do

    subject { Certmeister::Response.new(nil, nil) }

    it "has no error" do
      expect(subject.error).to be_nil
    end

    it "doesn't provide the PEM-encoded X509 certificate as a string" do
      expect(subject.pem).to be_nil
    end

    it "offers appropriate boolean flags" do
      expect(subject.hit?).to be_false
      expect(subject.miss?).to be_true
      expect(subject.error?).to be_false
    end

  end

  describe "on hit (success)" do

    subject { Certmeister::Response.new(pem, nil) }

    it "has no error" do
      expect(subject.error).to be_nil
    end

    it "provides the PEM-encoded X509 certificate as a string" do
      expect(subject.pem).to eql pem
    end

    it "offers appropriate boolean flags" do
      expect(subject.hit?).to be_true
      expect(subject.miss?).to be_false
      expect(subject.error?).to be_false
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
certmeister-0.0.2 spec/certmeister/response_spec.rb
certmeister-0.0.1 spec/certmeister/response_spec.rb