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: August 2010

Mike Gehard

Rocket powered Cucumber features in Rails3

Mike Gehard
Saturday, August 14, 2010

Are your Cucumber features that use the @javascript tag slowing you down?

Try adding the following to your Gemfile:

gem 'thin', :group => :test

and see what happens.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Jonathan Barnes

Standup 08/13/2010: (css3 nth-child pseudo selector bug in safari)

Jonathan Barnes
Friday, August 13, 2010

Ask for Help

*”when using the css3 pseudo selector nth-child followed by a nested selector e.g.

td:nth-child(4) > p

some times (but consitently) they do not match to the correct element. Has anyone using nth-child experienced this before and know why it sometimes works and other times not?”*

For now the solution is to use jQuery to get to the nth child and apply the styles that way.

Interesting Things

  • jQuery 1.4.2 ajax json responses with a response code of 200 and responseText:” ” (note the non empty string) causes jquery to trigger the failure callback instead of the success. Previous versions would handle this as a special case and still trigger the success callback. Most people agree this is proper as an empty string is not valid json, but be aware!

  • Perseids is a metor shower happening right now (July 23 – August 24) so look up!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Jonathan Barnes

Standup 08/12/2010: (Text encoding issues)

Jonathan Barnes
Thursday, August 12, 2010

Ask for Help

“We have a file claiming to be ISO-8859-l encoded, but having characters that don’t seem to be encoded that way. Every editor we try to open it in shows the bad characters. We have tried to use the iconv utility to change it to a UTF8 file type but it keeps crapping out whenever it hits an unknown character for that encoding. Any ideas how to fix these files??”

There were multiple suggestions:

  • Try running iconv to encode it to its current encoding and see if that works i.e. latin1 -> latin1
  • Manually fix the characters that iconv complains on. (this was rejected as there were thousands of fils that needed fixing).
  • Try pasting the file into a WYSYWIG editor that may fix the bad characters and then copying them out again (using mechanize or similar to automate)
  • Try opening it in MS-Word or similar and saving it back out.

Interesting Things

  • the ‘:contains’ pseudo selector in jQuery & webrat behave differently with regards to commas. in jQuery it treats it as a string, in webrat (probably because it is converted to xpath) it is treated as separator.
  • spec.opts << --format profile will show you the 10 slowest specs after the suite is run.
  • Rails versions > 2.3.x use HTTP only cookeis so you cannot use selenium to clear them out. You can turn that off in your test environment to fix this. while a slower you may also just want your sleenium tests to open a fresh browser for every test in case there are other side effects in the browser like local data stores etc.
  • If you are using RubyMine and are experiencing a perpetual ‘Attach gems’ problem you may be able to fix it by clearing out older gem versions. gem clean
  • Riak is a distributed hash table data store solution. They are working on a project that is going to implement the SOLR api but be backed by Riak instead of lucene
  • If your using Rails 3/Passanger and you would like to have a production like environment but not call it ‘production’, say ‘demo’ You will need to change not only the RAILS_ENV but also the RACK_ENV variable to get it to work. Someone also mentioned that there may be a Passenger config that will also do this.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Jonathan Barnes

Standup 08/11/2010 (using VCR to mock out external dependencies and much more)

Jonathan Barnes
Wednesday, August 11, 2010

(Title: Standup 11/31/2000: Something Interesting from the post)

Ask for Help

“I have a paid for iPhone app in the app store and I want to deprecate the paid for feature and release the next version as a free app with ads. How can I continue give the users who have paid an add free version while keeping all new/future downloads free-with-ads?”

So far the only idea has been to release a second app that is free, but that has the problem of loosing all positive press/feedback for the existing app. And would seem to double the effort to provide upgrades for all users.

“We are getting ‘Connection reset by peer’ errors using Rescue to kick off some background jobs. It seems to be happening even for jobs that run only locally on the machine. They seem to happen randomly for various bg jobs. Has anyone else experienced this or have ideas on what is causing it?”

The connection reset by peer error is most often thrown by TCP/IP connections being closed by someone other than the client. Either the remote service close the connection or the network failed to keep the connection open. No one seems to have ideas on why/how it would be happening for local BG jobs.

“Devise + Selenium == ‘you are being redirected’. When trying to selenium test log in, rather than redirecting correctly post login as it really does, the selenium test fails with a page stating ‘you are being redirected’. Why is it not doing the actual redirect?”

There is a config somewhat deep in SeleniumRC config that tells selenium whether or not to follow redirects, it may be that it is set wrong. (the default should be to follow them and if you have not messed with it, not sure if this is your problem)

“We would like to be able to run our full and long-running test suite in the background while still having the ‘test’ environment free for doing BDD/focused testing. There are many potential solutions for this but what is the easiest/best to implement?”

solutions include:

  • Create a VM image that has your dev/test environment setup on it, push the changes to it and run you full suite in the through a terminal window. This has the drawback of a fair amount of time/effort setting up the vm correctly but that is a one-time-cost. You also need to do some interesting things with your hosts file and ssh keys to make access between your main system and the VM easier, and tends to require to commit the code somewhere in order to push it to the vm which, depending on your workflow, may be exactly what you don’t want to do.
  • Create a new env & db call ‘test_suite’ and run your full suite against that environment. This solution generally requires you to clone a bunch of the default rake tasks which have the ‘test’ env hard coded in them such as db:test:prepare and related. if you look at db.rake for how often the test env is hard-coded you will see that it is non-trivial. Also once you have duplicated all those tasks you are stuck maintaining them as you upgrade rails.
  • Someone mention a project called Vagrant as a variant on the VM solution. This may solve some of the main pain points with doing it that way.
  • Someone else mentioned a plugin called Parallel Tests that utilizes the multiple environments approach. Maybe it can be tweaked/referenced as a solution to run all tests in an alt test environment

“I have upgraded to Selenium 2 pre-alpha 5 and seem to be unable to use ‘click’ in chrome?”

Most suggestions involved “… then don’t use click” or “… try double-click”

“We are trying out the new bluetooth only ‘magic mouse’ from apple but in this office with lots of macs it is taking for ever to connect the mouse. why?”

It seems that a lot of the machines have bluetooth enabled and have discoverability turned on at all times. It would be bets to turn bluetooth off if your not using it and if you are to turn off discoverability except when connecting a new device.

“after using ‘tail -f’ my terminal window no longer shows keyboard input. why?”

It is possible that you have a complex and buggy PS1 defined and there is some data being printed in whatever you are tailing that is messing with that PS1. Try greatly simplifying your PS1 and see if that resolves the problem then do a binary search on your old PS1 to find the offending portion.
If you are unable to find the root cause you can try one of the following. Try resetting your terminal using the unix command ‘reset’ and see if it fixes your terminal window. Try using the tailing option in Less ‘less -F [file]‘

Interesting Things

  • VCR is a great way to fake out an external dependency to run your tests against. It is an especially good/easy way to fake out external api’s
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 8/10/2009: Catatonic Edition

Pivotal Labs
Tuesday, August 10, 2010

“Anyone have any experience with the pfeed gem? We’re interested in a no-frills activity feed”

Crickets dominate the standup landscape. It is suggested that our guests, Diaspora, may have some opinions on activity feeds.

-fin-

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dan Podsedly

Network Issues Today

Dan Podsedly
Monday, August 9, 2010

Our managed hosting provider experienced an extended network outage today, which affected a number of applications including Pivotal Tracker.

The outage was caused by a failure of a primary network load balancer. Network engineers have replaced the load balancer, and are in the process of investigating why traffic did not fail over to a secondary load balancer as expected. They will be performing a fail over test early this morning, from 1am PDT to 3am PDT, during which time some Tracker users may experience increased latency.

We appreciate everyone who notified us about this outage, and apologize for the inconvenience of not being able to access your projects this morning.

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

Design Patterns and it all

Pivotal Labs
Monday, August 9, 2010

During my internship here at Pivotal, I have learned quite a few things. One that happened to become apparent quickly was about design patterns and their role in (actual) object-oriented programming, the stuff that isn’t given a good treatment in school. The entire “gang of four” book was squished into an hour long hail mary lecture accompanied by an irrelevant TA-led 30 minute discussion. Until working here at Pivotal the words ‘factory’ and ‘delegate’ were the centaurs and unicorns of anything that stepped into the realm of code.

I often scratched my chin at why my professor was explaining whether inversion of control had to do with design patterns or foundational software engineering. Literally the week into my internship, a lot of the academic fluff was turned up on it’s head. People actually used these words and they actually have context!? I thought this must have been some Ruby voodoo…until I saw the mobile team discussing these terms also. It was then that it all came together: that 5% of class had translated into a whole state of mind on the battlefield of software development.

After a month into my internship, it was clear in my mind that I would have to switch gears from worrying about the Big-Oh notation of everything I saw to worrying about whether what was done had accomplished the job. Design patterns facilitated this “get it done now” mentality all the time: the delegation pattern was scattered around the Cocoa framework and Objective-C code – that was when the bubble burst from the obfuscated box and pointer to diagram to something (somewhat) tangible. I later saw the proxy pattern heavily used in Android testing frameworks to essentially have communication between the object without the object there in all of it’s stuffy goodness. The Rails world is sprinkled with them: factory and decorators are prevalent in RSpec and Cucumber. The design patterns help preserve the Rails DRY-ness of the tests, making the code leaner and more reusable. These are only a few examples of what has been seen, the list goes on and on while that lecture becomes folklore.

The disparity between software development and academia has grown over the length of my internship here at Pivotal, and it really shows that the 5% in school could be more than 95% in the industry. I hope to elaborate later on the impact that test driven development has had on me in the context of coming straight from academia.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Where, oh where has my gem server gone?

Alex Chaffee
Sunday, August 8, 2010

Uh-oh!

ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    bad response Moved Permanently 301 (http://gems.rubyforge.org/latest_specs.4.8)

Whew!

gem sources -a http://rubygems.org/
gem sources -r http://gems.rubyforge.org/

Looks like they weren’t kidding when they said to switch from rubyforge to rubygems.org (née gemcutter)!

[Edited to change "http://production.s3.rubygems.org/" to "http://rubygems.org/". Note that the trailing slash is significant!]

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Adam Milligan

iPhone on blocks: UITextFields

Adam Milligan
Saturday, August 7, 2010

If you’ve ever used a UITextField in an iPhone project (or, I suppose, an NSTextField in a Cocoa project) you know that you pass it a delegate object in order to respond to events. Handling the “Return” key press from the on-screen keyboard may look something like this (probably implemented in your view controller):

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (0 == [textField.text length]) {
        return NO;
    }
    [self doSomethingWithText:textField.text];
    [textField resignFirstResponder];
    return YES;
}

The delegate pattern is de rigueur for Cocoa classes, so you’ve likely never given this much special thought. Unless, that is, you decided at some point to have two text fields on screen at once. With two text fields you need to handle two sets of callbacks. You have a couple options for how to do this:

  1. Use the same delegate to handle both sets of callbacks, and use conditionals or switch statements to differentiate between the text fields.
  2. Create UITextField subclasses for each text field, each of which knows how to handle its own events. Each subclass will need a reference to the view controller, and you’ll need to expose methods in the view controller’s public interface for the subclasses to call, in order to effect some change in the system.
  3. Create a separate delegate class for each text field. As in the previous option, each delegate class will need a reference to the view controller and a way to send it messages to effect changes in the system.

None of these options feel particularly satisfactory: the second overuses inheritance, which the delegate pattern exists largely to avoid; both the second and third can result in class explosion; and the first feels so… procedural. Isn’t Object Oriented Programming supposed to save us from problems like this?

Procedural or no, Apple suggests the first option in all of their documentation and example code. An if statement isn’t really a big deal for two text fields; but what about three? Five? Ten? Your delegate method could look something like this:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == self.fooTextField) {
        if (0 == [textField.text length]) {
            return NO;
        }
        // Do something with the text
        }
    } else if (textField == self.barTextField) {
        // different logic...
    } else if (textField == self.batTextField) {
        // more different logic...
    } else if (textField == self.bazTextField) {
        // yet more different logic...
    } else if (textField == self.wibbleTextField) {
        // still yet more different logic...
    } else if ...
    [textField resignFirstResponder];
    return YES;
}

Or, alternately, you could resort to the dreaded switch statement. Either way, ugh.

The fundamental problem here is that only one object (let’s say a view controller) knows what to do when events occur, but only the subordinate objects (the text fields) know when the events occur. Each text field object encapsulates the behavior of its particular on-screen representation, but can’t access the internal state or implementation details of the view controller in order to effect changes to the system.

The recent addition of blocks to iOS can help us work around this problem. Since blocks are closures they capture and maintain their surrounding state at the point they’re instantiated. We can use this to define an implementation, and capture the internal state of our view controller, and pass all of this to an individual text field. Once done, each text field object will manage its own behavior without any intervention from the view controller whatsoever.

To make this work you’d need one (and only one) new class (theoretically, you could make a subclass of UITextField and set it to be its own delegate; unfortunately, setting a UITextField to be its own delegate seems to create an infinite loop deep in the bowels of Cocoa):

@interface BlockTextFieldDelegate : NSObject <UITextFieldDelegate>
@property (nonatomic, copy) BOOL (^textFieldShouldReturn)(UITextField *textField);
@end

@implementation BlockTextFieldDelegate
@synthesize textFieldShouldReturn = textFieldShouldReturn_;

- (void)dealloc {
    self.textFieldShouldReturn = nil;
    [super dealloc];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (self.textFieldShouldReturn) {
        return self.textFieldShouldReturn(textField);
    }
    return YES;
}

@end

Using the BlockTextFieldDelegate class might look like this (in your view controller):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.textFieldDelegate.textFieldShouldReturn = ^ BOOL (UITextField *textField) {
        if (0 == [textField.text length]) {
            return NO;
        }
        [self doSomethingWithText:textField.text];
        [textField resignFirstResponder];
        return YES;
    };
}

The astute reader, armed with a passing familiarity with Apple’s Human Interface Guidelines, will point out that having several text fields on one screen may create a poor user experience. Certainly true for the iPhone, perhaps less true for the iPad’s larger screen. In any case, this technique works for any situation that requires multiple objects, not just UITextFields, reporting to a single delegate. Consider the case of multiple concurrent network requests, created by NSURLConnection objects, managed by a single view controller.

The astute reader will also point out that you may leave off the return type when defining blocks, assuming the compiler can infer it. I left the return type in to keep the example as explicit as possible, but the above block assignment could look like this (note the missing BOOL return declaration):

self.textFieldDelegate.textFieldShouldReturn = ^ (UITextField *textField) {

The block syntax isn’t beautiful, but you can use this technique to eliminate conditional chains, keep the number of classes and subclasses you create low, and avoid exposing the internal state of your objects; and that is beautiful.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

IndexTank: Full-text Search as a Service

Friday, August 6, 2010 | Run time: 34:44

Diego Basch and Santiago Perez Gonzales of Flaptor demonstrate their new product IndexTank, a hosted, scalable, real-time search solution. They demonstrate the API and show how to migrate a ThinkingSphinx-based solution to IndexTank.

  • 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. 6
  8. →
  • 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 >