Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from lmeijvogel/specs_cleanup

Make specs independent by cleaning up files before each spec
  • Loading branch information...
commit dd6d52eb16f759acb57f4da064008013c6a13547 2 parents 70d2c39 + e1ee21e
@devrandom devrandom authored
Showing with 50 additions and 43 deletions.
  1. +50 −43 spec/integration/net_dav_spec.rb
View
93 spec/integration/net_dav_spec.rb
@@ -2,113 +2,121 @@
require File.expand_path(File.dirname(__FILE__) + '/webdav_server')
describe "Net::Dav" do
-
before(:all) do
+ @server_uri = "http://localhost:10080/"
+ @new_file_uri = "/new_file.html"
+ @copied_file_uri = "/copied_file.html"
+ @moved_file_uri = "/moved_file.html"
+
# Start webdav server in subprocess
@pid = fork do
webdav_server(:port => 10080, :authentication => false)
end
# Wait for webdavserver to start
- wait_for_server("http://localhost:10080/")
+ wait_for_server(@server_uri)
+ end
+
+ before(:each) do
+ @dav = Net::DAV.new(@server_uri)
+
+ # Delete any files that are created by the specs
+ [@new_file_uri, @copied_file_uri, @moved_file_uri].each do |uri|
+ if (find_props_or_error(@dav, uri) =~ /200/)
+ @dav.delete(uri)
+ end
+ end
end
it "should create a Net::Dav object" do
- Net::DAV.new("http://localhost.localdomain/").should_not be_nil
+ @dav.should_not be_nil
end
it "should read properties from webdav server" do
- dav = Net::DAV.new("http://localhost:10080/")
- @props = dav.propfind("/").to_s
+ @props = @dav.propfind("/").to_s
@props.should match(/200 OK/)
end
it "should raise if finding non-existent path" do
- dav = Net::DAV.new("http://localhost:10080/")
lambda do
- dav.find("/") do |item|
+ @dav.find("/") do |item|
end
end.should_not raise_error
end
it "should raise if finding non-existent path" do
- dav = Net::DAV.new("http://localhost:10080/")
lambda do
- dav.find("/asdf") do |item|
+ @dav.find("/asdf") do |item|
end
end.should raise_error Net::HTTPServerException
end
it "should write files to webdav server" do
- dav = Net::DAV.new("http://localhost:10080/")
- @props = find_props_or_error(dav, "/new_file.html")
+ @props = find_props_or_error(@dav, @new_file_uri)
@props.should match(/404.*Not found/i)
- dav.put_string("/new_file.html","File contents")
+ @dav.put_string(@new_file_uri,"File contents")
- @props = find_props_or_error(dav, "/new_file.html")
+ @props = find_props_or_error(@dav, @new_file_uri )
@props.should match(/200 OK/i)
end
- it "should delete files from webdav server" do
- dav = Net::DAV.new("http://localhost:10080/")
+ it "should delete files from webdav server" do
+ @dav.put_string(@new_file_uri,"File contents")
- @props = find_props_or_error(dav, "/new_file.html")
- @props.should match(/200 OK/i)
+ @props = find_props_or_error(@dav, @new_file_uri)
+ @props.should match(/200 OK/i)
- dav.delete("/new_file.html")
- @props = find_props_or_error(dav, "/new_file.html")
- @props.should match(/404.*Not found/i)
- end
+ @dav.delete(@new_file_uri)
+ @props = find_props_or_error(@dav, @new_file_uri)
+ @props.should match(/404.*Not found/i)
+ end
it "should copy files on webdav server" do
- dav = Net::DAV.new("http://localhost:10080/")
-
- @props = find_props_or_error(dav, "/file.html")
+ @props = find_props_or_error(@dav, "/file.html")
@props.should match(/200 OK/i)
- dav.copy("/file.html","/copied_file.html")
- @props = find_props_or_error(dav, "/copied_file.html")
+ @dav.copy("/file.html", @copied_file_uri)
+
+ @props = find_props_or_error(@dav, @copied_file_uri)
@props.should match(/200 OK/i)
- dav.delete("/copied_file.html")
+ @dav.delete(@copied_file_uri)
- @props = find_props_or_error(dav, "/copied_file.html")
+ @props = find_props_or_error(@dav, @copied_file_uri)
@props.should match(/404.*Not found/i)
end
it "should move files on webdav server" do
- dav = Net::DAV.new("http://localhost:10080/")
-
- @props = find_props_or_error(dav, "/file.html")
+ @props = find_props_or_error(@dav, "/file.html")
@props.should match(/200 OK/i)
- dav.move("/file.html","/moved_file.html")
- @props = find_props_or_error(dav, "/moved_file.html")
+ @dav.move("/file.html", @moved_file_uri)
+ @props = find_props_or_error(@dav, @moved_file_uri)
@props.should match(/200 OK/i)
- @props = find_props_or_error(dav, "/file.html")
+ @props = find_props_or_error(@dav, "/file.html")
@props.should match(/404.*Not found/i)
- dav.move("/moved_file.html","/file.html")
- @props = find_props_or_error(dav, "/file.html")
+ @dav.move( @moved_file_uri,"/file.html")
+ @props = find_props_or_error(@dav, "/file.html")
@props.should match(/200 OK/i)
end
it "should retrieve acl" do
- dav = Net::DAV.new("http://localhost:10080/")
- @props = dav.propfind("/", :acl).to_s
+ @props = @dav.propfind("/", :acl).to_s
@props.should match(/200 OK/i)
end
it "should detect if resource or collection exists on server" do
- dav = Net::DAV.new("http://localhost:10080/")
- dav.exists?('/file.html').should == true
- dav.exists?('/totally_unknown_file.html').should == false
+ @dav.put_string( @new_file_uri, "File" )
+
+ @dav.exists?(@new_file_uri).should == true
+ @dav.exists?('/totally_unknown_file.html').should == false
end
# proppatch seems to work, but our simple webdav server don't update properties
# it "should alter properties on resources on webdav server" do
-# dav = Net::DAV.new("http://localhost:10080/")
+# dav = Net::DAV.new(@server_uri)
# @props = find_props_or_error(dav, "/file.html")
# puts @props
# dav.proppatch("/file.html", "<d:resourcetype>static-file</d:resourcetype>")
@@ -120,5 +128,4 @@
# Shut down webdav server
Process.kill('SIGKILL', @pid) rescue nil
end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.