spec/kamerling/registrar_spec.rb in kamerling-0.0.2 vs spec/kamerling/registrar_spec.rb in kamerling-0.0.3

- old
+ new

@@ -1,20 +1,48 @@ require_relative '../spec_helper' +require_relative '../../lib/kamerling/addr' +require_relative '../../lib/kamerling/client' +require_relative '../../lib/kamerling/message' +require_relative '../../lib/kamerling/project' +require_relative '../../lib/kamerling/registration' +require_relative '../../lib/kamerling/registrar' +require_relative '../../lib/kamerling/repo' -module Kamerling describe Registrar do - describe '#register' do - fakes :addr, :client, :project, :repo +module Kamerling + describe Registrar do + describe '.register' do + let(:addr) { Addr.new } + let(:client) { Client.new } + let(:project) { Project.new } - it 'registers that the given client can do the given project' do - repos = { - Client => { client.uuid => client }, - Project => { project.uuid => project }, - Registration => repo, - } - Registrar.new.register addr: addr, client_uuid: client.uuid, - project_uuid: project.uuid, repos: repos - registration = Registration.new addr: addr, client: client, - project: project, uuid: anything - repo.must_have_received :<<, [registration] + let(:mess) do + Message.build(client: client, payload: 'data', project: project, + task: Task.new, type: :RGST) + end + + let(:repos) { fake(:repos, as: :class) } + + before do + stub(repos).[](Client) { fake(:repo, :[] => client) } + stub(repos).[](Project) { fake(:repo, :[] => project) } + stub(repos).[](Registration) { fake(:repo) } + end + + it 'registers that the given client can do the given project' do + Registrar.register addr: addr, message: mess, repos: repos + repos.must_have_received :<<, [any(Registration)] + end + + it 'updates the clien’t addr' do + Registrar.register addr: addr, message: mess, repos: repos + repos.must_have_received :<<, [client] + end + + it 'doesn’t blow up when a new client tries to register' do + empty_repo = fake(:repo, :[] => -> { fail Repo::NotFound }) + stub(repos).[](Client) { empty_repo } + Registrar.register addr: addr, message: mess, repos: repos + repos.must_have_received :<<, [client] + end end end -end end +end