spec/clavem/authorizer_spec.rb in clavem-1.2.2 vs spec/clavem/authorizer_spec.rb in clavem-1.3.0
- old
+ new
@@ -38,42 +38,42 @@
describe Clavem::Authorizer do
let(:instance){::Clavem::Authorizer.new}
describe ".instance" do
it("should call .new with the passed arguments") do
- ::Clavem::Authorizer.should_receive(:new).with("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
- ::Clavem::Authorizer.instance("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
+ ::Clavem::Authorizer.should_receive(:new).with("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
+ ::Clavem::Authorizer.instance("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
end
it("should return the same instance") do
- ::Clavem::Authorizer.stub(:new) do Time.now end
+ ::Clavem::Authorizer.stub(:new) { Time.now }
authorizer = ::Clavem::Authorizer.instance("FIRST")
expect(::Clavem::Authorizer.instance("SECOND")).to be(authorizer)
end
it("should return a new instance if requested to") do
- ::Clavem::Authorizer.stub(:new) do Time.now end
+ ::Clavem::Authorizer.stub(:new) { Time.now }
authorizer = ::Clavem::Authorizer.instance("FIRST")
- expect(::Clavem::Authorizer.instance("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT", true)).not_to be(authorizer)
+ expect(::Clavem::Authorizer.instance("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT", true)).not_to be(authorizer)
end
end
describe "#initialize" do
it("should handle default arguments") do
authorizer = ::Clavem::Authorizer.new
- expect(authorizer.ip).to eq("127.0.0.1")
+ expect(authorizer.host).to eq("localhost")
expect(authorizer.port).to eq(2501)
expect(authorizer.command).to eq("open \"{{URL}}\"")
expect(authorizer.title).to eq("Clavem Authorization")
expect(authorizer.template).to eq(File.read(File.dirname(__FILE__) + "/../../lib/clavem/template.html.erb"))
expect(authorizer.timeout).to eq(0)
expect(authorizer.response_handler).to be_nil
end
it("should assign arguments") do
- authorizer = ::Clavem::Authorizer.new("IP", 2511, "COMMAND", "TITLE", "TEMPLATE", 2) do end
- expect(authorizer.ip).to eq("IP")
+ authorizer = ::Clavem::Authorizer.new("HOST", 2511, "COMMAND", "TITLE", "TEMPLATE", 2) do end
+ expect(authorizer.host).to eq("HOST")
expect(authorizer.port).to eq(2511)
expect(authorizer.command).to eq("COMMAND")
expect(authorizer.title).to eq("TITLE")
expect(authorizer.template).to eq("TEMPLATE")
expect(authorizer.timeout).to eq(2)
@@ -155,11 +155,11 @@
end
end
describe "#callback_url" do
it("should return the correct callback") do
- expect(::Clavem::Authorizer.new.callback_url).to eq("http://127.0.0.1:2501/")
+ expect(::Clavem::Authorizer.new.callback_url).to eq("http://localhost:2501/")
expect(::Clavem::Authorizer.new("10.0.0.1", "80").callback_url).to eq("http://10.0.0.1:80/")
end
end
describe "#default_response_handler" do
@@ -199,11 +199,11 @@
Kernel.should_receive(:system).with("open \"URL\"")
instance.instance_variable_set(:@url, "URL")
instance.send(:open_endpoint)
Kernel.should_receive(:system).with("COMMAND")
- ::Clavem::Authorizer.new("IP", "PORT", "COMMAND").send(:open_endpoint)
+ ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND").send(:open_endpoint)
end
it("should raise exception in case of failures") do
Kernel.stub(:system).and_raise(RuntimeError)
expect { instance.send(:open_endpoint) }.to raise_error(::Clavem::Exceptions::Failure)
@@ -221,11 +221,11 @@
end
describe "#setup_timeout_handling" do
it("should not set a timeout handler by default") do
authorizer = ::Clavem::Authorizer.new
- authorizer.stub(:open_endpoint) do end
+ authorizer.stub(:open_endpoint)
authorizer.stub(:setup_webserver) do authorizer.instance_variable_set(:@server, ::ClavemDummyServer.new) end
authorizer.authorize("URL")
expect(authorizer.instance_variable_get(:@timeout_handler)).to be_nil
end
@@ -234,11 +234,11 @@
Kernel.should_receive(:sleep).with(0.5)
server = ::ClavemDummyServer.new
server.stub(:start) do sleep(1) end
- authorizer = ::Clavem::Authorizer.new("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE", 500)
+ authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", 500)
authorizer.stub(:open_endpoint) do end
authorizer.stub(:setup_webserver) do authorizer.instance_variable_set(:@server, server) end
expect { authorizer.authorize("URL") }.to raise_error(::Clavem::Exceptions::Timeout)
thread = authorizer.instance_variable_get(:@timeout_thread)
@@ -258,11 +258,11 @@
end
it "should setup a single request handler on /" do
server = ::ClavemDummyServer.new
::WEBrick::HTTPServer.stub(:new).and_return(server)
- authorizer = ::Clavem::Authorizer.new("IP", "PORT")
+ authorizer = ::Clavem::Authorizer.new("HOST", "PORT")
server.should_receive(:mount_proc).with("/")
authorizer.send(:setup_webserver)
end
end
@@ -322,11 +322,11 @@
describe "#cleanup" do
it "should shutdown the server and cleanup signal handling" do
server = ::ClavemDummyServer.new
server.stub(:start) do sleep(1) end
- authorizer = ::Clavem::Authorizer.new("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE")
+ authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE")
authorizer.stub(:open_endpoint) do end
authorizer.stub(:setup_webserver) do authorizer.instance_variable_set(:@server, server) end
authorizer.authorize("URL")
Kernel.should_receive(:trap).with("USR2", "DEFAULT")
@@ -340,10 +340,10 @@
it "should exit timeout handling thread if active" do
thread = nil
server = ::ClavemDummyServer.new
server.stub(:start) do sleep(1) end
- authorizer = ::Clavem::Authorizer.new("IP", "PORT", "COMMAND", "TITLE", "TEMPLATE", 5000)
+ authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", 5000)
authorizer.send(:setup_timeout_handling)
thread = authorizer.instance_variable_get(:@timeout_thread)
thread.should_receive(:exit)
authorizer.send(:cleanup)
end
\ No newline at end of file