Skip to content

Instantly share code, notes, and snippets.

@JonKernPA
Created April 14, 2014 18:53
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 JonKernPA/10674021 to your computer and use it in GitHub Desktop.
Save JonKernPA/10674021 to your computer and use it in GitHub Desktop.
I spent 15 minutes creating a quick example...
require 'spec_helper'
# I spent 15 minutes creating a quick example for an email list...
describe "State" do
it 'has a list of states' do
State.respond_to?(:states)
expect(State.states).to have_key('AK')
end
it '.abbrev' do
expect(State.abbrev('Alaska')).to eq('AK')
expect(State.abbrev('ohio')).to eq('OH')
end
it '.state' do
expect(State.state('AK')).to eq('Alaska')
expect(State.state('pa')).to eq('Pennsylvania')
end
end
class State
STATES = {
'AK'=> 'Alaska',
'PA'=> 'Pennsylvania',
'OH'=> 'Ohio',
}
def self.states
STATES
end
def self.abbrev(state)
STATES.invert[state.titleize]
end
def self.state(abbrev)
STATES.fetch(abbrev.upcase)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment