Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created October 15, 2013 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahimmelstoss/6991688 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6991688 to your computer and use it in GitHub Desktop.
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
#implement a song class and artist class to pass the specs below.
#serialize method should replace spaces in the song title with underscores
#and write to the current working directory
class Song
attr_accessor :title, :artist
def file_name
self.title.gsub(" ", "_").downcase
end
def serialize
File.open("#{file_name}.txt", "w+") do |file|
file << "#{self.artist.name} - #{self.title}"
end
end
def deserialize(file)
end
end
class Artist
attr_accessor :name
def initialize(artist)
self.name = artist
end
end
describe Song do
it "has a title" do
song = Song.new
song.title = "Night Moves"
song.title.should eq("Night Moves")
end
it "has an artist" do
song = Song.new
song.title = "Night Moves"
song.artist = Artist.new("Bob Seger")
song.artist.name.should eq("Bob Seger")
end
it "can save a representation of itself to a file" do
song = Song.new
song.title = "Night Moves"
song.artist = Artist.new("Bob Seger")
song.serialize
File.read("night_moves.txt").should match /Bob Seger - Night Moves/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment