On Tue, Mar 25, 2008 at 2:06 AM, Seth L. [email protected] wrote:
Hm, of course, now that I have sent the previous email, I found the
bug in my code and have fixed it. So I know I am using RSpec
correctly with controllers and a respond_to block. Using the :format
=> ‘json’ attribute in my get call was all I needed.
However, not matter what the format I choose, the template rendered is
always “databases/show” (this is essentially correct behavior).
However, it’s hard to determine which show was rendered:
show.json.erb or show.html.erb
There is a guideline in TDD that you should test your code and not
other people’s code. The behaviour you’re interested in testing is
that of ActionController::Base, not of your code.
I can check the content-type header, but that’s not exactly what I’d
like to test.
Is there a better way to write a spec to ensure that the correct
template is rendered when I use certain formats?
The transformation from loosely-bound name (‘databases/show’) to
explicit template name with extensions happens deep in
ActionController::Base. Between that fact and the aforementioned
guideline, there is no direct support for what you are looking for in
rspec_on_rails.
You can do this to get closer to what you are looking for:
controller.expect_render(hash_including(:xml => anything))
or
controller.expect_render(hash_including(:json => anything))
But I, personally, would not. Since this is not supported directly by
rspec_on_rails, should the Rails implementation of render change you’d
be on your own to keep up with those changes.
HTH,
David