Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / gigasecond_naive.rb
Created November 9, 2016 15:32
Code that calculates a gigasecond from an inputted time
class Gigasecond
def self.from(date)
return date + 1000000000
end
end
@lkrych
lkrych / gigasecond_refactor.rb
Last active November 10, 2016 22:01
refactored version of gigasecond, uses constant and module functionality
module Gigasecond #convert from class to module
extend self
GIGASECOND = 1e9 #use constant
def from(date) #date must be in Time.utc format
return date + GIGASECOND
end
end
@lkrych
lkrych / getting_started_feature.sh
Created November 14, 2016 22:09
Get your environment set up for BDD and TDD
rails generate cucumber:install capybara
rails generate cucumber_rails_training_wheels:install
@lkrych
lkrych / AddDirectorToMovies.sh
Created November 14, 2016 22:34
generate migration for adding director to movies model
rails generate migration AddDirectorToMovies director:string
bundle exec rake db:migrate #apply migration
@lkrych
lkrych / director.feature
Created November 16, 2016 00:04
Cucumber file that tests if a director can be added to an existing movie
Feature: Add the ability to search by director
As a movie fan
So that I can find movies with my favorite director
I want to be able to add a director to a movie and find other movies with that director
Background: movies in database
Given the following movies exist:
| title | rating | director | release_date |
@lkrych
lkrych / director_steps_incomplete.rb
Created November 16, 2016 17:01
Fill in database in Cucumber
Given(/^the following movies exist:$/) do |movies_table|
movies_table.hashes.each do |movie|
# each returned element will be a hash whose key is the table header.
Movie.create(movie)
end
end
Then(/^the director of "([^"]*)" should be "([^"]*)"$/) do |movie, director|
pending
#still need to do this
@lkrych
lkrych / paths.rb
Last active November 16, 2016 22:22
Update paths.rb in your support file to allow cucumber to access the edit page.
# TL;DR: YOU SHOULD DELETE THIS FILE
#
# This file is used by web_steps.rb, which you should also delete
#
# You have been warned
module NavigationHelpers
# Maps a name to a path. Used by the
#
# When /^I go to (.+)$/ do |page_name|
#
@lkrych
lkrych / update_views.html.haml
Created November 16, 2016 17:13
Update the views to include director field
/for edit.html.haml and new.html.haml
= label :movie, :director, 'Director'
= text_field :movie, 'director'
/for index.html.haml
%table#movies
%thead
%tr
...blah
@lkrych
lkrych / director_steps_complete.rb
Created November 16, 2016 17:28
Complete step-definitions for director.feature
Given(/^the following movies exist:$/) do |movies_table|
movies_table.hashes.each do |movie|
# each returned element will be a hash whose key is the table header.
Movie.create(movie)
end
end
Then(/^the director of "([^"]*)" should be "([^"]*)"$/) do |movie, director|
expect(Movie.find_by_title(movie).director).to eq director #RSpec assertion
end
@lkrych
lkrych / rna_transcription_naive.rb
Created November 18, 2016 13:10
Naive implementation of RNA transcription with case statement
class Complement
def self.of_dna(dna)
rna = ""
dna.split("").each do |nucleotide|
case nucleotide
when "G"
rna << "C"
when "C"
rna << "G"
when "T"