[Ruby] matching spaces as \s+ in assert_select

Ken Harris kengruven at gmail.com
Wed Dec 5 20:16:09 PST 2007


Depends on what you think is not-nice about that.

My way: just hide it in an abstraction.

  # in test_helper:
  def assert_select_ignore_whitespace(tag, text)
    assert_select tag, /#{text.gsub!(/\s+/,'\s+')}/
  end

  # in the test:
  assert_select_ignore_whitespace 'h3', "Wants to do 1 thing"

My programs tend to end up with a lot of assert_* methods.  I'm told
that's a good thing.

I suppose this loses other features of assert_select.  If I needed to
use them, I'd probably push the regexp-builder into a String method so
I could say:
  assert_select 'h3', "Wants to do 1 thing".stretchy_whitespace


Now everybody who's been using Ruby for more than a couple months can
jump in and tell me (why) my style sucks.  :-)


- Ken


More information about the Ruby mailing list