Switch branches/tags
Nothing to show
Commits on Jan 12, 2012
  1. Put things in their own files.

    steveklabnik committed Jan 12, 2012
    We should try to stick to one class per file. Same
    with specs.
  2. Cleaned up the look of the code.

    steveklabnik committed Jan 12, 2012
    Those comments were pretty bad; they just re-iterated what the
    code does, rather than why the code is doing it. We'll reintroduce
    comments in another commit, but first, let's just clean up the look
    and some minor spacing issues.
  3. using rspec's let feature to great effect.

    steveklabnik committed Jan 12, 2012
    Two changes here: the first is to use an awesome feature of rspec: let.
    Basically, we can let rspec instantiate our object, which gets
    all of that typing of long class names out of the way. It also lets
    our tests focus on what's important, and ignore what isn't. Read the tests
    now: "When the ip is this, I expect the locator to do that."
    The second thing was breaking the last test into two. I wanted to do
    this as a separate step, but it didn't work until I made the change:
    you really had two assertions in that last one. It deserves its own
  4. removing outdated tests.

    steveklabnik committed Jan 12, 2012
    Let's only keep the new tests, now that we're sure about them.
  5. introducing tests for the new class.

    steveklabnik committed Jan 12, 2012
    I'm leaving the old tests in for now, to show that we're passing both.
    Since the tests are so similar, we can show that we have a high
    level of confidence that we're testing the same behavior, and
    get rid of the old tests.
  6. Getting rid of private by introducing new class.

    steveklabnik committed Jan 12, 2012
    Your original code felt the tension of two responsibilities: you
    have your own processing to do, as well as processing from calling
    an external service. You can see it in the code: you split it up
    into two methods for a reason. However, you marked the second as
    private, because you didn't want to make that part of your external
    That's great, but testing private methods is difficult, as your tests
    show. You're testing the private method through the public one, which
    is better than some Object#send shennanigans to test it directly.
    However, we can do better!
    Instead, let's make a new object, and consider it private, for our
    own use. We can use that object to wrap the external API, which
    provides two benefits:
    1) clear respect of the SRP principle. One object for our stuff, one
    object for external processing.
    2) a seam to migrate to a different service in the future. We can implement
    and use a different external service object, and none of our code
    has to change.
    Because we're testing through the public methods, no changes in tests are required.
  7. From structured to OO style.

    steveklabnik committed Jan 12, 2012
    The current style of the code is in a procedural style. "Here's a
    function, it's namespaced by my class." The standard idiom would
    have been to do this:
    module Geolocator
      extend self
      def ip_lookup
    However, Ruby is OO, not procedural. Let's take advantage of that!
    Basically, you can construct an object with the arguments instead.
    So now, we construct a geolocator object with an IP address, and
    then ask it to look up the IP.
    Right now it might not seem like much, but imagine two or three
    operations on an object:
    locator ="123.456.789.123")
    Much more DRY.
    There are also testing benefits to doing things this way: a bag
    of methods module is harder to test than an object.
  8. adding rake to gemspec

    steveklabnik committed Jan 12, 2012
    It's a good idea to include _all_ the things you rely on in your
    gemspec. That includes rake. Since it's only used for development,
    I've added it as a development dependency.
  9. Merge pull request #1 from jhsu/master

    thoughtpunch committed Jan 12, 2012
Commits on Jan 11, 2012
  1. rename to Geolocator

    jhsu committed Jan 11, 2012
  2. added .gemtest

    thoughtpunch committed Jan 11, 2012
  3. updating README

    thoughtpunch committed Jan 11, 2012
  4. updated README

    thoughtpunch committed Jan 11, 2012
  5. added sections to README

    thoughtpunch committed Jan 11, 2012
  6. bumping to version 0.0.1

    thoughtpunch committed Jan 11, 2012
  7. wrote first tests

    thoughtpunch committed Jan 11, 2012
  8. updated readme

    thoughtpunch committed Jan 11, 2012
  9. first commit

    thoughtpunch committed Jan 11, 2012