add link#href, #text test
This commit is contained in:
parent
534ab0a47a
commit
d34a20c73c
17
spec/page/link_spec.cr
Normal file
17
spec/page/link_spec.cr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
require "../spec_helper"
|
||||||
|
|
||||||
|
describe "Mechanize Page Link test" do
|
||||||
|
it "returns href" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
page = agent.get("http://example.com/link")
|
||||||
|
link = page.links.first
|
||||||
|
link.href.should eq "http://example.com/"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns text" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
page = agent.get("http://example.com/link")
|
||||||
|
link = page.links.first
|
||||||
|
link.text.should eq "link text"
|
||||||
|
end
|
||||||
|
end
|
@ -29,7 +29,7 @@ WebMock.stub(:get, "example.com/link").to_return(body: <<-BODY
|
|||||||
<title>page_title</title>
|
<title>page_title</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<a href="http://example.com/">ページのリンク</a>
|
<a href="http://example.com/">link text</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
BODY
|
BODY
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
class MechanizeCr::PageContent::Link
|
class MechanizeCr::PageContent::Link
|
||||||
property node : Lexbor::Node
|
getter node : Lexbor::Node
|
||||||
property page : Page
|
getter page : Page
|
||||||
property mech : Mechanize
|
getter mech : Mechanize
|
||||||
|
getter href : String
|
||||||
|
getter text : String
|
||||||
|
|
||||||
def initialize(node, mech, page)
|
def initialize(node, mech, page)
|
||||||
@node = node
|
@node = node
|
||||||
@page = page
|
@page = page
|
||||||
@mech = mech
|
@mech = mech
|
||||||
# @attributes = node
|
@href = node.fetch("href", "")
|
||||||
# @href = node['href']
|
@text = node.inner_text
|
||||||
# @text = nil
|
|
||||||
# @uri = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user