ftpspec 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +158 -0
- data/Rakefile +2 -0
- data/bin/ftpspec-init +7 -0
- data/ftpspec.gemspec +24 -0
- data/lib/ftpspec/commands.rb +121 -0
- data/lib/ftpspec/matchers.rb +29 -0
- data/lib/ftpspec/setup.rb +62 -0
- data/lib/ftpspec/utils.rb +34 -0
- data/lib/ftpspec/version.rb +3 -0
- data/lib/ftpspec.rb +17 -0
- data/spec/command_spec.rb +128 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/utils_spec.rb +30 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bbd5a0a229210a2cf9339b806b53609060e51164
|
4
|
+
data.tar.gz: cdd7137b58d9307673fdb27fa7ea20e6ee905ca5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c949188b95fc02f23c69c9a91c76456be7ed3674d88469ed366df2a3a8121d6492111d1befe47016fd528250e5e68f90f39dfab6b7b8424d7019f27a1c124dab
|
7
|
+
data.tar.gz: ebacd76005ad7676dbd766044683eaaffcc16c47d75d7931c405aae2706126bb38814ad08db2606a5a9a7266a696ca512c2d6c301101e458999562b65fa4c7f1
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/suzuki86/ftpspec.svg?branch=master)](https://travis-ci.org/suzuki86/ftpspec)
|
2
|
+
|
3
|
+
# Work in progress
|
4
|
+
|
5
|
+
This project is under development.
|
6
|
+
|
7
|
+
# FTPSpec
|
8
|
+
|
9
|
+
RSpec custom matchers for ftp server that enables you to test file structure like Serverspec.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Clone to your machine.
|
14
|
+
|
15
|
+
```
|
16
|
+
git clone https://github.com/suzuki86/ftpspec.git
|
17
|
+
```
|
18
|
+
|
19
|
+
Move to directory you cloned.
|
20
|
+
|
21
|
+
```
|
22
|
+
cd ftpspec
|
23
|
+
```
|
24
|
+
|
25
|
+
Create a gem from ftpspec.gemspec with `gem build`.
|
26
|
+
|
27
|
+
```
|
28
|
+
gem build ftpspec.gemspec
|
29
|
+
```
|
30
|
+
|
31
|
+
Install generated ftpspec-x.x.x.gem with `gem install`
|
32
|
+
|
33
|
+
```
|
34
|
+
gem install ftpspec-x.x.x.gem
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Execute ftpspec-init command.
|
40
|
+
|
41
|
+
```
|
42
|
+
ftpspec-init
|
43
|
+
```
|
44
|
+
|
45
|
+
Then, spec directory will be generated.
|
46
|
+
|
47
|
+
```
|
48
|
+
$ tree
|
49
|
+
.
|
50
|
+
├── Rakefile
|
51
|
+
└── spec
|
52
|
+
├── ftp_spec.rb
|
53
|
+
└── spec_helper.rb
|
54
|
+
|
55
|
+
1 directory, 3 files
|
56
|
+
```
|
57
|
+
|
58
|
+
Write credentials of ftp server into spec/spec_helper.rb
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require "ftpspec"
|
62
|
+
require "rubygems"
|
63
|
+
require "rspec"
|
64
|
+
require "net/ftp"
|
65
|
+
|
66
|
+
RSpec.configure do |c|
|
67
|
+
c.add_setting :ftp, :default => nil
|
68
|
+
c.before do
|
69
|
+
hostname = "YOUR HOSTNAME"
|
70
|
+
user = "YOUR USER"
|
71
|
+
password = "YOUR PASSWORD"
|
72
|
+
c.ftp = Net::FTP.new
|
73
|
+
c.ftp.passive = true
|
74
|
+
c.ftp.connect(hostname)
|
75
|
+
c.ftp.login(user, password)
|
76
|
+
Ftpspec.set_ftp
|
77
|
+
end
|
78
|
+
c.after do
|
79
|
+
c.ftp.close
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
Write spec in each spec files.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require "spec_helper"
|
88
|
+
|
89
|
+
describe "/httpdocs/index.html" do
|
90
|
+
it { should be_mode 644 }
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
Execute rake command.
|
95
|
+
|
96
|
+
```
|
97
|
+
rake spec
|
98
|
+
```
|
99
|
+
|
100
|
+
## Matchers
|
101
|
+
|
102
|
+
### be_mode
|
103
|
+
|
104
|
+
Test whether file permission of subject is same as expected.
|
105
|
+
|
106
|
+
```
|
107
|
+
describe "/httpdocs/index.html" do
|
108
|
+
it { should be_mode 644 }
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
### be_file
|
113
|
+
|
114
|
+
Test whether subject is a file.
|
115
|
+
|
116
|
+
```
|
117
|
+
describe "/httpdocs/index.html" do
|
118
|
+
it { should be_file }
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### be_directory
|
123
|
+
|
124
|
+
Test whether subject is a directory.
|
125
|
+
|
126
|
+
```
|
127
|
+
describe "/httpdocs/images" do
|
128
|
+
it { should be_directory }
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
### be_owned_by
|
133
|
+
|
134
|
+
Test whether subject is owned by expected owner.
|
135
|
+
|
136
|
+
```
|
137
|
+
describe "/httpdocs/index.html" do
|
138
|
+
it { should be_owned_by "someone" }
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
### be_grouped_into
|
143
|
+
|
144
|
+
Test whether subject is grouped into expected group.
|
145
|
+
|
146
|
+
```
|
147
|
+
describe "/httpdocs/index.html" do
|
148
|
+
it { should be_grouped_into "admin" }
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
## Contributing
|
153
|
+
|
154
|
+
1. Fork it ( https://github.com/[my-github-username]/ftpspec/fork )
|
155
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
156
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
157
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
158
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/ftpspec-init
ADDED
data/ftpspec.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ftpspec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ftpspec"
|
8
|
+
spec.version = Ftpspec::VERSION
|
9
|
+
spec.authors = ["Toshinari Suzuki"]
|
10
|
+
spec.email = ["tsnr0001@gmail.com"]
|
11
|
+
spec.summary = %q{RSpec custom matchers for ftp server.}
|
12
|
+
spec.description = %q{RSpec custom matchers for ftp server.}
|
13
|
+
spec.homepage = "https://github.com/suzuki86/ftpspec"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = "ftpspec-init"
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Ftpspec
|
2
|
+
class Commands
|
3
|
+
|
4
|
+
def self.check_mode(target, expected)
|
5
|
+
ftp = Ftpspec.get_ftp
|
6
|
+
ftp.chdir File.dirname(target)
|
7
|
+
ftp.list.each do |file|
|
8
|
+
part = file.split(" ")
|
9
|
+
if part[8] != "." && part[8] != ".." then
|
10
|
+
current_path = ftp.pwd
|
11
|
+
filemode = part[0]
|
12
|
+
|
13
|
+
if current_path == "/" then
|
14
|
+
filename = "/" + part[8]
|
15
|
+
else
|
16
|
+
filename = current_path + "/" + part[8]
|
17
|
+
end
|
18
|
+
|
19
|
+
if filename == target then
|
20
|
+
return Ftpspec::Utils.convert_to_octal(filemode).to_i == expected
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.check_file(target)
|
28
|
+
ftp = Ftpspec.get_ftp
|
29
|
+
ftp.chdir File.dirname(target)
|
30
|
+
ftp.list.each do |file|
|
31
|
+
part = file.split(" ")
|
32
|
+
if part[8] != "." && part[8] != ".." then
|
33
|
+
current_path = ftp.pwd
|
34
|
+
filemode = part[0]
|
35
|
+
|
36
|
+
if current_path == "/" then
|
37
|
+
filename = "/" + part[8]
|
38
|
+
else
|
39
|
+
filename = current_path + "/" + part[8]
|
40
|
+
end
|
41
|
+
|
42
|
+
if filename == target then
|
43
|
+
return filemode[0] == "-"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.check_directory(target)
|
51
|
+
ftp = Ftpspec.get_ftp
|
52
|
+
ftp.chdir File.dirname(target)
|
53
|
+
ftp.list.each do |file|
|
54
|
+
part = file.split(" ")
|
55
|
+
if part[8] != "." && part[8] != ".." then
|
56
|
+
current_path = ftp.pwd
|
57
|
+
filemode = part[0]
|
58
|
+
|
59
|
+
if current_path == "/" then
|
60
|
+
filename = "/" + part[8]
|
61
|
+
else
|
62
|
+
filename = current_path + "/" + part[8]
|
63
|
+
end
|
64
|
+
|
65
|
+
if filename == target then
|
66
|
+
return filemode[0] == "d"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.check_owner(target, expected)
|
74
|
+
ftp = Ftpspec.get_ftp
|
75
|
+
ftp.chdir File.dirname(target)
|
76
|
+
ftp.list.each do |file|
|
77
|
+
part = file.split(" ")
|
78
|
+
if part[8] != "." && part[8] != ".." then
|
79
|
+
current_path = ftp.pwd
|
80
|
+
filemode = part[0]
|
81
|
+
owner = part[2]
|
82
|
+
|
83
|
+
if current_path == "/" then
|
84
|
+
filename = "/" + part[8]
|
85
|
+
else
|
86
|
+
filename = current_path + "/" + part[8]
|
87
|
+
end
|
88
|
+
|
89
|
+
if filename == target then
|
90
|
+
return owner == expected
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
return false
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.check_group(target, expected)
|
98
|
+
ftp = Ftpspec.get_ftp
|
99
|
+
ftp.chdir File.dirname(target)
|
100
|
+
ftp.list.each do |file|
|
101
|
+
part = file.split(" ")
|
102
|
+
if part[8] != "." && part[8] != ".." then
|
103
|
+
current_path = ftp.pwd
|
104
|
+
filemode = part[0]
|
105
|
+
group = part[3]
|
106
|
+
|
107
|
+
if current_path == "/" then
|
108
|
+
filename = "/" + part[8]
|
109
|
+
else
|
110
|
+
filename = current_path + "/" + part[8]
|
111
|
+
end
|
112
|
+
|
113
|
+
if filename == target then
|
114
|
+
return group == expected
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
return false
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec::Matchers.define :be_mode do |expected|
|
2
|
+
match do |target|
|
3
|
+
Ftpspec::Commands.check_mode(target, expected)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :be_file do
|
8
|
+
match do |target|
|
9
|
+
Ftpspec::Commands.check_file(target)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :be_directory do
|
14
|
+
match do |target|
|
15
|
+
Ftpspec::Commands.check_directory(target)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec::Matchers.define :be_owned_by do |expected|
|
20
|
+
match do |target|
|
21
|
+
Ftpspec::Commands.check_owner(target, expected)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Matchers.define :be_grouped_into do
|
26
|
+
match do |target|
|
27
|
+
Ftpspec::Commands.check_group(target, expected)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module Ftpspec
|
4
|
+
class Setup
|
5
|
+
def self.run
|
6
|
+
|
7
|
+
file_contents = <<-EOF
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
describe "/httpdocs/index.html" do
|
11
|
+
it { should be_mode 644 }
|
12
|
+
end
|
13
|
+
EOF
|
14
|
+
|
15
|
+
rakefile_contents = <<-EOF
|
16
|
+
require "rake"
|
17
|
+
require "rspec/core/rake_task"
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
20
|
+
t.pattern = "spec/*/*_spec.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :spec
|
24
|
+
EOF
|
25
|
+
|
26
|
+
spec_helper_contents = <<-EOF
|
27
|
+
require "ftpspec"
|
28
|
+
require "rubygems"
|
29
|
+
require "rspec"
|
30
|
+
require "net/ftp"
|
31
|
+
|
32
|
+
RSpec.configure do |c|
|
33
|
+
c.add_setting :ftp, :default => nil
|
34
|
+
c.before do
|
35
|
+
hostname = ""
|
36
|
+
user = ""
|
37
|
+
password = ""
|
38
|
+
c.ftp = Net::FTP.new
|
39
|
+
c.ftp.passive = true
|
40
|
+
c.ftp.connect(hostname)
|
41
|
+
c.ftp.login(user, password)
|
42
|
+
Ftpspec.set_ftp
|
43
|
+
end
|
44
|
+
c.after do
|
45
|
+
c.ftp.close
|
46
|
+
end
|
47
|
+
end
|
48
|
+
EOF
|
49
|
+
|
50
|
+
FileUtils.mkdir "spec"
|
51
|
+
File.open("spec/ftp_spec.rb", "w") do |f|
|
52
|
+
f.puts file_contents
|
53
|
+
end
|
54
|
+
File.open("spec/spec_helper.rb", "w") do |f|
|
55
|
+
f.puts spec_helper_contents
|
56
|
+
end
|
57
|
+
File.open("Rakefile", "w") do |f|
|
58
|
+
f.puts rakefile_contents
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ftpspec
|
2
|
+
class Utils
|
3
|
+
def self.convert_to_octal(str)
|
4
|
+
if str.length != 10
|
5
|
+
raise
|
6
|
+
end
|
7
|
+
|
8
|
+
octal = Array.new(3)
|
9
|
+
3.times do |i|
|
10
|
+
octal[i] = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
3.times do |i|
|
14
|
+
3.times do |j|
|
15
|
+
|
16
|
+
str_key = j + 1 + (3 * i)
|
17
|
+
octal_key = (i % 3) + (i / 3)
|
18
|
+
|
19
|
+
if str[str_key] == "r" then
|
20
|
+
octal[octal_key] += 4
|
21
|
+
end
|
22
|
+
if str[str_key] == "w" then
|
23
|
+
octal[octal_key] += 2
|
24
|
+
end
|
25
|
+
if str[str_key] == "x" then
|
26
|
+
octal[octal_key] += 1
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
octal.join("").to_i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ftpspec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rspec"
|
3
|
+
require "ftpspec/version"
|
4
|
+
require "ftpspec/setup"
|
5
|
+
require "ftpspec/matchers"
|
6
|
+
require "ftpspec/commands"
|
7
|
+
require "ftpspec/utils"
|
8
|
+
|
9
|
+
module Ftpspec
|
10
|
+
@@ftp = nil
|
11
|
+
def self.set_ftp
|
12
|
+
@@ftp = RSpec.configuration.ftp
|
13
|
+
end
|
14
|
+
def self.get_ftp
|
15
|
+
@@ftp
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Ftpspec::Commands" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class Ftp
|
7
|
+
def chdir(target)
|
8
|
+
"/httpdocs"
|
9
|
+
end
|
10
|
+
def list
|
11
|
+
[
|
12
|
+
"drwxr-xr-x 25 owner_name group_name 4096 Aug 3 19:57 .",
|
13
|
+
"drwxr-xr-x 13 root root 4096 Oct 22 2012 ..",
|
14
|
+
"-rw-r--r-- 1 owner_name group_name 26482 Jul 19 2010 index.php",
|
15
|
+
"drwxr-xr-x 4 owner_name group_name 4096 Oct 17 2010 dir"
|
16
|
+
]
|
17
|
+
end
|
18
|
+
def pwd
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@ftp = Ftp.new
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".check_mode" do
|
25
|
+
it "returns true" do
|
26
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
27
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
28
|
+
actual = Ftpspec::Commands.check_mode("/httpdocs/index.php", 644)
|
29
|
+
expect(actual).to be true
|
30
|
+
end
|
31
|
+
it "returns true" do
|
32
|
+
allow(@ftp).to receive(:pwd) { "/" }
|
33
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
34
|
+
actual = Ftpspec::Commands.check_mode("/index.php", 644)
|
35
|
+
expect(actual).to be true
|
36
|
+
end
|
37
|
+
it "returns false" do
|
38
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
39
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
40
|
+
actual = Ftpspec::Commands.check_mode("/httpdocs/index.php", 645)
|
41
|
+
expect(actual).to be false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".check_file" do
|
46
|
+
it "returns true" do
|
47
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
48
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
49
|
+
actual = Ftpspec::Commands.check_file("/httpdocs/index.php")
|
50
|
+
expect(actual).to be true
|
51
|
+
end
|
52
|
+
it "returns true" do
|
53
|
+
allow(@ftp).to receive(:pwd) { "/" }
|
54
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
55
|
+
actual = Ftpspec::Commands.check_file("/index.php")
|
56
|
+
expect(actual).to be true
|
57
|
+
end
|
58
|
+
it "returns false" do
|
59
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
60
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
61
|
+
actual = Ftpspec::Commands.check_file("/httpdocs/dir")
|
62
|
+
expect(actual).to be false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ".check_directory" do
|
67
|
+
it "returns true" do
|
68
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
69
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
70
|
+
actual = Ftpspec::Commands.check_directory("/httpdocs/dir")
|
71
|
+
expect(actual).to be true
|
72
|
+
end
|
73
|
+
it "returns true" do
|
74
|
+
allow(@ftp).to receive(:pwd) { "/" }
|
75
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
76
|
+
actual = Ftpspec::Commands.check_directory("/dir")
|
77
|
+
expect(actual).to be true
|
78
|
+
end
|
79
|
+
it "returns false" do
|
80
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
81
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
82
|
+
actual = Ftpspec::Commands.check_directory("/httpdocs/index.php")
|
83
|
+
expect(actual).to be false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe ".check_owner" do
|
88
|
+
it "returns true if owner name is valid" do
|
89
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
90
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
91
|
+
actual = Ftpspec::Commands.check_owner("/httpdocs/index.php", "owner_name")
|
92
|
+
expect(actual).to be true
|
93
|
+
end
|
94
|
+
it "returns true if owner name is valid" do
|
95
|
+
allow(@ftp).to receive(:pwd) { "/" }
|
96
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
97
|
+
actual = Ftpspec::Commands.check_owner("/index.php", "owner_name")
|
98
|
+
expect(actual).to be true
|
99
|
+
end
|
100
|
+
it "returns false if owner name is invalid" do
|
101
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
102
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
103
|
+
actual = Ftpspec::Commands.check_owner("/httpdocs/index.php", "invalid_owner")
|
104
|
+
expect(actual).to be false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe ".check_group" do
|
109
|
+
it "returns true if group name is valid" do
|
110
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
111
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
112
|
+
actual = Ftpspec::Commands.check_group("/httpdocs/index.php", "group_name")
|
113
|
+
expect(actual).to be true
|
114
|
+
end
|
115
|
+
it "returns true if group name is valid" do
|
116
|
+
allow(@ftp).to receive(:pwd) { "/" }
|
117
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
118
|
+
actual = Ftpspec::Commands.check_group("/index.php", "group_name")
|
119
|
+
expect(actual).to be true
|
120
|
+
end
|
121
|
+
it "returns false if group name is invalid" do
|
122
|
+
allow(@ftp).to receive(:pwd) { "/httpdocs" }
|
123
|
+
allow(Ftpspec).to receive(:get_ftp) { @ftp }
|
124
|
+
actual = Ftpspec::Commands.check_group("/httpdocs/index.php", "invalid_owner")
|
125
|
+
expect(actual).to be false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "ftpspec"
|
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ".convert_to_octal" do
|
4
|
+
actual = Ftpspec::Utils.convert_to_octal "-rwxrwxrwx"
|
5
|
+
it "should be 777" do
|
6
|
+
expect(actual).to eq(777)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".convert_to_octal" do
|
11
|
+
actual = Ftpspec::Utils.convert_to_octal "-rw-r--r--"
|
12
|
+
it "should be 644" do
|
13
|
+
expect(actual).to eq(644)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".convert_to_octal" do
|
18
|
+
actual = Ftpspec::Utils.convert_to_octal "----------"
|
19
|
+
it "should be 000" do
|
20
|
+
expect(actual).to eq(000)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".convert_to_octal" do
|
25
|
+
it "should be raised error" do
|
26
|
+
expect do
|
27
|
+
Ftpspec::Utils.convert_to_octal("---------")
|
28
|
+
end.to raise_error
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ftpspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toshinari Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: RSpec custom matchers for ftp server.
|
56
|
+
email:
|
57
|
+
- tsnr0001@gmail.com
|
58
|
+
executables:
|
59
|
+
- ftpspec-init
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/ftpspec-init
|
70
|
+
- ftpspec.gemspec
|
71
|
+
- lib/ftpspec.rb
|
72
|
+
- lib/ftpspec/commands.rb
|
73
|
+
- lib/ftpspec/matchers.rb
|
74
|
+
- lib/ftpspec/setup.rb
|
75
|
+
- lib/ftpspec/utils.rb
|
76
|
+
- lib/ftpspec/version.rb
|
77
|
+
- spec/command_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/utils_spec.rb
|
80
|
+
homepage: https://github.com/suzuki86/ftpspec
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.2.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: RSpec custom matchers for ftp server.
|
104
|
+
test_files:
|
105
|
+
- spec/command_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/utils_spec.rb
|