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

Standup 11/11/2011: Some funkinesses

Stephan Hagemann
Friday, November 11, 2011

Interesting

  • rspec stub != stub!. stub! is an alias method for stub. There is however also a method stub that is an alias for double. If you try to stub a method on the test class (to stub it on the context), you should probably use the magic subject/helper/controller methods. If you don’t, using self.stub(:name => 'result') will create a double, while self.stub!(:name => 'result') will stub the method as you would expect.

  • Asynchronous file creation and downloading: if an asynchronous process writes a file using File.open and f.write, an other process checking the presence of the file to determine whether it is already available for download, will deliver the empty file, if the file has been opened, but not yet written.

    • Workarounds:
      • if you have one write to the file only: check filesize.
      • update an ActiveRecord attribute after the file writing is completed and check against that.
  • == on DelegateClass: newing up an instance delegate_x of DelegateClass from object x, x == delegate_x, while of course x.class != delegate_x.class.

Keystroke of the day

  • Rubymine KOTD: The search+replace mode you reach via Cmd+r allows you to see recent searches by hitting the down arrow. If that doesn’t work for you in Lion, hit Ctrl+h.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

2 Comments

  1. Ben Pickles says:

    RE asynchronous file creation: alternatively create the file in a temporary directory and `mv` it into its intended location as `mv` is an atomic operation.

    November 11, 2011 at 4:33 pm

  2. Jim Kingdon says:

    Agree with mv (within the same filesystem, and I’m not sure about NFS) or a database flag as a way of handling the atomic file update. Waiting for the file size to change from zero to nonzero (if that is what was being suggested) doesn’t work, I don’t think, although it might be a bit tricky to reproduce the race for sure (and it might depend on things like which OS).

    November 14, 2011 at 10:18 am

Add New Comment Cancel reply

Your email address will not be published.

Stephan Hagemann

Stephan Hagemann
Boulder

Recent Posts

  • Showing and hiding conditional HTML without Javascript
  • My must-see list from MWRC 2013
  • GoSpotCheck Is Looking For A Web Application Developer
Subscribe to Stephan's Feed

Author Topics

css (1)
html (1)
javascript (1)
conferences (1)
boulder (1)
jobs (1)
engines (2)
rails (2)
refactoring (1)
rspec (4)
testing (4)
ruby (3)
cancan (1)
rubymine (2)
rake (1)
basics (1)
  • 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 >