Skip to content

Instantly share code, notes, and snippets.

@senny
Created January 7, 2012 11:26
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 senny/1574493 to your computer and use it in GitHub Desktop.
Save senny/1574493 to your computer and use it in GitHub Desktop.
0047 - brittle and fragile tests
class Screencast
attr_accessor :versions
def initialize(params)
params.each {|key, value| self.send "#{key}=", value }
end
end
class ScreencastCategories
def self.by_tool(screencasts)
by_tool = Hash.new { |hash, key| hash[key] = [] }
screencasts.each do |screencast|
screencast.versions.each do |tool_name, version|
by_tool[tool_name] << screencast
end
end
by_tool
end
end
require 'rspec/autorun'
describe ScreencastCategories do
it 'groups by tool' do
screencast = Screencast.new(:versions => {:vim => '7.3'})
by_tool = ScreencastCategories.by_tool([screencast])
by_tool.fetch(:vim).should == [screencast]
end
end
class ScreencastCategories
def self.by_tool(screencasts)
by_tool = Hash.new { |hash, key| hash[key] = [] }
screencasts.each do |screencast|
screencast.versions.each do |tool_name, version|
by_tool[tool_name] << screencast
end
end
by_tool
end
end
require 'rspec/autorun'
describe ScreencastCategories do
it 'groups by tool' do
screencast = stub(:screencast, :versions => {:vim => '7.3'})
by_tool = ScreencastCategories.by_tool([screencast])
by_tool.fetch(:vim).should == [screencast]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment