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: November 2011

Pivotal Labs

[Standup][SG] 2011-11-21 – Don’t use GitHub to host your JavaScript!

Pivotal Labs
Sunday, November 20, 2011

Interestings

  • We included a JavaScript file and set its src attribute to a file’s RAW URL on github. After about 400 requests within an hour, github started returning 403.

  • Public Service Announcement: local_assigns is a hash of local variables in a view. Useful when passing those variables on when rendering a partial; instead of enumerating the variables: render :partial 'foo', locals: { bar: bar, baz: baz}, pass the hash of locals: render :partial 'foo', locals: local_assigns

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Glenn Jahnke

Standup 11/18/2011

Glenn Jahnke
Friday, November 18, 2011

Helps

Selenium Firefox Version

“What’s the canonical version of Firefox to use with Selenium”

Firefox 3.6 is recommended.

Compiling Ruby 1.8.7 on Lion

“I’m having trouble compiling Ruby 1.8.7 on Lion.”

Turns out there specifying the version of GCC to use fixed the problem.

CC=4.2 rvm install ruby-1.8.7

File Upload Plugin for jQuery

“What are the recommended jQuery plugins to do file uploading?”

There is a jQuery plugin by blueimp that is supposed to be customizable and backward-compatible for most browsers (even IE6!).

Also, Ajax Upload is supposed to be a reasonable alternative.

Interestings

Memorial Service for Ilya

Ilya Zhitomirskiy’s memorial service will be held today. Everyone is welcome to come from 5pm to 8pm

McAvoy O’Hara
4545 Geary Blvd
San Francisco, CA 94118

Javascript Strangeness

Oh Javascript, you prankster.

typeof(NaN) => “number”

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Ash Hogan

Post+Beam is looking for a Senior RoR Developer

Ash Hogan
Friday, November 18, 2011

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.

Below is the description for a Ruby developer position for Post+Beam, who connect with audiences by listening to their needs, and influencers by understanding their vision. The result is innovation: new products, experiences and processes. Our expertise in communication gets the word out.

Post+Beam is hiring senior Ruby on Rails developers – here’s why you want to work there:

Post+Beam

Description

You will be building web applications and designing websites for clients across multiple industries that integrate with various platforms and third party APIs. This requires rock solid RoR development skills and the ability to work fluidly with a design team.

You will be working for an incubator of funded startups, backed by years of agency experience in PR, marketing, design, and development. This is a fast-paced position that focuses on mobile and web development in multiple industries. As such, your will role will have a heavy stake in product development.

You will be expected to participate in all phases of our software development life cycle to convert concepts and specifications into released web applications and websites. You will be the lead developer at our SF office and work collaboratively with our other offices and realize this is not a managerial position.

Location and Relocation

Our offices are in beautiful South Park in San Francisco. We are very interested in people looking to relocate to join our team.

Requirements

  • BS in Computer Science or equivalent
  • 1-3+ years of RoR experience
  • A proven record of web applications and websites (please provide a link to your portfolio)
  • Obsessive about UI and UX standards
  • Experience with deploying and maintaining cloud hosted websites
  • Ability to produce high quality, well-documented BDD code
  • Experience in NoSQL/mySQL databases and database performance tuning
  • Experience with Amazon Web Services and Heroku
  • Deep knowledge of Ruby on Rails
  • Strong grasp of client-side code (HTML, CSS, JS, JQuery, AJAX)
  • Experience with server side API’s
  • Grasp of algorithms, memory management, object oriented programming, and concurrent programming
  • Strong experience optimizing code for application performance
  • A strong understanding of iterative development cycles
  • Social network API integration experience
  • Reliable with strong communication skills
  • Strong attention to details
  • Self-driven with an ambitious mentality

Bonus Points

  • Participation with the larger professional RoR community and forums
  • Experience with Social API’s (Facebook, Twitter, etc.)
  • Experience with scalability

Innovation

We pay special attention to those that are looking to create the new, not just re-purpose the old. Special consideration will be given to those that show entrepreneurial spirit, are looking to mold the organization, and help create a better agile development environment.

Communication

Candidates should have solid communication skills: on one hand they should be able to “speak truth to power” but at the same time be able to listen to and understand strategic business, design and user needs.

Salary and Compensation

Based on experience, talent and ability to innovate and communicate. Strong bonus tied to delivery of successful startups in the incubator.

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

[Standup][SG] 2011-11-17 – Chock-full of JavaScript

Pivotal Labs
Thursday, November 17, 2011

Helps

“Adding a JS alert box (with remote:true, confirm: 'Are you sure?' on a link_to) causes the cucumber feature to fail. It looks like, after we accept the alert with page.page.driver.browser.switch_to.alert.accept, the browser runs much slower than the cucumber feature, so while everything technically works, the feature fails. We worked around this by delaying cucumber with page.should have_no_content('content inside removed li') but it feels like a hack. Does anyone know what could be wrong with our setup, or is this to be expected?”

  • There were no comments other than the work-around we’re already using.

“The pattern we use when testing ajax calls in Jasmine feels unsatisfactory because expect($.ajax).toHaveBeenCalledWith({ /* all params here */}); requires all the parameters passed to the ajax call to be specified in the expectation. This includes parameters we don’t care about, such as beforeSend (which is passed by Rails’ remote: true). There must be a better way?”

  • One suggestion was to use something like RSpec’s hash_including, or building it if it doesn’t exist. Turns out, there’s a pull request from earlier this year with just this improvement.

Interestings

  • To get the html of an element (ie: a ‘ul’) including itself, append the element to a new element (ie: an empty div), then get the html of the new element. For example: $('<div>').append($('ul')).html(). The element’s parent could also be used if the element is an only child.

  • When appending an element which already exists in the DOM to another element, it will be moved from its present location in the DOM. This can be problematic when using the trick above to generate an element’s html, and is fixed by cloning the element.

  • If you see ‘Timezone Displacement out of range’ when doing a heroku db:push, it’s probably because you’re using Ruby 1.9.3 in development while Heroku runs 1.9.2. Don’t do that.

Events

  • GOV Camp at Suntec City TODAY, November 18, 2-10pm
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Glenn Jahnke

Standup 11/17/2011 – Cloudy Cloud

Glenn Jahnke
Thursday, November 17, 2011

Interestings

Travis CI: Javascript Testing in the Cloud

Jasmine gem test suites are now being run on Travis CI which is an open, distributed build system for the open source community.

Check out Travis CI.

Fix Git Author

As Pivots move to different machines frequently when we pair switch, its often a problem that we forget to switch the author when we commit to Git. Here’s how you can fix the author of a commit (before you’ve pushed to remote).

  1. change your git author
  2. git commit –amend –reset-author -C HEAD

This changes the author of commit to whomever is configured in the git config, and uses the same message you previously used (the -C HEAD part).

TDDium Cloud Test Runner

TDDium is an easy-to-use, secure, hosted testing environment that takes the tedium out of building high quality Ruby web applications using Test Driven Development and Continuous Integration.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
JT Archie

[Standup][NYC] 2011-11-16 – Lion is not Enterprise ready

JT Archie
Thursday, November 17, 2011

Interesting

  • If you are trying to get REE on Lion make sure that you have GCC 4.2 or higher. Learn more.
  • If you are still using a mouse with scroll wheel in Lion, disable the middle click annoyance with Mission Control.

Help

  • Donate for Movember we are team ‘Pivots NY’. We grow facial hair for Man Cancer Awareness Month.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Glenn Jahnke

Standup 11/16/2011 – Blamo things

Glenn Jahnke
Wednesday, November 16, 2011

Helps

Rails Shopping Carts

“Can anyone recommend a good Rails shopping cart?”

Spree was mentioned as reasonable suitable, but it does not support multiple merchants.

Interestings

Modernizer < 2.0 hates IE7

A Pivot was experiencing Modernizer at versions less than 2.0 throwing insecure content exceptions because of version detection code that it was using. Upgrading to version higher than 2.0 or removing Modernizer solved the problem.

Resque and New Relic outstanding but

There is a bug when using RPM contrib in New Relic while also using Resque that causes Resque workers to die. Definitely something to watch out for.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dmitriy Kalinin

Cedar and OCUnit

Dmitriy Kalinin
Wednesday, November 16, 2011

tl;dr Latest version of Cedar can nicely integrate with Xcode just like OCUnit.

Why

When creating new Xcode project you might have noticed that New Project dialog has ‘Include Unit Tests’ checkbox at the bottom. When that option is selected in addition to creating an app target Xcode will also create a separate target that is used for testing your application. This target most likely will be named [app]Tests. Convenient, huh! Since Xcode is such a nice IDE[1] it will also create an example test file that uses Xcode’s built-in unit testing framework — OCUnit (also known as SenTestingKit). If you never heard of it below is a screenshot of how that example OCUnit test file looks.


Because Apple ships OCUnit with Xcode it is tightly integrated into the IDE and that gives it somewhat of an advantage over other testing frameworks. Example of such unfair treatment is relatively nice looking red error markers (shown above) that show up next to failed test cases when application tests are run. If you have ever used Cedar before you would know that when Cedar specs fail we do not get those markers but rather we are presented with boring gray console output (we have dots though!). Unfortunately there is no documented way for custom testing frameworks to mimic OCUnit behavior without building on top of it. But even if do decide to use OCUnit as a base for your custom testing framework you will run into several problems. One of those problems, at least a year ago, was that you could not reliably use debugger with OCUnit tests. That was one of the main reasons why Cedar was not build on top of it. Recently, however, Xcode 4 was released with a lot of enhancements including better support for running OCUnit tests (with or without debugger) or so it seems. Red markers being a driving force, once again it was worth to investigate on how take advantage of OCUnit goodies from Cedar. Latest version of Cedar succeeds at that. What follows are the steps on how to setup Cedar for maximum Xcode integration.

Setup steps


Check ‘Include Unit Tests’ checkbox in New Project dialog. If you want to add application tests to an existing project here is a very nice tutorial: http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/


After Xcode is done creating a new project file go to Build Settings for application tests target (in this case ExampleTests) and find Other Linker Flags settings. Add -ObjC, -all_load, and -lstdc++ to that setting and click Done.


Next step is to add Cedar static library to application tests target.


Now you are ready to create a Cedar spec file. Create a new empty file and end the filename with ‘Spec.mm’. ‘mm’ file extension is needed to be able to use built-in Cedar matcher library. Also since this file should only be run as part of application tests and not the actual application make sure that you only include it in application tests target.


Add a test or two (see above for example) to be able to test that Cedar is working correctly. Example above tries to assert that 2+2 equals 5 and that should hopefully fail. Notice that here I’m using recently added Cedar matchers should syntax. If you do not like that you can always rewrite that expectation as expect(2+2).to(equal(5));


Larger image.
And finally to run specs you just wrote select scheme for your app (in this case Example) from the drop down in the upper left corner and press ‘Cmd+U’. ‘Cmd+U’ in Xcode by default runs tests associated with selected scheme. That should first build your app (because application tests target lists the app as a target dependency), then build application tests target and then run the tests. Since 2+2 does not equal 5 you will see that Xcode will highlight that line in red and show that as an error in the errors panel on the left side. Fixing that expectation should make the test pass.

Running from the command line

If you want to run your application tests from the command line you can use rake ocunit:application to do that. Before doing so make sure you have updated APP_NAME and OCUNIT_APPLICATION_SPECS_TARGET_NAME in the Rakefile. Also you’ll need to use Debug for CONFIGURATION so that your tests are able to include classes from your application. What’s nice about this rake task is that it is ready to be used on your CI machine since it returns exit code 1 when any tests fail and 0 if they all succeed. It also prints in color.

How it actually works

If you are wondering how Cedar pretends to be OCUnit here is a short summary:

  • When Cedar is loaded it overrides runTests class method on SenTestProbe class (related file to look at is CDROTestIPhoneRunner.m)
  • SenTestProbe +runTests gets called by otest — an executable that Xcode uses to run tests after it injected the application tests bundle into TEST_HOST app
  • Since SenTestProbe +runTests was overridden with Cedar’s run method Cedar executes all of its specs following all the usual rules: focused, pended, etc.
  • When specs are running CDROTestReporter (source) gets notified which tests passed, failed, got skipped, etc. and prints out appropriate information which you see in console log
  • CDROTestReporter prints out failed tests in a way that is recognized by Xcode (OCUnit spits out same output for failed examples) e.g.:
Test Case '-[ExampleTests testExample]' started.
/Users/work/workspace/Example/ExampleTests/ExampleTests.m:16: error: -[ExampleTests testExample] : '4' should be equal to '5': 2+2 != 5
Test Case '-[ExampleTests testExample]' failed (0.000 seconds).
  • Xcode notices that pattern in the console output, parses it, gets filename and line number and marks that file location with a red marker to indicate a test failure

Drawbacks/Not implemented features

  • Debugger support is still a bit flaky but this is a problem with Xcode/OCUnit integration
  • I have not tried running it on the device but it should work
  • If you are used to specifying -SenTest option to run specific test case it will be ignored; however, you can use Cedar’s fit, fdescribe, and fcontext to focus on specific tests
  • Some third party OCUnit add-ons might not work (let us know about them)

Useful links

  • Cedar source code
  • Apple Unit Testing Overview
  • Official but outdated OCUnit and otest source code
  • More recent version of OCUnit source code
  • Public Pivotal Tracker project for Cedar to submit bugs and feature requests

[1] It’s not.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dmitriy Kalinin

Too many parentheses

Dmitriy Kalinin
Wednesday, November 16, 2011

Cedar comes with its own built-in matcher library and here is Adam Milligan’s blog post that explains on how to use it. An example of expectation written using Cedar matcher library:

expect(controller.button).to_not(be_nil());

Even though this is much better than OCHamcrest it is still not satisfying (in my opinion) because there are so many parentheses involved. Since Cedar matcher library is written in C++ we can do some magic here. The result is you can write your expectations like this:

controller.button should_not be_nil;

So let’s dig into how Cedar’s should syntax is implemented.

  controller.button   should_not   be_nil
|-------------------|------------|--------|
    actual value       C macro     matcher

As you might have guessed should and should_not are C macros. Besides making possible for each expectation to know its filename and line number (with __FILE__ and __LINE__ preprocessor variables), they also hide the unnecessary complexity which makes this syntax possible. Here is how it looks expanded:

  controller.button   ,(ActualValueMarker){__FILE__, __LINE__},true,   be_nil
|-------------------|------------------------------------------------|--------|
    actual value                        mumbo jumbo                    matcher

So how does this mumbo jumbo work? Since Cedar matcher library was written in C++ we can overload the comma operator. Besides being a weird operator to overload, it has a useful property that we can exploit here. Comma operator has the lowest precedence among all other operators and that allows us to write 2+2 should equal(4) instead of (2+2) should equal(4). Now let’s break mumbo jumbo into pieces:

(1) <actual value>
    (ActualValueMarker){__FILE__, __LINE__} -> (2) ActualValue
                                                   true/false  -> (3) ActualValueProxy
                                                                      <matcher>

(1) This step captures actual value (can be anything since it is templated), filename and line number. It is implemented like this:

template<typename T>
const ActualValue<T> operator,(const T & actualValue, const ActualValueMarker & marker) {
    return ActualValue<T>(marker.fileName, marker.lineNumber, actualValue);
}

(2) Now we overload comma operator to match ActualValue (returned from step 1) and a bool that indicates whether matcher result should be negated.

template<typename T>
const ActualValueMatchProxy<T> operator,(const ActualValue<T> & actualValue, bool negate) {
    return negate ? actualValue.to_not : actualValue.to;
}

(3) And finally we overload comma operator again so that it matches ActualValueMatchProxy (returned from step 2) and anything else. Second argument will be considered to be a matcher.

template<typename T, typename MatcherType>
void operator,(const ActualValueMatchProxy<T> & matchProxy, const MatcherType & matcher) {
    matchProxy(matcher);
}

That’s pretty much all. Full implementation of should syntax (which is just several more lines more than what is shown above) can be found in ShouldSyntax.h (and corresponding spec file that makes sure syntax works). Everything above allows us to write expectations as follows:

controller.button should_not be_nil();

Since the goal is to get rid of as many parentheses as possible we still have some work to do. Nil matcher that comes with Cedar is implemented with BeNil class. The way it worked before was be_nil was a function defined in Cedar::Matchers namespace. Calling it each time would return a new instance of BeNil class. To make parentheses go away be_nil was turned into a static variable that is initialized only once to an instance of BeNil class. (be_nil matcher still supports being used with two parentheses for backwards compatibility by implementing call operator on BeNil class.) Bam.

controller.button should_not be_nil;

Usually it is not recommended to use operator overloading for non-operator related purposes (e.g. don’t use + operator for subtraction); however, in this case I think it’s fine to bend the rules just a bit to escape all those parentheses and provide clean expectation DSL. You can use should syntax with the latest Cedar master branch.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Glenn Jahnke

Polyglot Factorial

Glenn Jahnke
Tuesday, November 15, 2011

Someone on Hacker News mentioned the number of orderings of a deck of cards. I took up the challenge in some of my favorite and not so favorite languages, I’ll let you guess :).

Ruby

ruby-1.9.2-p180> (1..52).inject{|a,b|a*b}
=>
80658175170943878571660636856403766975289505440883277824000000000000

Scala

scala> BigInt(1).to(BigInt(52)).toList.foldLeft(BigInt(1))((a,b) => a*b)
res23: scala.math.BigInt =>
80658175170943878571660636856403766975289505440883277824000000000000

Haskell

Prelude> foldl1 (x -> y -> x*y) [1..52]
80658175170943878571660636856403766975289505440883277824000000000000

CoffeeScript

coffee> [1..52].reduce (a,b) -> a*b

8.065817517094388e+67

Java

Non-existent REPL>
import java.math.*;
public class Factorial {
public static void main(String[] args) {
BigInteger result = BigInteger.ONE;
BigInteger fiftyTwo = new BigInteger(”52″);
for(BigInteger i = BigInteger.ONE; i.compareTo(fiftyTwo) <= 0; i = i.add(BigInteger.ONE)) {
result = result.multiply(i);
}
System.out.println(result);
}
}

$ java Factorial
80658175170943878571660636856403766975289505440883277824000000000000

** I could have used the product function in most of those examples, but I wanted to play with foldL ;)

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (86)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • mobile (22)
  • bloggerdome (20)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • tdd (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • rubygems (9)
Subscribe to Community Feed
  1. ←
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. →
  • 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 >