Peter Marklund

Peter Marklund's Home

Wed Aug 01 2007 07:49:30 GMT+0000 (Coordinated Universal Time)

Rails Testing: Quoting angle brackets in assert_select

This is just a little detail but today I rediscovered the way to quote angle brackets in argument values in HTML::Selector expressions in your assert_select commands (and corresponding response.should have_tag commands in RSpec). I tried using back slashes before I realized that I needed to enclose the argument value in single quotes. Notice the nested angle brackets ([ and ] signs) below:

  it "Should have the allow_public_messages radio buttons on the edit contact info page" do
    get :edit_my_options
    response.should be_success
    response.should have_tag("input[name='profile[allow_public_messages]']")
  end