RSpec, Haml and decent_exposure are incompatible? That'd be odd.
Posted: 12 months ago (2011-02-24 07:20:26 UTC ) / Updated: 12 months ago (2011-02-25 05:31:45 UTC )
[EDIT: Scroll to the bottom for the solution to this problem.]
I have an odd situation where RSpec is set up with view helpers (normal), I'm using Haml (normal-ish), and I'm using decent_exposure a fair bit (semi-normal, but it's a really simple library).
What's odd is that the expose() calls, which I call "entry" and "entries", are simply not being seen in the Haml-generated views, but only when the views are used via the RSpec view specs. Very odd.
Other helper methods can be seen just fine -- though if they call the decent_exposure methods, they can't see them either.
I thought - aha! I have it. But no. Since decent_exposure registers these methods using ActionController::Base#helper_method, I thought I could just require the controller file from my view spec (or just reference the controller) and boom, all my problems would be solved.
But in fact, that hasn't helped me. It appears that view specs, rspec and decent_exposure may be incompatible when taken as a single lump -- or Haml may be complicating things as well.
What confuses me is that I haven't seen anybody else complain about this, and Haml plus RSpec plus decent_exposure is precisely what Obie Fernandez recommends highly for any serious Rails shop in his new edition of The Rails Way... So I assume at *least* HashRocket has to be doing this. How do they do it?
[EDIT: FOUND A SOLUTION!
This is a feature of RSpec view specs, sort of. They're not supposed to depend on the controller in any way. So if you expose(:entry), that means you need to mock that, something like:
view.should_receive(:entry).at_least(:once).and_return(my_entry)
So, it was my fault, sort of. Presumably we're supposed to mock the expose methods in the view specs, since those *do* depend on the controller. Fair enough. I'm just happy it works now!]
