diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..b013f76 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +Metrics/LineLength: + Max: 120 + +Style/FileName: + Enabled: false + +Style/Documentation: + Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe4bbb..91a77e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). We follow [Keep a Changelog](http://keepachangelog.com/) format. +## 0.5.0 - TO BE RELEASED +### Added +- Rubocop codestyle + ## 0.4.0 - 2015-08-21 ### Added - I18n support diff --git a/Gemfile b/Gemfile index b4e2a20..fa75df1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index c92b11e..57feb22 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,9 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) +RuboCop::RakeTask.new -task default: :spec +task default: [:spec, :lint] +task lint: [:rubocop] diff --git a/lib/lita-queue.rb b/lib/lita-queue.rb index 355fe46..001e8f1 100644 --- a/lib/lita-queue.rb +++ b/lib/lita-queue.rb @@ -1,12 +1,11 @@ -require "lita" +require 'lita' Lita.load_locales Dir[File.expand_path( - File.join("..", "..", "locales", "*.yml"), __FILE__ + File.join('..', '..', 'locales', '*.yml'), __FILE__ )] -require "lita/handlers/queue" +require 'lita/handlers/queue' Lita::Handlers::Queue.template_root File.expand_path( - File.join("..", "..", "templates"), - __FILE__ + File.join('..', '..', 'templates'), __FILE__ ) diff --git a/lib/lita/handlers/queue.rb b/lib/lita/handlers/queue.rb index ae2adbc..c269f44 100644 --- a/lib/lita/handlers/queue.rb +++ b/lib/lita/handlers/queue.rb @@ -1,19 +1,18 @@ module Lita module Handlers class Queue < Handler - route(/^queue$/, :queue_list, command: :true) route(/^queue me$/, :queue_me, command: :true) route(/^unqueue me$/, :unqueue_me, command: :true) route(/^queue next\?$/, :queue_list_next, command: :true) route(/^queue next!$/, :queue_change_to_next, command: :true) route(/^queue rotate!$/, :queue_rotate, command: :true) - #route(/^queue = \[([^\]]*)\]\s*$$/, :queue_recreate, command: :true) + # route(/^queue = \[([^\]]*)\]\s*$$/, :queue_recreate, command: :true) # API def fetch_queue(room) - raise ArgumentError, 'must be a Lita::Room object' unless room.is_a? Lita::Room + fail ArgumentError, 'must be a Lita::Room object' unless room.is_a? Lita::Room serialized = redis.get(room.id) diff --git a/lita-queue.gemspec b/lita-queue.gemspec index b944a7b..9d74852 100644 --- a/lita-queue.gemspec +++ b/lita-queue.gemspec @@ -1,26 +1,27 @@ Gem::Specification.new do |spec| - spec.name = "lita-queue" - spec.version = "0.4.0" - spec.authors = ["Gabriel Mazetto"] - spec.email = ["brodock@gmail.com"] - spec.description = "Lita plugin to manage channel specific queue" - spec.summary = "Lita plugin to manage channel specific queue" - spec.homepage = "https://github.com/brodock/lita-queue" - spec.license = "MIT" - spec.metadata = { "lita_plugin_type" => "handler" } + spec.name = 'lita-queue' + spec.version = '0.4.0' + spec.authors = ['Gabriel Mazetto'] + spec.email = ['brodock@gmail.com'] + spec.description = 'Lita plugin to manage channel specific queue' + spec.summary = 'Lita plugin to manage channel specific queue' + spec.homepage = 'https://github.com/brodock/lita-queue' + spec.license = 'MIT' + spec.metadata = { 'lita_plugin_type' => 'handler' } - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_runtime_dependency "lita", ">= 4.4.3" + spec.add_runtime_dependency 'lita', '>= 4.4.3' - spec.add_development_dependency "bundler", "~> 1.3" - spec.add_development_dependency "pry-byebug" - spec.add_development_dependency "rake" - spec.add_development_dependency "rack-test" - spec.add_development_dependency "rspec", ">= 3.0.0" - spec.add_development_dependency "simplecov" - spec.add_development_dependency "coveralls" + spec.add_development_dependency 'bundler', '~> 1.3' + spec.add_development_dependency 'pry-byebug' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rack-test' + spec.add_development_dependency 'rspec', '>= 3.0.0' + spec.add_development_dependency 'simplecov' + spec.add_development_dependency 'coveralls' + spec.add_development_dependency 'rubocop' end diff --git a/spec/lita/handlers/queue_spec.rb b/spec/lita/handlers/queue_spec.rb index 1c14459..09f19e2 100644 --- a/spec/lita/handlers/queue_spec.rb +++ b/spec/lita/handlers/queue_spec.rb @@ -1,68 +1,67 @@ -require "spec_helper" +require 'spec_helper' describe Lita::Handlers::Queue, lita_handler: true do - user1 = Lita::User.create(100, name: 'User 1') user2 = Lita::User.create(101, name: 'User 2') user3 = Lita::User.create(102, name: 'User 3') # Routes - it { is_expected.to route_command("queue").to(:queue_list) } - it { is_expected.to route_command("queue me").to(:queue_me) } - it { is_expected.to route_command("unqueue me").to(:unqueue_me) } - it { is_expected.to route_command("queue next?").to(:queue_list_next) } - it { is_expected.to route_command("queue next!").to(:queue_change_to_next) } - it { is_expected.to route_command("queue rotate!").to(:queue_rotate) } - #it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) } + it { is_expected.to route_command('queue').to(:queue_list) } + it { is_expected.to route_command('queue me').to(:queue_me) } + it { is_expected.to route_command('unqueue me').to(:unqueue_me) } + it { is_expected.to route_command('queue next?').to(:queue_list_next) } + it { is_expected.to route_command('queue next!').to(:queue_change_to_next) } + it { is_expected.to route_command('queue rotate!').to(:queue_rotate) } + # it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) } - let(:room) { Lita::Room.new(1, {name: 'my-channel'}) } + let(:room) { Lita::Room.new(1, name: 'my-channel') } # Commands - describe "#queue_list" do - context "when queue is empty" do + describe '#queue_list' do + context 'when queue is empty' do before { subject.store_queue(room, []) } - it "replies with an empty queue message" do - send_command("queue", from: room) - expect(replies.last).to include("Queue is empty") + it 'replies with an empty queue message' do + send_command('queue', from: room) + expect(replies.last).to include('Queue is empty') end end - context "when queue has elements" do + context 'when queue has elements' do before { subject.store_queue(room, [user1.mention_name, user2.mention_name]) } - it "replies with a list of queue users" do - send_command("queue", from: room) + it 'replies with a list of queue users' do + send_command('queue', from: room) expect(replies.last).to include(user1.mention_name, user2.mention_name) end end end - describe "#queue_me" do + describe '#queue_me' do context "when I'm already queued" do before { subject.store_queue(room, [user.mention_name]) } - it "replies with an error message" do - send_command("queue me", from: room) - expect(replies.last).to include("already on queue") + it 'replies with an error message' do + send_command('queue me', from: room) + expect(replies.last).to include('already on queue') end end context "when I'm not on queue" do - it "replies with a confirmation message" do - send_command("queue me", from: room) + it 'replies with a confirmation message' do + send_command('queue me', from: room) expect(replies.last).to include("#{user.name} have been added to queue") expect(subject.fetch_queue(room)).to include(user.mention_name) end end end - describe "#unqueue_me" do + describe '#unqueue_me' do context "when I'm already queued" do before { subject.store_queue(room, [user.mention_name]) } - it "replies with a confirmation and remove from queue" do - send_command("unqueue me", from: room) + it 'replies with a confirmation and remove from queue' do + send_command('unqueue me', from: room) expect(replies.last).to include("#{user.name} have been removed from queue") expect(subject.fetch_queue(room)).not_to include(user.mention_name) end @@ -71,94 +70,93 @@ context "when I'm not on queue" do before { subject.store_queue(room, []) } - it "replies with an error message" do - send_command("unqueue me", from: room) - expect(replies.last).to include("not on queue!") + it 'replies with an error message' do + send_command('unqueue me', from: room) + expect(replies.last).to include('not on queue!') end end end - describe "#queue_list_next" do - context "when queue is empty" do - it "replies with an error message" do - send_command("queue next?", from: room) - expect(replies.last).to include("Queue is empty") + describe '#queue_list_next' do + context 'when queue is empty' do + it 'replies with an error message' do + send_command('queue next?', from: room) + expect(replies.last).to include('Queue is empty') end end - context "when queue has only one element" do + context 'when queue has only one element' do before { subject.store_queue(room, [user1.mention_name]) } it "replies listing current user on queue and warning that's the last one" do - send_command("queue next?", from: room) + send_command('queue next?', from: room) expect(replies.last).to include(user1.mention_name) - expect(replies.last).to include("is the last one on queue") + expect(replies.last).to include('is the last one on queue') end end - context "when queue has more than one elements" do + context 'when queue has more than one elements' do before { subject.store_queue(room, [user1.mention_name, user2.mention_name]) } - it "replies listing the next one on the queue" do - send_command("queue next?", from: room) + it 'replies listing the next one on the queue' do + send_command('queue next?', from: room) expect(replies.last).to include(user2.mention_name) end end end - describe "#queue_change_to_next" do - context "when queue is empty" do - it "replies with an error message" do - send_command("queue next!", from: room) - expect(replies.last).to include("Queue is empty") + describe '#queue_change_to_next' do + context 'when queue is empty' do + it 'replies with an error message' do + send_command('queue next!', from: room) + expect(replies.last).to include('Queue is empty') end end - context "when queue has enough elements" do + context 'when queue has enough elements' do let(:queue) { [user1.mention_name, user2.mention_name] } before { subject.store_queue(room, queue) } - it "remove the first element from the queue" do - send_command("queue next!", from: room) + it 'remove the first element from the queue' do + send_command('queue next!', from: room) expect(subject.fetch_queue(room)).to eq([user2.mention_name]) end - it "replies informing who was been removed and who is next" do - send_command("queue next!", from: room) + it 'replies informing who was been removed and who is next' do + send_command('queue next!', from: room) expect(replies.first).to include("#{user1.mention_name} have been removed from queue") expect(replies[1]).to include("#{user2.mention_name} is the next") - end - it "informs the new queue after execution" do - send_command("queue next!", from: room) + it 'informs the new queue after execution' do + send_command('queue next!', from: room) expect(replies.last).to include(user2.mention_name) expect(replies.last).not_to include(user1.mention_name) end - context "when queue has only one element" do + context 'when queue has only one element' do let(:queue) { [user2.mention_name] } - it "replies with a notification message when removing the last element from queue" do - send_command("queue next!", from: room) + it 'replies with a notification message when removing the last element from queue' do + send_command('queue next!', from: room) expect(replies.first).to include("#{user2.mention_name} have been removed from queue") - expect(replies.last).to include("Queue is empty") + expect(replies.last).to include('Queue is empty') end end end end - describe "#queue_rotate" do - context "when queue has enough elements" do + describe '#queue_rotate' do + context 'when queue has enough elements' do before { subject.store_queue(room, [user1.mention_name, user2.mention_name, user3.mention_name]) } - it "removes the first element and add to the end" do - send_command("queue rotate!", from: room) + it 'removes the first element and add to the end' do + send_command('queue rotate!', from: room) expect(subject.fetch_queue(room)).to eq([user2.mention_name, user3.mention_name, user1.mention_name]) end - it "replies mentioning the next user on queue and notifing the rotated one" do - send_command("queue rotate!", from: room) + it 'replies mentioning the next user on queue and notifing the rotated one' do + send_command('queue rotate!', from: room) expect(replies.first).to include("#{user1.mention_name} has been moved to the end of the queue") expect(replies[1]).to include("#{user2.mention_name} is the next") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e00c185..2a3f7b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,14 @@ -require "pry" -require "simplecov" -require "coveralls" +require 'pry' +require 'simplecov' +require 'coveralls' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] -SimpleCov.start { add_filter "/spec/" } +SimpleCov.start { add_filter '/spec/' } -require "lita-queue" -require "lita/rspec" +require 'lita-queue' +require 'lita/rspec' # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin # was generated with Lita 4, the compatibility mode should be left disabled.