Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Fix bug with has_css #333

Merged
merged 1 commit into from
Jun 18, 2013
Merged

Conversation

alexspeller
Copy link
Contributor

When using has_css with a count, I was finding that an error is
raised casued by trying to gsub on nil when the element is not
present. This fix avoids that by casting to a string first,
ensuring the gsub method is available.

I think this was caused by this line mapping the result to text:

From: /Users/alex/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/capybara-2.1.0/lib/capybara/result.rb @ line 41 Capybara::Result#failure_message:

    38: def failure_message
    39:   message = Capybara::Helpers.failure_message(@query.description, @query.options)
    40:   if count > 0
 => 41:     message << ", found #{count} #{Capybara::Helpers.declension("match", "matches", count)}: " << @result.map(&:text).map(&:inspect).join(", ")
    42:   else
    43:     message << " but there were no matches"
    44:   end
    45:   unless @rest.empty?
    46:     elements = @rest.map(&:text).map(&:inspect).join(", ")
    47:     message << ". Also found " << elements << ", which matched the selector but not all filters."
    48:   end
    49:   message
    50: end

@jonleighton
Copy link
Contributor

Please could you add a test?

@alexspeller
Copy link
Contributor Author

The test really isn't great but I found it impossible to reproduce the error more meaningfully within the test harness.

@jonleighton
Copy link
Contributor

Could you explain more about your problem? Part of the reason I wanted a test was so that I'd understand the issue, unfortunately this test doesn't help with that.

@alexspeller
Copy link
Contributor Author

@jonleighton this is the actual issue that was being caused for me. I'm not sure if it only affects svg elements, however that's where I was experiencing the problem

@alexspeller
Copy link
Contributor Author

I did just try with another "empty" element (<img> tag), and that wasn't affected by this bug. I suspect svg elements are "empty" in a way that normal elements aren't, which causes this bug to manifest.

@alexspeller
Copy link
Contributor Author

@jonleighton did you see I updated this PR?

@jonleighton
Copy link
Contributor

@alexspeller sorry, I didn't see. I'm happy to merge this. Please could you rebase and squash the commits into one. Thanks.

@alexspeller
Copy link
Contributor Author

@jonleighton no problem, done.

jonleighton added a commit that referenced this pull request Jun 18, 2013
@jonleighton jonleighton merged commit 037897f into teampoltergeist:master Jun 18, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants