spec/certmeister/response_spec.rb in certmeister-0.0.2 vs spec/certmeister/response_spec.rb in certmeister-0.1.0
- old
+ new
@@ -4,17 +4,17 @@
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)
+ it "must be instantiated via the factory methods only" do
+ expect { Certmeister::Response.new(pem, nil, nil) }.to raise_error(NoMethodError, /private/)
end
describe "on error" do
- subject { Certmeister::Response.new(nil, "something went wrong") }
+ subject { Certmeister::Response.error("something went wrong") }
it "provides the error" do
expect(subject.error).to eql "something went wrong"
end
@@ -23,18 +23,40 @@
end
it "offers appropriate boolean flags" do
expect(subject.hit?).to be_false
expect(subject.miss?).to be_false
+ expect(subject.denied?).to be_false
expect(subject.error?).to be_true
end
end
+ describe "on denial" do
+
+ subject { Certmeister::Response.denied("bad client, no cookie") }
+
+ it "provides the reason" do
+ expect(subject.error).to eql "bad client, no cookie"
+ 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.denied?).to be_true
+ expect(subject.error?).to be_false
+ end
+
+ end
+
describe "on miss (i.e. not found)" do
- subject { Certmeister::Response.new(nil, nil) }
+ subject { Certmeister::Response.miss }
it "has no error" do
expect(subject.error).to be_nil
end
@@ -43,29 +65,32 @@
end
it "offers appropriate boolean flags" do
expect(subject.hit?).to be_false
expect(subject.miss?).to be_true
+ expect(subject.denied?).to be_false
expect(subject.error?).to be_false
end
end
describe "on hit (success)" do
- subject { Certmeister::Response.new(pem, nil) }
+ subject { Certmeister::Response.hit(pem) }
it "has no error" do
expect(subject.error).to be_nil
end
- it "provides the PEM-encoded X509 certificate as a string" do
+ it "provides the PEM-encoded X509 certificate as a string (or :none)" do
+ # some hits, like the one for a remove(), don't have a pem, returning :none
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.denied?).to be_false
expect(subject.error?).to be_false
end
end