sambal 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -327,7 +327,7 @@
327
327
  ; path = /cdrom
328
328
  ; guest ok = yes
329
329
 
330
- [spec]
330
+ [<%= share_name %>]
331
331
  comment = Spec directory
332
332
  read only = no
333
333
  writeable = yes
@@ -0,0 +1,77 @@
1
+ # coding: UTF-8
2
+
3
+ require "erb"
4
+ require "fileutils"
5
+
6
+ class Hash
7
+ def to_binding(object = Object.new)
8
+ object.instance_eval("def binding_for(#{keys.join(",")}) binding end")
9
+ object.binding_for(*values)
10
+ end
11
+ end
12
+
13
+ class Document
14
+ def initialize(template)
15
+ @template = ERB.new(template)
16
+ end
17
+
18
+ def interpolate(replacements = {})
19
+ @template.result(replacements.to_binding)
20
+ end
21
+ end
22
+
23
+ module Sambal
24
+ class TestServer
25
+
26
+ attr_reader :port
27
+ attr_reader :share_path
28
+ attr_reader :root_path
29
+ attr_reader :config_path
30
+ attr_reader :share_name
31
+ attr_reader :run_as
32
+ attr_reader :host
33
+
34
+ def initialize(root_path="/tmp/sambal_test_server_#{Time.now.to_i}", share_name='sambal_test', run_as=ENV['USER'])
35
+ @erb_path = "#{File.expand_path(File.dirname(__FILE__))}/smb.conf.erb"
36
+ @host = "127.0.0.1" ## will always just be localhost
37
+ @root_path = root_path
38
+ @share_path = "#{root_path}/share"
39
+ @share_name = share_name
40
+ @config_path = "#{root_path}/smb.conf"
41
+ @port = Random.new(Time.now.to_i).rand(2345..5678).to_i
42
+ @run_as = run_as
43
+ FileUtils.mkdir_p @share_path
44
+ write_config
45
+ end
46
+
47
+ def find_pids
48
+ pids = `ps ax | grep smbd | grep #{@port} | grep -v grep | awk '{print \$1}'`.chomp
49
+ pids.split("\n").map {|p| (p.nil? || p=='') ? nil : p.to_i }
50
+ end
51
+
52
+ def write_config
53
+ File.open(@config_path, 'w') do |f|
54
+ f << Document.new(IO.binread(@erb_path)).interpolate(samba_share: @share_path, local_user: @run_as, share_name: @share_name)
55
+ end
56
+ end
57
+
58
+ def start
59
+ @smb_server_pid = fork do
60
+ `smbd -S -F -s #{@config_path} -p #{@port}`
61
+ end
62
+ sleep 2 ## takes a short time to start up
63
+ end
64
+
65
+ def stop
66
+ ## stopping is done in an ugly way by grepping
67
+ pids = find_pids
68
+ pids.each { |ppid| `kill -9 #{ppid} 2> /dev/null` }
69
+ end
70
+
71
+ def stop!
72
+ stop
73
+ FileUtils.rm_rf @root_path
74
+ end
75
+
76
+ end
77
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module Sambal
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
@@ -5,26 +5,18 @@ require 'tempfile'
5
5
 
6
6
  describe Sambal::Client do
7
7
 
8
- SMB_PORT = 2321
9
- SHARE_NAME = 'spec'
10
-
11
- def smbd_pids
12
- pids = `ps ax | grep smbd | grep #{SMB_PORT} | grep -v grep | awk '{print \$1}'`.chomp
13
- pids.split("\n").map {|p| (p.nil? || p=='') ? nil : p.to_i }
14
- end
15
-
16
- def start_smbd
17
- ## we just start an smb server here for the duration of this spec
18
- @smb_server_pid = fork do
19
- `smbd -S -F -s #{SAMBA_CONF} -p 2321`
8
+ before(:all) do
9
+ File.open("#{test_server.share_path}/#{testfile}", 'w') do |f|
10
+ f << "Hello"
20
11
  end
21
- sleep 2 ## takes a short time to start up
12
+ FileUtils.mkdir_p "#{test_server.share_path}/#{test_directory}"
13
+ FileUtils.chmod 0775, "#{test_server.share_path}/#{test_directory}"
14
+ FileUtils.chmod 0777, "#{test_server.share_path}/#{testfile}"
15
+ @sambal_client = described_class.new(host: test_server.host, share: test_server.share_name, port: test_server.port)
22
16
  end
23
-
24
- def stop_smbd
25
- ## stopping is done in an ugly way now by greping etc - it works
26
- pids = smbd_pids
27
- pids.each { |ppid| `kill -9 #{ppid} 2> /dev/null` }
17
+
18
+ after(:all) do
19
+ @sambal_client.close
28
20
  end
29
21
 
30
22
  let(:file_to_upload) do
@@ -43,22 +35,6 @@ describe Sambal::Client do
43
35
  'testfile.txt'
44
36
  end
45
37
 
46
- before(:all) do
47
- File.open("#{SAMBA_SHARE}/#{testfile}", 'w') do |f|
48
- f << "Hello"
49
- end
50
- FileUtils.mkdir_p "#{SAMBA_SHARE}/#{test_directory}"
51
- FileUtils.chmod 0775, "#{SAMBA_SHARE}/#{test_directory}"
52
- FileUtils.chmod 0777, "#{SAMBA_SHARE}/#{testfile}"
53
- start_smbd
54
- @sambal_client = described_class.new(host: '127.0.0.1', share: SHARE_NAME, port: SMB_PORT)
55
- end
56
-
57
- after(:all) do
58
- @sambal_client.close
59
- stop_smbd
60
- end
61
-
62
38
  it "should list files on an smb server" do
63
39
  @sambal_client.ls.should have_key(testfile)
64
40
  end
data/spec/spec_helper.rb CHANGED
@@ -8,41 +8,7 @@ lib_path = File.expand_path('../lib', File.dirname(__FILE__))
8
8
  $:.unshift(lib_path) if File.directory?(lib_path) && !$:.include?(lib_path)
9
9
 
10
10
  require 'sambal'
11
-
12
- FileUtils.rm_rf "/tmp/sambal_spec/samba"
13
- FileUtils.mkdir_p "/tmp/sambal_spec/samba/"
14
-
15
- spec_path = File.expand_path('./', File.dirname(__FILE__))
16
-
17
- SAMBA_SHARE = "#{spec_path}/sambashare"
18
- SAMBA_CONF = "#{spec_path}/smb.conf"
19
-
20
- FileUtils.rm_rf SAMBA_SHARE
21
- FileUtils.mkdir_p SAMBA_SHARE
22
- #
23
- require "erb"
24
- #
25
- class Hash
26
- def to_binding(object = Object.new)
27
- object.instance_eval("def binding_for(#{keys.join(",")}) binding end")
28
- object.binding_for(*values)
29
- end
30
- end
31
-
32
- class Document
33
- def initialize(template)
34
- @template = ERB.new(template)
35
- end
36
-
37
- def interpolate(replacements = {})
38
- @template.result(replacements.to_binding)
39
- end
40
- end
41
- #
42
-
43
- File.open(SAMBA_CONF, 'w') do |f|
44
- f << Document.new(IO.binread("#{spec_path}/smb.conf.erb")).interpolate(samba_share: SAMBA_SHARE, local_user: ENV['USER'])
45
- end
11
+ require 'sambal/test_server'
46
12
 
47
13
  RSpec::Matchers.define :be_successful do
48
14
  match do |actual|
@@ -50,8 +16,11 @@ RSpec::Matchers.define :be_successful do
50
16
  end
51
17
  end
52
18
 
53
- #
54
- #
19
+ module TestServer
20
+ def test_server
21
+ $test_server
22
+ end
23
+ end
55
24
 
56
25
  RSpec.configure do |config|
57
26
  # == Mock Framework
@@ -68,4 +37,16 @@ RSpec.configure do |config|
68
37
  config.color_enabled = true
69
38
  ## dont do this, do it in Rakefile instead
70
39
  #config.formatter = 'd'
40
+
41
+ config.before(:suite) do
42
+ $test_server = Sambal::TestServer.new
43
+ $test_server.start
44
+ end
45
+
46
+ config.after(:suite) do
47
+ $test_server.stop! ## removes any created directories
48
+ end
49
+
50
+ config.include TestServer
51
+
71
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sambal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
12
+ date: 2012-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70152943099320 !ruby/object:Gem::Requirement
16
+ requirement: &70339101671600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70152943099320
24
+ version_requirements: *70339101671600
25
25
  description: Ruby Samba Client using the cmdline smbclient
26
26
  email:
27
27
  - john@insane.se
@@ -35,10 +35,11 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - lib/sambal.rb
38
+ - lib/sambal/smb.conf.erb
39
+ - lib/sambal/test_server.rb
38
40
  - lib/sambal/version.rb
39
41
  - sambal.gemspec
40
42
  - spec/sambal/client_spec.rb
41
- - spec/smb.conf.erb
42
43
  - spec/spec_helper.rb
43
44
  homepage: https://github.com/johnae/sambal
44
45
  licenses: []
@@ -66,5 +67,4 @@ specification_version: 3
66
67
  summary: Ruby Samba Client
67
68
  test_files:
68
69
  - spec/sambal/client_spec.rb
69
- - spec/smb.conf.erb
70
70
  - spec/spec_helper.rb