Skip to content

Instantly share code, notes, and snippets.

View scottcreynolds's full-sized avatar

Scott C Reynolds scottcreynolds

View GitHub Profile
require_relative './jukebox'
RSpec.configure do |config|
config.color_enabled = true
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
def capture_stdout(&block)
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end

##RSpec Code Coverage Lab

How do we know we have enough tests, and that our tests cover all of our code?

Enter simplecov! simplecov is a tool that will measure your test run against the code paths in your code files and see if you're exercising them all. "Code Paths" includes method calls, conditional statements, loops, and anything that branches program flow.

This is important because you want to be able to know that every decision your program makes is being tested, no matter what.

Assignment

class Student
attr_accessor :name, :twitter, :linkedin, :facebook, :website
attr_reader :id
@@students = []
def initialize
if @@students.count == 0
@id = 1
else
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
@scottcreynolds
scottcreynolds / Readme.md
Last active December 24, 2015 12:29
Lab: Bugs! Download all files, and look at Readme.md for instructions.

You're new on the job and have been given ownership of the company's jukebox application. Unfortunately, before you can even begin adding cool new features to make it much, much more awesome than it is now, you fire it up and it won't even run! Now you have to go through the code and squash all the bugs (there's a bunch!).

Given the following spec, dive into the code and fix one problem at a time until the program's output matches the spec and there are no errors!

to run the program, type ruby runner.rb

Remember!

  1. read your error messages carefully, check error messages and line numbers
  2. use pry or irb to check your assumptions!
  3. not all bugs will throw errors, check the output against the spec!
require_relative './song_library.rb'
def jukebox(command)
if command.downcase == "list"
list_library
else
parse_command(command)
end
end
#create a method called create_groups that, given an array of student names,
#a group size, and a number of groups, will return an array of groups of
#of students with no student in adjacent groups
def create_groups(student_array, group_size, number_of_groups)
student_list = student_array.shuffle
groups = []
number_of_groups.times do
s = student_list.shift(group_size)
groups << s
def my_while(condition, &body)
if condition.call
body.call
my_while(condition, &body)
end
end
x = 1
my_while -> {x < 10} do
puts x
@scottcreynolds
scottcreynolds / blog_post_scheduler.rb
Last active December 24, 2015 09:59
Download gist and make the RSpec tests pass by implementing the create_groups method. Don't forget to also implement the pending tests, meaning you have to write those tests yourself!
#create a method called create_groups that, given an array of student names,
#a group size, and a number of groups, will return an array of groups of
#of students with no student in adjacent groups