yihong0618 和朋友们的频道 头像

消息来源频道

yihong0618 和朋友们的频道

@hyi0618

频道8,612 位成员公开可见0 人在线

yihong0618 和朋友们的频道

成员规模8,612 位成员
在线情况0 人在线
消息总数10,129 条消息
浏览量总数3,285,753 次浏览

在这个频道里搜索消息……

t.me/hyi0618

TIL:
Link: https://github.com/thoughtbot/til/blob/main/testing/capybara-all-does-not-return-array.md
📌 Capybara all does not return an array
Although it looks like it returns an Array, Capybara's all finder actually
returns a Capybara::Result. This object includes Enumerable and responds to
many of the most used methods on Array such as [].
Given the following HTML:
<body>
<p>Some content</p>
<p>Other content</p>
<p>Final content</p>
</body>
The following really looks like we are dealing with an array:
paragraphs = all("p")
# => [<Capybara::Element>,<Capybara::Element>,<Capybara::Element>]
paragraphs[1]
# => <Capybara::Element>
paragraphs.map(&:text)
# => ["Some content", "Other content", "Final Content"]
However, if I try to use some of the Array monkey patches provided by
ActiveSupport:
paragraphs.second
# => NoMethodError: undefined method `second' for Capybara::Result
paragraphs.class
# => Capybara::Result