Skip to content

Instantly share code, notes, and snippets.

View novohispano's full-sized avatar

Jorge Téllez novohispano

View GitHub Profile
require 'spec_helper'
describe "Apple" do
let (:apple) { Fruit::Apple.new }
describe "#initialize" do
context "when given no parameters" do
it "variety is 'Granny Smith'" do
expect(apple.variety).to eq "Granny Smith"
end
module Fruit
class Apple
require 'time'
attr_accessor :variety
def initialize(variety = "Granny Smith")
@variety = variety
@remaining_slices = apple_size
@created_at = Time.now
class Encryptor
def cypher(letter, rotation)
(letter.ord + rotation).chr
end
def encrypt(message, rotation)
letters = message.split("")
letters.collect { |letter| cypher(letter, rotation) }.join
end
---
LongMethod:
max_statements: 8
FeatureEnvy:
enabled: false
IrresponsibleModule:
enabled: false
UncommunicativeVariableName:
enabled: false
@novohispano
novohispano / gist:7235442
Created October 30, 2013 16:15
Array of hashes
slugs = ["menu", "index", "food"]
contents = ["menu contents", "index contents", "food contents"]
pages = []
pages = slugs.each_with_index do |slug, index|
{slug: slug, content: contents[index]}
end
# [{slug: "menu", content: "menu contents"}, {slug: "index", content: "index contents"}]
@novohispano
novohispano / seed.rb
Created November 5, 2013 18:06
Seeder example
class Seeder
def create_data
100.times do
create_user
create_event
end
end
private
@novohispano
novohispano / item.rb
Created January 9, 2014 23:00
Testing with Darryl
class Item < ActiveRecord::Base
has_many :order_items
has_many :orders, through: :order_items
validates :name, presence: true, uniqueness: true
validates :description, presence: true, uniqueness: true
end
@novohispano
novohispano / beer-song.rb
Last active January 2, 2016 20:49
Beer Song excercism solution.
require 'forwardable'
class BeerSong
def verse(number)
fragments = build_fragments(number)
Verse.new(fragments).to_s
end
def verses(start, ending = 0)
song = ""
@novohispano
novohispano / user.rb
Created January 21, 2014 22:33
Rails Model Testing Exercise
class User < ActiveRecord::Base
has_many :orders
validates :name, presence: true
validates :email, presence: true, uniqueness: true
end
@novohispano
novohispano / item_spec.rb
Created January 30, 2014 23:17
Example of Model Testing
require 'spec_helper'
describe Item do
it "should exist" do
item = Item.new
expect item
end
it "should have a name" do
item = Item.new(name: "hammer")