Add layout checking to test_spec_on_rails

test_spec_on_rails is a plugin that adds Rails-specific assertions to test_spec, allowing you to do nifty things like this:

it "should render with foo template" do
  get :some_action "foo"
  # equivalent to assert_equal "foo", @response.template

it "should display foo on page" do
  get :some_action "p", "foo"
  # equivalent to assert_select "p", "foo"  

One thing test_spec_on_rails is missing, though, is the ability to check the layout that a template renders with. For example, it would be nice to do this:

it "should render with foo layout" do
  get :some_action "foo"
  # equivalent to assert_equal "foo", @response.layout

I’ve submitted a patch to Rick Olson that adds this capability. I’m not sure if or when it will get incorporated into the plugin though, so I’m posting the patch here for anyone who might need it.

To apply, right-click on the link and download the file into your vendor/plugins/test_spec_on_rails folder, then run this command from inside the same folder:

patch -p0 < add_layout.diff

Assuming your plugin isn't checked out as an external, you'll be able to commit the changes to your own repository. You can then start using the new hotness as described above. Enjoy!

Update: Rick made me a committer so I was able to add this myself.

One thought on “Add layout checking to test_spec_on_rails

  1. Pingback: puts”nonsense”) » Blog Archive » test/spec/rails => You Bettuh Recognize

Comments are closed.