[Ruby] matching spaces as \s+ in assert_select

James Moore banshee at banshee.com
Thu Dec 6 14:38:18 PST 2007


On 12/6/07, Mikhail Seregine <seregine at yahoo.com> wrote:
> OK, enlighten me, why the '\s+'? Why not:
>
> assert_select 'h3', Regexp.new("Wants to do 1 thing".gsub!(/\s+/, ' '))

This doesn't quite do the same thing - I think what you're suggesting
would be to preprocess the html rather than the regular expression.
You could do this in Test::Unit::TestCase:

  def assert_select_one_whitespace &block
    html = @response.body.gsub(/\s+/, ' ')
    doc = HTML::Document.new(html, false, true)
    assert_select doc.root, ':root', &block
  end

And call it like:

    assert_select_one_whitespace do
      assert_select 'span' 'something with multiple whitespaces should
still pass'
    end

-- 
James Moore | james at restphone.com
Interested in hooking up phone calls to your Ruby on Rails site?
Send me mail about the RESTPhone beta.
blog.restphone.com


More information about the Ruby mailing list