spec/lita/handlers/locker_spec.rb in lita-locker-0.4.0 vs spec/lita/handlers/locker_spec.rb in lita-locker-0.5.0
- old
+ new
@@ -1,200 +1,218 @@
require 'spec_helper'
describe Lita::Handlers::Locker, lita_handler: true do
- it { routes('(lock) foobar').to(:lock) }
- it { routes('(unlock) foobar').to(:unlock) }
+ label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
+ resource_examples = ['foobar', 'foo.bar', 'foo-bar', 'foo_bar']
- it { routes_command('lock foobar').to(:lock) }
- it { routes_command('lock foo bar').to(:lock) }
- it { routes_command('lock foo-bar').to(:lock) }
- it { routes_command('lock foo_bar').to(:lock) }
-# it { routes_command('lock foobar 30m').to(:lock) }
+ label_examples.each do |l|
+ it { routes("(lock) #{l}").to(:lock) }
+ it { routes("(unlock) #{l}").to(:unlock) }
+ it { routes("(release) #{l}").to(:unlock) }
- it { routes_command('unlock foobar').to(:unlock) }
- it { routes_command('unlock foo bar').to(:unlock) }
- it { routes_command('unlock foo-bar').to(:unlock) }
- it { routes_command('unlock foo_bar').to(:unlock) }
- it { routes_command('unlock foobar force').to(:unlock_force) }
+ it { routes("(lock) #{l} #this is a comment").to(:lock) }
+ it { routes("(unlock) #{l} #this is a comment").to(:unlock) }
+ it { routes("(release) #{l} #this is a comment").to(:unlock) }
+ it { routes_command("lock #{l}").to(:lock) }
+ it { routes_command("lock #{l} #this is a comment").to(:lock) }
+ it { routes_command("unlock #{l}").to(:unlock) }
+ it { routes_command("unlock #{l} #this is a comment").to(:unlock) }
+ it { routes_command("steal #{l}").to(:steal) }
+ it { routes_command("steal #{l} #this is a comment").to(:steal) }
+ end
+
+ label_examples.each do |l|
+ it { routes_command("locker status #{l}").to(:status) }
+ end
+
+ resource_examples.each do |r|
+ it { routes_command("locker status #{r}").to(:status) }
+ end
+
it { routes_command('locker resource list').to(:resource_list) }
- it { routes_command('locker resource create foobar').to(:resource_create) }
- it { routes_command('locker resource create foo.bar').to(:resource_create) }
- it { routes_command('locker resource create foo-bar').to(:resource_create) }
- it { routes_command('locker resource create foo_bar').to(:resource_create) }
- it { routes_command('locker resource delete foobar').to(:resource_delete) }
- it { routes_command('locker resource show foobar').to(:resource_show) }
+ resource_examples.each do |r|
+ it { routes_command("locker resource create #{r}").to(:resource_create) }
+ it { routes_command("locker resource delete #{r}").to(:resource_delete) }
+ it { routes_command("locker resource show #{r}").to(:resource_show) }
+ end
+
it { routes_command('locker label list').to(:label_list) }
- it { routes_command('locker label create foobar').to(:label_create) }
- it { routes_command('locker label delete foobar').to(:label_delete) }
- it { routes_command('locker label show foobar').to(:label_show) }
- it { routes_command('locker label add foo to bar').to(:label_add) }
- it { routes_command('locker label remove foo from bar').to(:label_remove) }
+ label_examples.each do |l|
+ it { routes_command("locker label create #{l}").to(:label_create) }
+ it { routes_command("locker label delete #{l}").to(:label_delete) }
+ it { routes_command("locker label show #{l}").to(:label_show) }
+ it { routes_command("locker label add resource to #{l}").to(:label_add) }
+ it { routes_command("locker label remove resource from #{l}").to(:label_remove) }
+ end
+
it { routes_http(:get, '/locker/label/foobar').to(:http_label_show) }
it { routes_http(:get, '/locker/resource/foobar').to(:http_resource_show) }
before do
allow(Lita::Authorization).to receive(:user_in_group?).with(
user,
:locker_admins
).and_return(true)
end
- describe '#lock' do
- it 'locks a resource when it is available' do
- send_command('locker resource create foobar')
- send_command('lock foobar')
- expect(replies.last).to eq('foobar locked')
- end
+ let(:alice) do
+ Lita::User.create('9001@hipchat', name: 'Alice', mention_name: '@alice')
+ end
+ let(:bob) do
+ Lita::User.create('9002@hipchat', name: 'Bob', mention_name: '@bob')
+ end
+
+ describe '#lock' do
it 'locks a label when it is available and has resources' do
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
- send_command('lock bazbat')
- expect(replies.last).to eq('bazbat locked')
+ send_command('lock bazbat # with a comment')
+ expect(replies.last).to eq('(successful) bazbat locked')
send_command('locker resource show foobar')
expect(replies.last).to eq('Resource: foobar, state: locked')
end
it 'shows a warning when a label has no resources' do
send_command('locker label create foobar')
send_command('lock foobar')
- expect(replies.last).to eq('foobar has no resources, ' \
+ expect(replies.last).to eq('(failed) foobar has no resources, ' \
'so it cannot be locked')
end
- it 'shows a warning when a resource is unavailable' do
- send_command('locker resource create foobar')
- send_command('lock foobar')
- send_command('lock foobar')
- expect(replies.last).to eq('foobar is locked')
+ it 'shows a warning when a label is unavailable' do
+ send_command('locker resource create r1')
+ send_command('locker label create l1')
+ send_command('locker label create l2')
+ send_command('locker label add r1 to l1')
+ send_command('locker label add r1 to l2')
+ send_command('lock l1', as: alice)
+ send_command('lock l2', as: alice)
+ expect(replies.last).to eq('(failed) Label unable to be locked, ' \
+ 'blocked on a dependency')
end
- it 'shows a warning when a label is unavailable' do
+ it 'shows a warning when a label is taken by someone else' do
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
- send_command('lock foobar')
- send_command('lock bazbat')
- expect(replies.last).to eq('bazbat unable to be locked')
+ send_command('lock bazbat', as: alice)
+ send_command('lock bazbat', as: bob)
+ expect(replies.last).to eq('(failed) bazbat is locked by Alice @alice')
end
- it 'shows an error when a <subject> does not exist' do
+ it 'shows an error when a label does not exist' do
send_command('lock foobar')
- expect(replies.last).to eq('foobar does not exist')
+ expect(replies.last).to eq('(failed) Label foobar does not exist. To ' \
+ 'create it: "!locker label create foobar"')
end
-# it 'locks a resource when it is available for a period of time' do
-# send_command('locker resource create foobar')
-# send_command('lock foobar 17m')
-# expect(replies.last).to eq('foobar locked for 17 minutes')
-# send_command('locker resource show foobar')
-# expect(replies.last).to eq('Resource: foobar, state: locked')
-# send_command('unlock foobar')
-# send_command('lock foobar 12s')
-# expect(replies.last).to eq('foobar locked for 17 seconds')
-# send_command('unlock foobar')
-# send_command('lock foobar 14h')
-# expect(replies.last).to eq('foobar locked for 14 hours')
-# end
+ # it 'locks a resource when it is available for a period of time' do
+ # send_command('locker resource create foobar')
+ # send_command('lock foobar 17m')
+ # expect(replies.last).to eq('foobar locked for 17 minutes')
+ # send_command('locker resource show foobar')
+ # expect(replies.last).to eq('Resource: foobar, state: locked')
+ # send_command('unlock foobar')
+ # send_command('lock foobar 12s')
+ # expect(replies.last).to eq('foobar locked for 17 seconds')
+ # send_command('unlock foobar')
+ # send_command('lock foobar 14h')
+ # expect(replies.last).to eq('foobar locked for 14 hours')
+ # end
end
describe '#unlock' do
- it 'unlocks a resource when it is available' do
- send_command('locker resource create foobar')
- send_command('lock foobar')
- send_command('unlock foobar')
- expect(replies.last).to eq('foobar unlocked')
- end
-
- it 'does not unlock a resource when someone else locked it' do
- alice = Lita::User.create(1, name: 'Alice')
- bob = Lita::User.create(2, name: 'Bob')
- send_command('locker resource create foobar')
- send_command('lock foobar', as: alice)
- send_command('unlock foobar', as: bob)
- expect(replies.last).to eq('foobar is locked by Alice')
- end
-
it 'unlocks a label when it is available' do
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
send_command('lock bazbat')
- send_command('unlock bazbat')
- expect(replies.last).to eq('bazbat unlocked')
+ send_command('unlock bazbat # with a comment')
+ expect(replies.last).to eq('(successful) bazbat unlocked')
end
it 'does not unlock a label when someone else locked it' do
- alice = Lita::User.create(1, name: 'Alice')
- bob = Lita::User.create(2, name: 'Bob')
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
send_command('lock bazbat', as: alice)
send_command('unlock bazbat', as: bob)
- expect(replies.last).to eq('bazbat is locked by Alice')
+ expect(replies.last).to eq('(failed) bazbat is locked by Alice @alice')
end
- it 'shows a warning when a resource is already unlocked' do
- send_command('locker resource create foobar')
- send_command('unlock foobar')
- expect(replies.last).to eq('foobar is unlocked')
- end
-
it 'shows a warning when a label is already unlocked' do
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
send_command('unlock bazbat')
send_command('unlock bazbat')
- expect(replies.last).to eq('bazbat is unlocked')
+ expect(replies.last).to eq('(successful) bazbat is unlocked')
end
it 'shows an error when a <subject> does not exist' do
send_command('unlock foobar')
- expect(replies.last).to eq('foobar does not exist')
+ expect(replies.last).to eq('(failed) Sorry, that does not exist')
end
end
- describe '#unlock_force' do
- it 'unlocks a resource from someone else when it is available' do
- alice = Lita::User.create(1, name: 'Alice')
- bob = Lita::User.create(2, name: 'Bob')
- send_command('locker resource create foobar')
- send_command('lock foobar', as: alice)
- send_command('unlock foobar force', as: bob)
- expect(replies.last).to eq('foobar unlocked')
- end
-
+ describe '#steal' do
it 'unlocks a label from someone else when it is available' do
- alice = Lita::User.create(1, name: 'Alice')
- bob = Lita::User.create(2, name: 'Bob')
send_command('locker resource create foobar')
send_command('locker label create bazbat')
send_command('locker label add foobar to bazbat')
send_command('lock bazbat', as: alice)
- send_command('unlock bazbat force', as: bob)
- expect(replies.last).to eq('bazbat unlocked')
+ send_command('steal bazbat # with a comment', as: bob)
+ expect(replies.last).to eq('(successful) bazbat unlocked')
end
it 'shows an error when a <subject> does not exist' do
- send_command('unlock foobar force')
- expect(replies.last).to eq('foobar does not exist')
+ send_command('steal foobar')
+ expect(replies.last).to eq('(failed) Sorry, that does not exist')
end
end
+ describe '#status' do
+ it 'shows the status of a label' do
+ send_command('locker resource create bar')
+ send_command('locker label create foo')
+ send_command('locker label add bar to foo')
+ send_command('locker status foo')
+ expect(replies.last).to eq('Label: foo, state: unlocked')
+ send_command('lock foo')
+ send_command('locker status foo')
+ expect(replies.last).to eq('Label: foo, state: locked')
+ end
+
+ it 'shows the status of a resource' do
+ send_command('locker resource create bar')
+ send_command('locker label create foo')
+ send_command('locker label add bar to foo')
+ send_command('locker status bar')
+ expect(replies.last).to eq('Resource: bar, state: unlocked')
+ send_command('lock foo')
+ send_command('locker status bar')
+ expect(replies.last).to eq('Resource: bar, state: locked')
+ end
+
+ it 'shows an error if nothing exists with that name' do
+ send_command('locker status foo')
+ expect(replies.last).to eq('Sorry, that does not exist')
+ end
+ end
+
describe '#label_list' do
it 'shows a list of labels if there are any' do
send_command('locker label create foobar')
send_command('locker label create bazbat')
send_command('locker label list')
- expect(replies.include?('Label: foobar')).to eq(true)
- expect(replies.include?('Label: bazbat')).to eq(true)
+ expect(replies.include?('Label: foobar, state: unlocked')).to eq(true)
+ expect(replies.include?('Label: bazbat, state: unlocked')).to eq(true)
end
end
describe '#label_create' do
it 'creates a label with <name>' do
@@ -222,11 +240,12 @@
expect(replies.last).to eq('Label foobar deleted')
end
it 'shows a warning when <name> does not exist' do
send_command('locker label delete foobar')
- expect(replies.last).to eq('Label foobar does not exist')
+ expect(replies.last).to eq('Label foobar does not exist. To create ' \
+ 'it: "!locker label create foobar"')
end
end
describe '#label_show' do
it 'shows a list of resources for a label if there are any' do
@@ -243,11 +262,12 @@
expect(replies.last).to eq('Label foobar has no resources')
end
it 'shows an error if the label does not exist' do
send_command('locker label show foobar')
- expect(replies.last).to eq('Label foobar does not exist')
+ expect(replies.last).to eq('Label foobar does not exist. To create ' \
+ 'it: "!locker label create foobar"')
end
end
describe '#label_add' do
it 'adds a resource to a label if both exist' do
@@ -264,16 +284,17 @@
send_command('locker resource create baz')
send_command('locker label create bar')
send_command('locker label add foo to bar')
send_command('locker label add baz to bar')
send_command('locker label show bar')
- expect(replies.last).to eq('Label bar has: baz, foo')
+ expect(replies.last).to eq('Label bar has: foo, baz')
end
it 'shows an error if the label does not exist' do
send_command('locker label add foo to bar')
- expect(replies.last).to eq('Label bar does not exist')
+ expect(replies.last).to eq('Label bar does not exist. To create ' \
+ 'it: "!locker label create bar"')
end
it 'shows an error if the resource does not exist' do
send_command('locker label create bar')
send_command('locker label add foo to bar')
@@ -298,11 +319,12 @@
expect(replies.last).to eq('Label bar does not have Resource foo')
end
it 'shows an error if the label does not exist' do
send_command('locker label add foo to bar')
- expect(replies.last).to eq('Label bar does not exist')
+ expect(replies.last).to eq('Label bar does not exist. To create ' \
+ 'it: "!locker label create bar"')
end
it 'shows an error if the resource does not exist' do
send_command('locker label create bar')
send_command('locker label add foo to bar')
@@ -313,12 +335,12 @@
describe '#resource_list' do
it 'shows a list of resources if there are any' do
send_command('locker resource create foobar')
send_command('locker resource create bazbat')
send_command('locker resource list')
- expect(replies.include?('Resource: foobar, state: unlocked')).to eq(true)
- expect(replies.include?('Resource: bazbat, state: unlocked')).to eq(true)
+ expect(replies.last).to match(/Resource: foobar, state: unlocked/)
+ expect(replies.last).to match(/Resource: bazbat, state: unlocked/)
end
end
describe '#resource_create' do
it 'creates a resource with <name>' do
@@ -355,12 +377,9 @@
describe '#resource_show' do
it 'shows the state of a <name> if it exists' do
send_command('locker resource create foobar')
send_command('locker resource show foobar')
expect(replies.last).to eq('Resource: foobar, state: unlocked')
- send_command('lock foobar')
- send_command('locker resource show foobar')
- expect(replies.last).to eq('Resource: foobar, state: locked')
end
it 'shows a warning when <name> does not exist' do
send_command('locker resource show foobar')
expect(replies.last).to eq('Resource foobar does not exist')