Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the existing Rubocop configuration #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in mob_rotation.gemspec
gemspec
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require "bundler/gem_tasks"
require 'rake/testtask'
require 'rspec/core/rake_task'
require "rake/testtask"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:test)
desc "Default task is test or spec"
task :spec => :test
task :default => :test

task spec: :test
task default: :test
8 changes: 4 additions & 4 deletions lib/mob_rotation/command_routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def define_command(name, &block)
end

def command_router(command, mobster_names)
command_implementation = CommandRouting::COMMAND_MAPPINGS.fetch(command) {
lambda { |command|
command_implementation = CommandRouting::COMMAND_MAPPINGS.fetch(command) do
lambda do |command|
inform_lovely_user(command)
}
}
end
end
case command_implementation.arity
when -2
instance_exec(command, *mobster_names, &command_implementation)
Expand Down
59 changes: 27 additions & 32 deletions lib/mob_rotation/rotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(database, git_dir)
@git_dir = git_dir
@database = database

@real_mobsters = @database.sanitized_entries_in do | entry |
@real_mobsters = @database.sanitized_entries_in do |entry|
mobster = build_mobster entry
end
end
Expand All @@ -70,17 +70,17 @@ def show_mobsters
end
end

def format_mobster(role, person, color=nil)
width = ENV['TABLE'] ? "navigator".size : 0
def format_mobster(role, person, color = nil)
width = ENV["TABLE"] ? "navigator".size : 0
role = sprintf("%-#{width}s", role)

formatted = if person.email.to_s.empty?
"#{role} #{person.name}"
else
"#{role} #{person.name} <#{person.email}>"
"#{role} #{person.name}"
else
"#{role} #{person.name} <#{person.email}>"
end

if color && ENV['COLOR']
if color && ENV["COLOR"]
formatted.send color
else
formatted
Expand All @@ -89,7 +89,7 @@ def format_mobster(role, person, color=nil)

def add_mobster(*mobsters_to_add)
mobsters_to_add.map(&:to_s).map(&:strip).each do |mobster_to_add|
raise if mobster_to_add.empty?
fail if mobster_to_add.empty?

if @real_mobsters.map(&:name).include?(mobster_to_add)
puts "user name '#{mobster_to_add}' already exists"
Expand All @@ -104,9 +104,7 @@ def add_mobster(*mobsters_to_add)

def remove_mobster(given_mobster)
@real_mobsters.each_with_index do |mobster, i|
if found_mobster(mobster, given_mobster)
@real_mobsters.delete_at(i)
end
@real_mobsters.delete_at(i) if found_mobster(mobster, given_mobster)
end
sync
end
Expand All @@ -118,22 +116,22 @@ def remove_mobsters(*mobsters)
end

def show_help
puts ['Available commands are:',
'show',
'help',
'rotate',
'random',
'add <name1> [name2]',
'remove <name1> [name2]',
'run_with_timer [seconds]'
]
end

def self.annoying_and_probably_not_accidental_beep(n=number_of_beeps)
puts ["Available commands are:",
"show",
"help",
"rotate",
"random",
"add <name1> [name2]",
"remove <name1> [name2]",
"run_with_timer [seconds]"
]
end

def self.annoying_and_probably_not_accidental_beep(n = number_of_beeps)
n.times { print("\a") || sleep(minimum_sleep_between_beeps) }
end

def countdown_to_rotate(seconds=300)
def countdown_to_rotate(seconds = 300)
sleep(seconds)
puts "Time to rotate"
self.class.annoying_and_probably_not_accidental_beep
Expand All @@ -159,7 +157,7 @@ def rotate
end
end

def random(seed=nil)
def random(seed = nil)
puts "Randomized Output"

rotate_mobsters do
Expand All @@ -173,7 +171,6 @@ def extract_next_mobster_email
email.empty? ? "mob@rubysteps.com" : email
end


def time_to_rotate
puts "Time to rotate!"
end
Expand All @@ -187,20 +184,18 @@ def self.number_of_beeps
end

def extract_name_from(entry)
entry_to_array = entry.split('')
entry_to_array.take_while { |c| c != '<' }.join('').strip
entry_to_array = entry.split("")
entry_to_array.take_while { |c| c != "<" }.join("").strip
end

def extract_email_from(entry)
result = if entry =~ /\<(.*)\>/
$1
end
result = Regexp.last_match(1) if entry =~ /\<(.*)\>/
end

private

def git_config_update
#FIX yo that rescue nil is bogus
# FIX yo that rescue nil is bogus
system "git --git-dir=#{@git_dir} config user.name '#{@real_mobsters.first.name}'" rescue nil
system "git --git-dir=#{@git_dir} config user.email '#{extract_next_mobster_email}'" rescue nil
end
Expand Down
14 changes: 7 additions & 7 deletions spec/database_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative 'spec_helper'
require_relative "spec_helper"

describe MobRotation::Database do
let(:temp_rotation_db) { '/tmp/rotation_test.txt' }
let(:temp_rotation_db) { "/tmp/rotation_test.txt" }

it 'formats the mobster, maintaining original name and email data' do
it "formats the mobster, maintaining original name and email data" do
database = MobRotation::Database.new(temp_rotation_db)

name, email = " David ", " david.is.great@i.am.fab.com "
formatted_name_and_email = database.format_mobster(name,email)
name = " David "
email = " david.is.great@i.am.fab.com "
formatted_name_and_email = database.format_mobster(name, email)

expect(formatted_name_and_email).to eq(' David < david.is.great@i.am.fab.com >')
expect(formatted_name_and_email).to eq(" David < david.is.great@i.am.fab.com >")
end

end
4 changes: 2 additions & 2 deletions spec/foo_fighter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

describe FooFighter do
it "raises an error when a class defines `#foo`" do
expect {
expect do
class TestClass
extend FooFighter

def foo
"shouldn't work"
end
end
}.to raise_error(/no foo for you/)
end.to raise_error(/no foo for you/)
end

it "removes a method named `#foo`" do
Expand Down
22 changes: 11 additions & 11 deletions spec/mob_rotation_executable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_rotate_with_specified_redirect(command = nil, env = nil, redirect = nil)

def our_output
@our_output ||= File.readlines("./tmp/results.txt").collect(&:strip)
.reject(&:empty?)
.reject(&:empty?)
end

context "command: ruby mob_rotation" do
Expand Down Expand Up @@ -133,7 +133,7 @@ def our_output
run_rotate("random 0")

git_username = `git --git-dir=./tmp/test_project/.git config user.name`
.strip
.strip
expect(git_username).to eq("Phoebe Example")
end
end
Expand Down Expand Up @@ -208,7 +208,7 @@ def our_output
run_rotate("rotate")

git_username = `git --git-dir=./tmp/test_project/.git config user.name`
.strip
.strip
expect(git_username).to eq("Phoebe Example")
end

Expand All @@ -219,7 +219,7 @@ def our_output
run_rotate("rotate")

git_email = `git --git-dir=./tmp/test_project/.git config user.email`
.strip
.strip
expect(git_email).to eq("phoebe@example.com")
end

Expand All @@ -233,7 +233,7 @@ def our_output
run_rotate("rotate")

git_email = `git --git-dir=./tmp/test_project/.git config user.email`
.strip
.strip
expect(git_email).to eq("joe@example.com")
end

Expand All @@ -245,9 +245,9 @@ def our_output
run_rotate("rotate")

git_email = `git --git-dir=./tmp/test_project/.git config user.email`
.strip
.strip
git_global_user_email = `git config --global user.email`
.strip
.strip
expect(git_email).to eq(git_global_user_email)
end

Expand All @@ -261,7 +261,7 @@ def our_output
run_rotate("rotate")

git_email = `git --git-dir=./tmp/test_project/.git config user.email`
.strip
.strip
expect(git_email).to eq("joe@example.com")
end
end
Expand All @@ -287,7 +287,7 @@ def our_output
run_rotate("add Ralph")

expect(our_output).to include("user name 'Ralph' already exists")
expect(our_output.select { |l| l.include?("Ralph") }.size).to eq(2)
expect(our_output.count { |l| l.include?("Ralph") }).to eq(2)
end
end

Expand Down Expand Up @@ -317,9 +317,9 @@ def our_output
end

it "waits until time runs out before stating 'Time to Rotate'" do
expect {
expect do
Timeout.timeout(1) { run_rotate("run_with_timer 5") }
}.to raise_error(Timeout::Error)
end.to raise_error(Timeout::Error)
expect(our_output).to eq([])
end

Expand Down
4 changes: 2 additions & 2 deletions spec/rotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe MobRotation::Rotation do
extend FooFighter

let(:mob_rotator) {
let(:mob_rotator) do
MobRotation::Rotation.new(
MobRotation::Database.new(file_name),
"./tmp/test_project/.git"
)
}
end

before { FileUtils.rm_f(file_name) }

Expand Down