Stephan Hagemann's blog
TL;DR
We moved a Rails app into an unbuilt engine of a new blank slate container app to allow new parts of our app to live next to it as engines as well. It has been working great for us!
I have a sample app rails_container_and_engines of the result's structure on github.
Skip to the pitfalls and discoveries section to read about some of the speed bumps we during our transition. Interested in the why and how? Read on!
Shared example groups are a feature of rspec that allow specifying common behavior in a reusable group of specs.
I believe that there is a very specific way in which one can benefit from shared examples groups (and should keep them) and many more in which they come in handy at some point and should be refactored away from as development continues.
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.
rspec should render_template still behaving weirdly
Specing a partial being rendered with render_template blows up. What to do?
render_template has been brittle for a long time. It obviously still is:
response.should render_template("template") #works fine
response.should render_template(partial: "template") #works fine
response.should render_template(partial: "template", locals: {local_array: []}) #blows up within rspec
You know how to fix it? Solve it here
RubyMine 4 is out
RubyMine "compare two files" isn't broken
It is just really, really weird: if you have to scroll when comparing two files check the file that is above in the project drawer first. If you scroll up to do select the second file to compare, the compare window won't open.
Stubbing can? can be hard
In a system with a lot of cancan abilities - what is the best way to stub a particular ability for controller specs? In the hierarchy of controllers, a lot of abilities may be checked, all of which would need to stubbed in order to get to the code under test.
Instead of stubbing the abilities, create a new, anonymous, ability class specific for your spec that gets all the necessary abilities and then stub current_ability to return an instance of that class. Internally cancan calls current_ability when you call can?: cancan controller additions
IntelliJ has a feature called modules: "a functional unit which you can compile, run, test and debug independently."

A module in IntelliJ is a top-level view on a part of a codebase. IntelliJ is for Java, which is why I do not typically use it. I use Rubymine - no similar functionality exists here... but a way around that!
There are several reasons why you should test your Rake tasks:
- Rake tasks are code and as such deserve testing.
- When untested Rake tasks have a tendency to become overly long and convoluted. Tests will help keep them in bay.
- As Rake tasks typically depend on your models, you (should) loose confidence in them if you don't have tests and are attempting refactorings.
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.
James' post from a couple of weeks ago inspired me to write up my own experiences of my first couple of weeks at Pivotal. However, instead of telling you how it felt, I will tell you about stuff I learned.
