Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Monthly Archives: March 2012

JT Archie

[Standup][NY] 03/08/2012

JT Archie
Thursday, March 8, 2012

Interesting

  • Ruby MRI seems to have taken a step back in time, a dangerous, but useful feature (to some) is the goto statement.
  • It appears that DateTime object has some issues with doing math.

    DateTime.now - 1.hour #raises TypeError
    DateTime.now - 3600   #works as expected
    1.hour.class          #Fixnum
    
  • Reading the CSS property background-position in Chrome returns an invalid value. Don’t rely on it.

  • Github was hacked! They had a security issue that was a result of attr_accessible being uses incorrectly. Remember to authorize your SSH keys.
  • Need help with cron? Use http://cronwtf.github.com to convert cron into friendly English.
  • &&, ||, and ! vs. and, or, and not. It is highly recommended to always use the strict logical operators (&&, ||, and !) because the keywords
    (and, or, and not) don’t have the same operator precedence.
  • When evaluating variables in strings with bash, its better to use ${var} than $var. The curly-brace allows you to evaluate a variable with copy behind it. For example, ${var}asdf and $varasdf evaluate differently because of the expected variable name.

Help

  • Rails <3.1 has some gotchyas when using :inverse_of option.

    class Note < ActiveRecord::Base
      has_many :contacts, inverse_of: :note
    end
    
    
    class Contact < ActiveRecord::Base
      belongs_to :note, touch: true #for triggering the note observer when the contact is updated
    end
    
    
    class NotObserver
      def after_touch(note)
        note.contacts # does not have the new attributes updated unless you specify the :inverse_of
      end
    end
    
    
    # Somewhere in the code...
    contact.update_attributes....
    
  • When table names are not namespaced on a class. What is the best way to work with this if we want table names to be namespaced?

    class Foo::Bar < ActiveRecord::Base
    end
    
    
    > Foo::Bar.table_name == "bars"
    true
    
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Barinek

Portico is looking for a Web Application Developer

Mike Barinek
Wednesday, March 7, 2012

At Pivotal Labs, one of the services we provide our clients is helping them interview and hire. Pivotal Labs and our clients place a strong emphasis on Agile development and its many aspects: Pair Programming, Test-Driven Development, rapid iterations, and frequent refactoring.

ESSENTIAL DUTIES AND RESPONSIBILITIES:

Portico by Exclusive Resorts® www.porticoclub.com is a new private club that provides access to a growing portfolio of incredible luxury vacation homes in the world’s best destinations, combined with personalized pre-trip planning and expert concierge service. Portico leverages the unmatched track record and expertise of Exclusive Resorts®, the company that has set a new standard for luxury travel and has provided more than 150,000 exceptional vacations for tens of thousands of its members and their family and friends.

We are looking for a developer to help create an exceptional, custom-built luxury travel solution for our rapidly growing member base and portfolio of homes. Responsibilities include interpreting requirements to identify and evaluate solution alternatives, developing and deploying high-quality applications. You are expected to consistently produce reliable, scalable, high-performance technology solutions using modern design and development patterns. You will be an integral component of strong, tightly-knit, collaborative development team working with a product owner and other key internal business stakeholders.

JOB REQUIREMENTS:

  • Proven experience in development of flexible and scalable web-based applications
  • Passion for technology, specifically software development
  • 1+ years of experience with Ruby language and the Rails framework, be proficient with the entire Ruby on Rails stack
  • 3+ years of hands-on web development, demonstrating:
  • Proficiency with HTML/XHTML, CSS, JavaScript and JQuery
  • Sound object oriented design skills and knowledge of application architecture patterns
  • Proficiency with relational databases, including design and development
  • Working knowledge in development of MVC-based web solutions
  • Ability and desire to thrive in an Extreme Programming environment, including pair programming
  • Competency managing source control and automated build processes
  • Excellent analytical and problem solving skills
  • Strong communication and interpersonal skills

DESIRED EXPERIENCE:

  • Experience with agile software development methodologies such as SCRUM and/or XP
  • Working knowledge with test-driven development and related frameworks (preferably with RSpec and/or Test::Unit)
  • Working knowledge of associated platforms and technologies, including Linux and Apache

careers@exclusiveresorts.com

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 3/7/2012

Pivotal Labs
Wednesday, March 7, 2012

New Faces

No new faces today

Help

What is the approved way of finding out if a migration is pending? Trying to avoid Heroku restart.

Interesting

Heroku + submodule: .slugignore is your friend!

Onsi says:

Heroku supports git submodules! However, when building your slugs it includes the .git directory in your submodules. This unnecessarily inflates the slug’s size. To circumvent this make a .slugignore file in your app’s root directory add path/to/submodule/.git to it. You can also use .slugignore to ignore specs, docs, etc…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

DevOps for Developers: When the site goes down I should know what to do

Wednesday, March 7, 2012

Agile brings the idea that when designing a product, collaboration produces better results than conflict, but all too often a familiar us-vs-them war breaks out between developers and operations. Devops is a buzzword, but in reduction it means putting the people in charge of writing the code in charge of keeping it running. Pivot Matthew Kocher attempts to convince you that you want to run your own site, and teaches you a little bit about how to do it.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Stephan Hagemann

Specific interfaces – in the small

Stephan Hagemann
Wednesday, March 7, 2012

Everyone on the Web I found who states that quote I was looking for says “I don’t know who said it, but be ‘Generous on input, strict on output’” (or some variation on this). While I am unsure about the first proposition, I wholeheartedly agree with the second.

Edit 3/8: the quote is known in a different wording as Postel’s Law, which shows up as the Robustness Principle in RFC 793, the specification of TCP. Thanks for the hint, Austin!

Unfortunately, the closest a Rubyist typically gets to the implementation of an interface specification is his tests. This provides a pretty good, but somewhat disconnected specification that can sometimes cover up imprecisions in the interface’s implementation.

On top of that, sometimes our frameworks make it easy to forget what our tests are asserting or spec’ing.

Take rspec’s predicate matchers and this example:

require 'rspec/core'

class VeryImportantQuestions
  def self.really?(answer)
    answer == 'Yes. I am telling you.'
  end

  def self.really_really?(answer)
    answer == 'Yes. I am telling you.' ? 42 : nil
  end
end

describe "really?" do
  context "using rspec predicate matchers" do
    context "if someone is telling you" do
      it "should be really really the case and return true" do
        VeryImportantQuestions.really?('Yes. I am telling you.').should be_true
      end
    end
    context "if someone is not sure" do
      it "should return false" do
        VeryImportantQuestions.really?('I am not sure.').should be_false
      end
    end
  end
end

describe "really_really?" do
  context "using rspec predicate matchers" do
    context "if someone is telling you" do
      it "should be really really the case and return true" do
        VeryImportantQuestions.really_really?('Yes. I am telling you.').should be_true
      end
    end
    context "if someone is not sure" do
      it "should return false" do
        VeryImportantQuestions.really_really?('I am not sure.').should be_false
      end
    end
  end
end

be_true and be_false effectively hide the fact that what’s actually spec’ed is truthiness and falsiness. Only when the following context is added is this imprecision revealed:

  context "spec'ing the actual output of the method fails" do
    context "if someone is telling you" do
      it "should be really really the case and return true" do
        VeryImportantQuestions.really_really?('Yes. I am telling you.').should == true
      end
    end
    context "if someone is not sure" do
      it "should return false" do
        VeryImportantQuestions.really_really?('I am not sure.').should == false
      end
    end
  end

With regard to rspec, I suggest to consider twice whether the benefits of using specific matchers to not outweigh their benefits in your situation. You might get nicer test output, but you might lose the ability to immediately tell what you’re spec’ing.

With regard to tests in general: be specific about what you output – aka be specific about what you test.

Here is the gist: https://gist.github.com/1998462

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Barinek

Testing Ruby Services without Mocks

Mike Barinek
Wednesday, March 7, 2012

There seems to be a tendency to stub or mock classes when writing integration tests for basic http services. I’m actually not a big fan of this approach. By definition, the integration test should truly integrate with another subsystem. In the case of a http service, the tests should probably integrate over http, agreed?

Here’s one approach for testing services without stub or mocks…

Imagine a reservation booking system that integrates with a 3rd party API. By default, you might create a Rails model that extends ActiveModel, ActiveRecord or even ActiveResource. Although you stop, after reading this blog post, and create an unbuilt Gem that reaches out to the 3rd party service. Your service might look something like this…

require "rack"
require "nokogiri"

class ReservationService
  def create_reservation(reservation)
    url = URI.parse('http://localhost:9393/')
    http = Net::HTTP.new(url.host, url.port)
    response, body = http.post(url.path, reservation.to_xml, {'Content-type' => 'text/xml; charset=utf-8'})
    reservation = Reservation.from_xml(body)
    reservation
  end
end

More important, your immutable model might look something like this. (Note: I’m not inheriting from a Active* base class, although I’ll save the inheritance discussion for another blog post)

class Reservation
  attr_reader :name, :date, :duration, :booked

  def initialize(name, date, duration, booked = false)
    @name = name
    @date = date
    @duration = duration
    @booked = booked
  end

  def to_xml
    doc = <<XML
<?xml version="1.0" encoding="UTF-8"?>
<reservations>
  <reservation>
    <name>#{@name}</name>
    <date>#{@date}</date>
    <duration>#{@duration}</duration>
    <booked>#{@booked}</booked>
  </reservation>
</reservations>
XML
    doc
  end

  def self.from_xml(xml)
    doc = Nokogiri::HTML(xml)
    doc.xpath("//reservation").each do |reservation|
      reservation.children.each do |child|
        case child.name
          when "name"
            @name = child.text
          when "date"
            @date = Date.parse(child.text)
          when "duration"
            @duration = child.text.to_i
          when "booked"
            @booked = eval(child.text)
        end
      end
    end
    Reservation.new(@name, @date, @duration, @booked)
  end
end

Then you start writing tests. You stub the service, then you stub Typhoeus. You might pull Typhoeus and use Artifice or rack-test. Sure the approach works, although are you really testing the full integration (they do stub at the lowest level)?

You could argue a more complete integration test might include the http layer. One approach might be to fire up a simple rack handler that matches the API specification.

Here’s an example…

require "test/unit"
require "date"

require File.expand_path(File.join(File.dirname(__FILE__), "reservation_service"))

class TestServer
  def initialize(response_code, response_body, response_headers = {})
    @response_code = response_code
    @response_body = response_body
    @response_headers = response_headers
  end

  def start
    @thread = Thread.new do
      Rack::Handler::WEBrick.run(self, :Port => "9393", :Host => "localhost")
    end
    sleep 1
    puts "started server."
  end

  def stop
    Thread.kill(@thread)
    puts "stopped server."
  end

  def call(env)
    [@response_code, @response_headers, [@response_body]]
  end
end

class TestService < Test::Unit::TestCase
  def test_create_reservation
    expected_reservation = Reservation.new("John Brown", Date.today, 3, true)

    server = TestServer.new(200, expected_reservation.to_xml, {})
    server.start

    service = ReservationService.new
    actual_reservation = service.create_reservation(Reservation.new("John Brown", Date.today, 3))

    assert_equal(expected_reservation.name, actual_reservation.name)
    assert_equal(expected_reservation.date, actual_reservation.date)
    assert_equal(expected_reservation.duration, actual_reservation.duration)
    assert_equal(expected_reservation.booked, actual_reservation.booked)

    server.stop
  end
end

(Typhoeus actually uses a similar approach via TyphoeusLocalhostServer.rb within their own test suite)

You might ask why not just integrate with the 3rd party’s API sandbox environment. Because doing so could impact test performance as well as your ability to run tests – you become too dependent on their service’s availability.

A similar approach might be to VCR, although VCR might not work without an actual sandbox environment.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Devops for Developers

Tuesday, March 6, 2012

Matthew Kocher talks about devops for developers.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 03/05/2012

Pivotal Labs
Monday, March 5, 2012

New Faces

Rachel Bobbins – new intern

Help

Web 2 App – is there a service to mobile-optimise web sites?

There are many

Rubymine and Spork issue: when starting Spork from Rubymine, Rubymine doesn’t format test output correctly

The solution currently in use is to add a RUBYMINE_HOME path to the bash profile:

export RUBYMINE_HOME=/Applications/RubyMine.app/

And also the following block to a file loaded by spec_helper.rb (ex: YOUR_PROJECT/spec/support/rubymine.rb )

if ENV['RUBYMINE_HOME']
  $:.unshift(File.expand_path('rb/testing/patch/common', ENV['RUBYMINE_HOME']))
  $:.unshift(File.expand_path('rb/testing/patch/bdd', ENV['RUBYMINE_HOME']))
end

caveat: It may be necessary to launch Rubymine from a terminal with the mine command, rather than from the Dock or Spotlight, because variables set in .bash_profile normally apply only to the terminal environment in Mac OS X. See: Runtime Configuration Library: Environment Variables

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Mongo Madness!

Pivotal Labs
Friday, March 2, 2012

New faces

No new faces today.

Requests for help

“MongoMapper v. Mongoid v. Candy v. etc…? Which should I use?”

A1: Don’t use a mapper at all, just interact with MongoDB directly. If you use a mapper, choose a library that’s least like Active Record.
A2: We used MongoMapper and it worked out okay. It doesn’t behave like Active Record in some ways, but it wasn’t a huge problem.
A3: We had to fight against Mongoid, since it only provided a subset of what Active Record provides and it didn’t provide some MongoDB specific things.

“Does anyone have experience with the awesome nested set library? Nested set is getting corrupted when storing information in a tree”

No answers from the crowd.

Interesting/Protips

A heads up: Rails XSS – two patches were released, but one doesn’t work for Rails 2.

There’s a cool Blabs out about running jasmine in the background @ full speed. Check it out!

Subscribe to the Pivotal Blabs RSS feed!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mark Rushakoff

Make Jasmine run at (near) full-speed in a background tab

Mark Rushakoff
Friday, March 2, 2012

Jasmine environments have a default updateInterval value of 250 that determines how often, in milliseconds, execution of the next spec will be deferred so that the screen can be updated.

    var now = new Date().getTime();
    if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
      self.env.lastUpdate = now;
      self.env.setTimeout(function() {
        self.next_();
      }, 0);
    } else {
      if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
        goAgain = true;
      } else {
        self.next_();
      }
    }

Both Chrome and Firefox now require a minimum value of one second for setTimeout in a background tab. This basically means that for every 250ms of work that we do, we end up sleeping for 1000ms.

This gist shows one way to tell Jasmine to not even bother trying to update the screen when running in the background.

var foregroundScreenRefreshRate = 1500;
var backgroundScreenRefreshRate = 9000;

jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;

$(window).focus(function() {
    jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;
});

$(window).blur(function() {
    jasmine.getEnv().updateInterval = backgroundScreenRefreshRate;
});

(Please refer to the gist for the most up-to-date code.)

This code makes Jasmine run at full-speed in a background tab in Chrome, but continue to be updated about once every 2.5 seconds when in a foreground tab. However, using this as-is in Firefox will result in a warning about an unresponsive script, if the tab is inactive. Luckily, you can continue to run Firefox in the foreground fine with this script (good for CI perhaps), or you can just override the dom.max_script_run_time variable to never get that warning, or you can set updateInterval to something less than the default 10 second max script run time.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (781)
  • rails (114)
  • testing (88)
  • ruby (84)
  • ruby on rails (70)
  • jobs (62)
  • javascript (56)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (24)
  • mobile (22)
  • process (21)
  • pivotal tracker (21)
  • cucumber (20)
  • design (19)
  • jasmine (19)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • tracker ecosystem (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • tdd (14)
  • gem (13)
  • css (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. ←
  2. 1
  3. 2
  4. 3
  5. 4
  6. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >