download file within transact
parent
d344fadc44
commit
cfa824c909
|
@ -57,13 +57,6 @@ describe "Mechanize Agent test" do
|
|||
agent2.history.pop.uri.to_s.should eq "http://example.com/form"
|
||||
end
|
||||
|
||||
it "can download page" do
|
||||
agent = Mechanize.new
|
||||
agent.download("http://example.com", "mechanizecr_example.html")
|
||||
File.exists?("mechanizecr_example.html").should eq true
|
||||
File.delete("mechanizecr_example.html")
|
||||
end
|
||||
|
||||
it "doesn't add page to history within transact block" do
|
||||
agent = Mechanize.new
|
||||
agent.get("http://example.com/")
|
||||
|
@ -73,4 +66,13 @@ describe "Mechanize Agent test" do
|
|||
end
|
||||
agent.history.size.should eq 1
|
||||
end
|
||||
|
||||
it "can download page" do
|
||||
agent = Mechanize.new
|
||||
agent.history.size.should eq 0
|
||||
agent.download("http://example.com", "mechanizecr_example.html")
|
||||
agent.history.size.should eq 0
|
||||
File.exists?("mechanizecr_example.html").should eq true
|
||||
File.delete("mechanizecr_example.html")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -130,13 +130,13 @@ class Mechanize
|
|||
filename,
|
||||
headers = HTTP::Headers.new,
|
||||
params : Hash(String, String | Array(String)) = Hash(String, String).new)
|
||||
page = get(uri, headers, params)
|
||||
|
||||
case page
|
||||
when MechanizeCr::File
|
||||
File.write(filename, page.body)
|
||||
transact do
|
||||
page = get(uri, headers, params)
|
||||
case page
|
||||
when MechanizeCr::File
|
||||
File.write(filename, page.body)
|
||||
end
|
||||
end
|
||||
page
|
||||
end
|
||||
|
||||
# Runs given block, then resets the page history as it was before.
|
||||
|
|
Loading…
Reference in New Issue