require 'spec_helper' describe Mulder::Client do describe '.initialize' do let(:mocked_connection) { mock } it 'stores the app' do described_class.new(mocked_connection, 'foo', 'bar', 'worker').app.should == 'foo' end it 'stores the environment' do described_class.new(mocked_connection, 'foo', 'bar', 'worker').environment.should == 'bar' end end describe '#group' do it 'finds the correct group based on the given attributes' do mocked_connection = mock mocked_connection.expects(:group_by_id_regexp).with(/^foo-bar-(.*-)?WorkerGroup-.*$/i) client = described_class.new(mocked_connection, 'foo', 'bar', 'WorkerGroup') client.group end end describe '#instances' do it 'finds the instances for the group' do mocked_connection = mock mocked_group = mock mocked_connection.expects(:instances_by_group).with(mocked_group) client = described_class.new(mocked_connection, 'foo', 'bar', 'worker') client.expects(:group).returns(mocked_group) client.instances end end describe '#id_regexp' do it 'matches without an autogenerated id' do client = described_class.new(mock, 'foo', 'bar', 'worker') 'foo-bar-worker-3'.should match(client.id_regexp) end it 'matches with an autogenerated id' do client = described_class.new(mock, 'foo', 'bar', 'worker') 'foo-bar-abc123-worker-3'.should match(client.id_regexp) end context 'with prefixed id' do let(:client) { described_class.new(mock, 'widget-foo', 'bar', 'worker') } it 'matches the prefixed group' do 'widget-foo-bar-abd123-worker-8'.should match(client.id_regexp) end it 'does not match the non-prefixed group' do 'foo-bar-derp456-worker-99'.should_not match(client.id_regexp) end end context 'with non-prefixed id' do let(:client) { described_class.new(mock, 'foo', 'bar', 'worker') } it 'does not match the prefixed group' do 'widget-foo-bar-abd123-worker-8'.should_not match(client.id_regexp) end it 'matches the non-prefixed group' do 'foo-bar-derp456-worker-99'.should match(client.id_regexp) end end end end