kareemgrant
2/11/2013 - 9:53 PM

Event_manager testing exercise

Event_manager testing exercise

require 'minitest/autorun'
require './lib/zipcode'

class ZipcodeTest < MiniTest::Unit::TestCase

  def test_it_exists
    zipcode = Zipcode.new
    assert_kind_of Zipcode, zipcode
  end
end
require 'minitest/autorun'
# require './lib/attendee'
require './lib/phone_number'



class PhoneNumberTest < MiniTest::Unit::TestCase

  # def setup
  #   @phone = Phone.new
  # end

  def test_if_exists
    phone = PhoneNumber.new
    assert_kind_of PhoneNumber, phone
  end

  def test_it_cleans_up_phone_numbers_with_periods_and_hyphens
    phone = PhoneNumber.new("202.444-9382")
    assert_equal "2024449382", phone.number
  end

  def test_it_removes_leading_one_from_an_eleven_digit_phone_number
    phone = PhoneNumber.new("12223334444")
    assert_equal "2223334444", phone.number
  end

  def test_it_throws_away_phone_numbers_that_are_too_long
    phone = PhoneNumber.new("23334445555")
    assert_equal "0000000000", phone.number
  end

  def test_it_throws_away_phone_numbers_that_are_too_short
    phone = PhoneNumber.new("2223334")
    assert_equal "0000000000", phone.number
  end

  def test_if_provides_default_for_nil_numbers
    phone = PhoneNumber.new
    assert_equal "0000000000", phone.number
  end



end
class PhoneNumber
  attr_reader :number

  def initialize(number = nil)
    @number = clean_phone_number(number)
  end

  def clean_phone_number(number)
    if number
      number = number.gsub(/[^0-9]/, "")

      if number.length == 11 && number[0] == "1"
        number = number[1..-1]
      elsif number.length == 10
        number
      else
        number = "0000000000"
      end
    else
      number = "0000000000"
    end
  end

end
require 'minitest/autorun'
require 'minitest/pride'

require './event_manager'

class EventManagerTest < MiniTest::Unit::TestCase

  def test_it_exists
    em = EventManager.new
    assert_kind_of EventManager, em
  end
end
require 'minitest/autorun'
require './lib/attendee'

class AttendeeTest < MiniTest::Unit::TestCase

  def test_it_exists
    attendee = Attendee.new
    assert_kind_of Attendee, attendee
  end

  def test_it_is_initialized_from_a_hash_of_data
    data = {:first_name => 'George', :last_name => 'Washington', :phone_number => '2024556677'}
    attendee = Attendee.new(data)
    assert_equal data[:first_name], attendee.first_name
    assert_equal data[:last_name], attendee.last_name
    assert_equal data[:phone_number], attendee.phone_number
  end

  def test_it_can_change_first_name
    data = {:first_name => "George"}
    attendee = Attendee.new(data)
    assert_equal data[:first_name], attendee.first_name
    attendee.first_name = "Thomas"
    assert_equal "Thomas", attendee.first_name
  end

end
require './lib/phone_number'

class Attendee

  attr_accessor :first_name, :last_name, :phone_number

  def initialize(input = {})
    @first_name = input[:first_name]
    @last_name = input[:last_name]
    @phone_number = PhoneNumber.new(input[:phone_number]).number #clean_phone_number(input[:phone_number])
  end




end
require 'rake/testtask'

Rake::TestTask.new do |t|
  t.pattern = "test/*_test.rb"
end