spec/lita/handlers/locker_labels_spec.rb in lita-locker-0.7.0 vs spec/lita/handlers/locker_labels_spec.rb in lita-locker-1.0.0
- old
+ new
@@ -1,33 +1,45 @@
require 'spec_helper'
describe Lita::Handlers::LockerLabels, lita_handler: true do
before do
robot.auth.add_user_to_group!(user, :locker_admins)
+ Lita.config.robot.adapter = :hipchat
end
label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
label_examples.each do |l|
it do
is_expected.to route_command("locker label create #{l}").to(:create)
is_expected.to route_command("locker label delete #{l}").to(:delete)
is_expected.to route_command("locker label show #{l}").to(:show)
is_expected.to route_command("locker label add resource to #{l}").to(:add)
+ is_expected.to route_command("locker label add foo, bar to #{l}").to(:add)
is_expected.to route_command("locker label remove resource from #{l}").to(:remove)
+ is_expected.to route_command("locker label remove foo, bar from #{l}").to(:remove)
end
end
+ multi_label_examples = ['foo, bar', 'foo,bar']
+
+ multi_label_examples.each do |l|
+ it do
+ is_expected.to route_command("locker label create #{l}").to(:create)
+ is_expected.to route_command("locker label delete #{l}").to(:delete)
+ end
+ end
+
it { is_expected.to route_command('locker label list').to(:list) }
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, state: unlocked')).to eq(true)
- expect(replies.include?('Label: bazbat, state: unlocked')).to eq(true)
+ expect(replies.include?('foobar is unlocked')).to eq(true)
+ expect(replies.include?('bazbat is unlocked')).to eq(true)
end
end
describe '#label_create' do
it 'creates a label with <name>' do
@@ -39,15 +51,26 @@
send_command('locker label create foobar')
send_command('locker label create foobar')
expect(replies.last).to eq('foobar already exists')
end
- it 'shows a warning when the <name> already exists as a resource' do
- send_command('locker resource create foobar')
- send_command('locker label create foobar')
- expect(replies.last).to eq('foobar already exists')
+ it 'accepts a comma-separated list of labels' do
+ send_command('locker label create foo, bar,baz')
+ expect(replies.last).to eq('Label foo created, Label bar created, Label baz created')
end
+
+ it 'handles comma-separated labels nicely when a label already exists' do
+ send_command('locker label create bar')
+ send_command('locker label create foo, bar,baz')
+ expect(replies.last).to eq('Label foo created, bar already exists, Label baz created')
+ end
+
+ # it 'shows a warning when the <name> already exists as a resource' do
+ # send_command('locker resource create foobar')
+ # send_command('locker label create foobar')
+ # expect(replies.last).to eq('foobar already exists')
+ # end
end
describe '#label_delete' do
it 'deletes a label with <name>' do
send_command('locker label create foobar')
@@ -57,10 +80,16 @@
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. To create it: "!locker label create foobar"')
end
+
+ it 'accepts a comma-separated list of labels' do
+ send_command('locker label create foo, bar, baz')
+ send_command('locker label delete foo, bar,baz')
+ expect(replies.last).to eq('Label foo deleted, Label bar deleted, Label baz deleted')
+ end
end
describe '#label_show' do
it 'shows a list of resources for a label if there are any' do
send_command('locker resource create whatever')
@@ -102,10 +131,18 @@
expect(replies.last).to match(/Label bar has:/)
expect(replies.last).to match(/foo/)
expect(replies.last).to match(/baz/)
end
+ it 'adds multiple resources to a label when given as a comma-separated list' do
+ send_command('locker resource create foo')
+ send_command('locker resource create bar')
+ send_command('locker label create baz')
+ send_command('locker label add foo, bar to baz')
+ expect(replies.last).to eq('Resource foo has been added to baz, Resource bar has been added to 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. To create it: "!locker label create bar"')
end
@@ -131,17 +168,38 @@
send_command('locker label create bar')
send_command('locker label remove foo from bar')
expect(replies.last).to eq('Label bar does not have Resource foo')
end
+ it 'removes multiple resources to a label when given as a comma-separated list' do
+ send_command('locker resource create foo')
+ send_command('locker resource create bar')
+ send_command('locker label create baz')
+ send_command('locker label add foo, bar to baz')
+ send_command('locker label remove foo, bar from baz')
+ expect(replies.last).to eq('Resource foo has been removed from baz, Resource bar has been removed from 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. To create it: "!locker label create bar"')
end
+ it 'shows an error if the label does not exist when given a list of resources' do
+ send_command('locker label add foo, baz to bar')
+ 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')
expect(replies.last).to eq('Resource foo does not exist')
+ end
+
+ it 'shows an error if a resource in a list does not exist' do
+ send_command('locker label create bar')
+ send_command('locker resource create baz')
+ send_command('locker label add foo, baz to bar')
+ expect(replies.last).to eq('Resource foo does not exist, Resource baz has been added to bar')
end
end
end