Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't strip newlines in `Node#text`

Fixes #128.
  • Loading branch information...
commit 8abc10a9ccb6e2fb8f33e4175ed5167e4dd551e2 1 parent e154037
@jonleighton jonleighton authored
View
4 README.md
@@ -216,7 +216,9 @@ makes debugging easier). Running `rake autocompile` will watch the
[Issue #127]
* Use `el.innerText` for `Node#text`. This ensures that e.g. `<br>` is
- returned as a space. It also simplifies the method. [Issue #139]
+ returned as a newline. It also simplifies the method. [Issue #139]
+
+* Don't strip newlines in `Node#text`. [Issue #128]
### 0.7.0 ###
View
2  lib/capybara/poltergeist/node.rb
@@ -31,7 +31,7 @@ def find(selector)
end
def text
- command(:text).strip.gsub(/\s+/, ' ')
+ command :text
end
def [](name)
View
2  spec/integration/session_spec.rb
@@ -313,7 +313,7 @@
it 'returns BR as a space in #text' do
@session.visit '/poltergeist/simple'
- @session.find(:css, '#break').text.should == "Foo Bar"
+ @session.find(:css, '#break').text.should == "Foo\nBar"
end
end
end

6 comments on commit 8abc10a

@carhartl

Wondering whether this did make sense. capybara-webkit is doing something similar: https://github.com/thoughtbot/capybara-webkit/blob/master/lib/capybara/webkit/node.rb#L7

Given HTML such as

<p>
  <span>One</span>
  <span>Two</span>
</p>

I need to write an expectation like this:

page.should have_selector('p', text: 'One\nTwo')

though

page.should have_selector('p', text: 'One Two')

seems more intuitive?

@jonleighton
Owner

Hmm, maybe. This is an annoying issue. I'll have a think about it again.

@carhartl

Sorry for being annoying.

@jonleighton
Owner

You are not annoying, the issue is annoying :)

@carhartl

Should that be defined at capybara level? I'd prefer js driver interoperability...

@jonleighton
Owner

Yes, it should be standardised by Capybara. In fact, it is: jnicklas/capybara@060fc3a

That commit isn't in the 1.1 branch though, hence why this commit didn't cause a failure. Anyway, I will revert this.

Please sign in to comment.
Something went wrong with that request. Please try again.