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

Commit

Permalink
Don't strip newlines in Node#text
Browse files Browse the repository at this point in the history
Fixes #128.
  • Loading branch information
jonleighton committed Sep 24, 2012
1 parent e154037 commit 8abc10a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -216,7 +216,9 @@ makes debugging easier). Running `rake autocompile` will watch the
[Issue #127] [Issue #127]


* Use `el.innerText` for `Node#text`. This ensures that e.g. `<br>` is * 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 ### ### 0.7.0 ###


Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/poltergeist/node.rb
Expand Up @@ -31,7 +31,7 @@ def find(selector)
end end


def text def text
command(:text).strip.gsub(/\s+/, ' ') command :text
end end


def [](name) def [](name)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/session_spec.rb
Expand Up @@ -313,7 +313,7 @@


it 'returns BR as a space in #text' do it 'returns BR as a space in #text' do
@session.visit '/poltergeist/simple' @session.visit '/poltergeist/simple'
@session.find(:css, '#break').text.should == "Foo Bar" @session.find(:css, '#break').text.should == "Foo\nBar"
end end
end end
end end

6 comments on commit 8abc10a

@carhartl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@carhartl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being annoying.

@jonleighton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not annoying, the issue is annoying :)

@carhartl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jonleighton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be standardised by Capybara. In fact, it is: teamcapybara/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.