Interesting
rspec
stub != stub!.stub!is an alias method forstub. There is however also a methodstubthat is an alias fordouble. 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, usingself.stub(:name => 'result')will create a double, whileself.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.openandf.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.
- Workarounds:
== on DelegateClass: newing up an instance
delegate_xof DelegateClass from objectx,x == delegate_x, while of coursex.class != delegate_x.class.
Keystroke of the day
- Rubymine KOTD: The search+replace mode you reach via
Cmd+rallows you to see recent searches by hitting the down arrow. If that doesn’t work for you in Lion, hitCtrl+h.
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
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