Created
November 19, 2012 16:53
-
-
Save rubygeek/4111823 to your computer and use it in GitHub Desktop.
Simple Breadcrumb Object with Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Breadcrumb | |
Crumb = Struct.new(:name, :link) | |
attr_reader :crumbs | |
def initialize(name = "Home", link = "/") | |
@crumbs = [] | |
self.add(name, link) | |
end | |
def add(name, link) | |
@crumbs << Crumb.new(name,link) | |
end | |
end | |
------ and tests -------- | |
describe Breadcrumb do | |
describe '#new' do | |
it 'sets default crumb of Home /' do | |
@breadcrumb = Breadcrumb.new | |
@breadcrumb.should have(1).crumb | |
@breadcrumb.crumbs.first.name.should == 'Home' | |
@breadcrumb.crumbs.first.link.should == '/' | |
end | |
it 'sets initial crumb of Main /main' do | |
@breadcrumb = Breadcrumb.new('Main', '/main') | |
@breadcrumb.should have(1).crumb | |
@breadcrumb.crumbs.first.name.should == 'Main' | |
@breadcrumb.crumbs.first.link.should == '/main' | |
end | |
end | |
describe '#add' do | |
it 'a second crumb' do | |
@breadcrumb = Breadcrumb.new | |
@breadcrumb.add('Products', '/products') | |
@breadcrumb.should have(2).crumbs | |
end | |
end | |
--------- | |
output of spec doc | |
Breadcrumb | |
#new | |
sets default crumb of Home / | |
sets initial crumb of Main /main | |
#add | |
a second crumb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmm i stil not happy with the names of the tests for #new ...