linux_admin 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/distro_spec.rb CHANGED
@@ -1,10 +1,8 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::Distros::Distro do
4
2
  let(:subject) { LinuxAdmin::Distros.local }
5
3
  describe "#local" do
6
4
  before do
7
- LinuxAdmin::Distros.unstub(:local)
5
+ allow(LinuxAdmin::Distros).to receive(:local).and_call_original
8
6
  end
9
7
 
10
8
  [['ubuntu', :ubuntu],
@@ -74,6 +72,6 @@ describe LinuxAdmin::Distros::Distro do
74
72
  private
75
73
 
76
74
  def exists(files)
77
- files.each_pair { |file, value| allow(File).to receive(:exists?).with(file).and_return(value) }
75
+ files.each_pair { |file, value| allow(File).to receive(:exist?).with(file).and_return(value) }
78
76
  end
79
77
  end
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'stringio'
3
2
 
4
3
  describe LinuxAdmin::EtcIssue do
@@ -9,7 +8,7 @@ describe LinuxAdmin::EtcIssue do
9
8
  end
10
9
 
11
10
  it "should not find the phrase when the file is missing" do
12
- expect(File).to receive(:exists?).with('/etc/issue').at_least(:once).and_return(false)
11
+ expect(File).to receive(:exist?).with('/etc/issue').at_least(:once).and_return(false)
13
12
  expect(subject).not_to include("phrase")
14
13
  end
15
14
 
data/spec/fstab_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'stringio'
3
2
 
4
3
  describe LinuxAdmin::FSTab do
@@ -13,9 +12,9 @@ describe LinuxAdmin::FSTab do
13
12
 
14
13
 
15
14
  eos
16
- File.should_receive(:read).with('/etc/fstab').and_return(fstab)
17
- LinuxAdmin::FSTab.instance.entries.size.should == 3
18
- LinuxAdmin::FSTab.instance.entries.any? { |e| e.has_content? }.should be_false
15
+ expect(File).to receive(:read).with('/etc/fstab').and_return(fstab)
16
+ expect(LinuxAdmin::FSTab.instance.entries.size).to eq(3)
17
+ expect(LinuxAdmin::FSTab.instance.entries.any? { |e| e.has_content? }).to be_falsey
19
18
  end
20
19
 
21
20
  it "creates FSTabEntry for each line in fstab" do
@@ -27,27 +26,27 @@ eos
27
26
  /dev/sda1 / ext4 defaults 1 1
28
27
  /dev/sda2 swap swap defaults 0 0
29
28
  eos
30
- File.should_receive(:read).with('/etc/fstab').and_return(fstab)
29
+ expect(File).to receive(:read).with('/etc/fstab').and_return(fstab)
31
30
  entries = LinuxAdmin::FSTab.instance.entries
32
- entries.size.should == 6
31
+ expect(entries.size).to eq(6)
33
32
 
34
- entries[0].comment.should == "# Comment, indented comment, comment with device information\n"
35
- entries[1].comment.should == "# /dev/sda1 / ext4 defaults 1 1\n"
36
- entries[2].comment.should == "# /dev/sda1 / ext4 defaults 1 1\n"
37
- entries[3].comment.should == nil
38
- entries[4].device.should == '/dev/sda1'
39
- entries[4].mount_point.should == '/'
40
- entries[4].fs_type.should == 'ext4'
41
- entries[4].mount_options.should == 'defaults'
42
- entries[4].dumpable.should == 1
43
- entries[4].fsck_order.should == 1
33
+ expect(entries[0].comment).to eq("# Comment, indented comment, comment with device information\n")
34
+ expect(entries[1].comment).to eq("# /dev/sda1 / ext4 defaults 1 1\n")
35
+ expect(entries[2].comment).to eq("# /dev/sda1 / ext4 defaults 1 1\n")
36
+ expect(entries[3].comment).to eq(nil)
37
+ expect(entries[4].device).to eq('/dev/sda1')
38
+ expect(entries[4].mount_point).to eq('/')
39
+ expect(entries[4].fs_type).to eq('ext4')
40
+ expect(entries[4].mount_options).to eq('defaults')
41
+ expect(entries[4].dumpable).to eq(1)
42
+ expect(entries[4].fsck_order).to eq(1)
44
43
 
45
- entries[5].device.should == '/dev/sda2'
46
- entries[5].mount_point.should == 'swap'
47
- entries[5].fs_type.should == 'swap'
48
- entries[5].mount_options.should == 'defaults'
49
- entries[5].dumpable.should == 0
50
- entries[5].fsck_order.should == 0
44
+ expect(entries[5].device).to eq('/dev/sda2')
45
+ expect(entries[5].mount_point).to eq('swap')
46
+ expect(entries[5].fs_type).to eq('swap')
47
+ expect(entries[5].mount_options).to eq('defaults')
48
+ expect(entries[5].dumpable).to eq(0)
49
+ expect(entries[5].fsck_order).to eq(0)
51
50
  end
52
51
 
53
52
  describe "#write!" do
@@ -61,11 +60,11 @@ eos
61
60
  entry.dumpable = 1
62
61
  entry.fsck_order = 1
63
62
  entry.comment = "# more"
64
- LinuxAdmin::FSTab.any_instance.stub(:refresh) # don't read /etc/fstab
63
+ allow_any_instance_of(LinuxAdmin::FSTab).to receive(:refresh) # don't read /etc/fstab
65
64
  LinuxAdmin::FSTab.instance.maximum_column_lengths = [9, 1, 4, 8, 1, 1, 1]
66
65
  LinuxAdmin::FSTab.instance.entries = [entry]
67
66
 
68
- File.should_receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1 # more\n")
67
+ expect(File).to receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1 # more\n")
69
68
  LinuxAdmin::FSTab.instance.write!
70
69
  end
71
70
  end
data/spec/hosts_spec.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::Hosts do
4
2
  etc_hosts = "\n #Some Comment\n127.0.0.1\tlocalhost localhost.localdomain # with a comment\n127.0.1.1 my.domain.local"
5
3
  before do
6
- File.stub(:read).and_return(etc_hosts)
4
+ allow(File).to receive(:read).and_return(etc_hosts)
7
5
  @instance = LinuxAdmin::Hosts.new
8
6
  end
9
7
 
@@ -35,7 +33,7 @@ describe LinuxAdmin::Hosts do
35
33
 
36
34
  describe "#save" do
37
35
  before do
38
- File.stub(:write)
36
+ allow(File).to receive(:write)
39
37
  end
40
38
 
41
39
  it "properly generates file with new content" do
@@ -52,4 +50,4 @@ describe LinuxAdmin::Hosts do
52
50
  expect(@instance.raw_lines).to eq(expected_array)
53
51
  end
54
52
  end
55
- end
53
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe LinuxAdmin::LogicalVolume do
4
2
  before(:each) do
5
3
  @logical_volumes = <<eos
@@ -23,7 +21,7 @@ eos
23
21
  it "uses lvextend" do
24
22
  vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
25
23
  lv = described_class.new :name => 'lv', :volume_group => vg
26
- lv.should_receive(:run!).
24
+ expect(lv).to receive(:run!).
27
25
  with(vg.cmd(:lvextend),
28
26
  :params => ['lv', 'vg'])
29
27
  lv.extend_with(vg)
@@ -32,8 +30,8 @@ eos
32
30
  it "returns self" do
33
31
  vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
34
32
  lv = described_class.new :name => 'lv', :volume_group => vg
35
- lv.stub(:run!)
36
- lv.extend_with(vg).should == lv
33
+ allow(lv).to receive(:run!)
34
+ expect(lv.extend_with(vg)).to eq(lv)
37
35
  end
38
36
  end
39
37
 
@@ -41,7 +39,7 @@ eos
41
39
  it "returns /dev/vgname/lvname" do
42
40
  vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
43
41
  lv = described_class.new :name => 'lv', :volume_group => vg
44
- lv.path.should == '/dev/vg/lv'
42
+ expect(lv.path).to eq('/dev/vg/lv')
45
43
  end
46
44
  end
47
45
 
@@ -52,7 +50,7 @@ eos
52
50
 
53
51
  it "uses lvcreate" do
54
52
  described_class.instance_variable_set(:@lvs, [])
55
- described_class.should_receive(:run!).
53
+ expect(described_class).to receive(:run!).
56
54
  with(LinuxAdmin.cmd(:lvcreate),
57
55
  :params => { '-n' => 'lv',
58
56
  nil => 'vg',
@@ -63,7 +61,7 @@ eos
63
61
  context "size is specified" do
64
62
  it "passes -L option to lvcreate" do
65
63
  described_class.instance_variable_set(:@lvs, [])
66
- described_class.should_receive(:run!).
64
+ expect(described_class).to receive(:run!).
67
65
  with(LinuxAdmin.cmd(:lvcreate),
68
66
  :params => { '-n' => 'lv',
69
67
  nil => 'vg',
@@ -75,7 +73,7 @@ eos
75
73
  context "extents is specified" do
76
74
  it "passes -l option to lvcreate" do
77
75
  described_class.instance_variable_set(:@lvs, [])
78
- described_class.should_receive(:run!).
76
+ expect(described_class).to receive(:run!).
79
77
  with(LinuxAdmin.cmd(:lvcreate),
80
78
  :params => { '-n' => 'lv',
81
79
  nil => 'vg',
@@ -85,84 +83,84 @@ eos
85
83
  end
86
84
 
87
85
  it "returns new logical volume" do
88
- LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
89
- described_class.stub(:run! => double(:output => ""))
86
+ allow(LinuxAdmin::VolumeGroup).to receive_messages(:run! => double(:output => ""))
87
+ allow(described_class).to receive_messages(:run! => double(:output => ""))
90
88
  lv = described_class.create 'lv', @vg, 256.gigabytes
91
- lv.should be_an_instance_of(described_class)
92
- lv.name.should == 'lv'
89
+ expect(lv).to be_an_instance_of(described_class)
90
+ expect(lv.name).to eq('lv')
93
91
  end
94
92
 
95
93
  context "name is specified" do
96
94
  it "sets path under volume group" do
97
- LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
98
- described_class.stub(:run! => double(:output => ""))
95
+ allow(LinuxAdmin::VolumeGroup).to receive_messages(:run! => double(:output => ""))
96
+ allow(described_class).to receive_messages(:run! => double(:output => ""))
99
97
  lv = described_class.create 'lv', @vg, 256.gigabytes
100
- lv.path.to_s.should == "#{described_class::DEVICE_PATH}#{@vg.name}/lv"
98
+ expect(lv.path.to_s).to eq("#{described_class::DEVICE_PATH}#{@vg.name}/lv")
101
99
  end
102
100
  end
103
101
 
104
102
  context "path is specified" do
105
103
  it "sets name" do
106
- LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
107
- described_class.stub(:run! => double(:output => ""))
104
+ allow(LinuxAdmin::VolumeGroup).to receive_messages(:run! => double(:output => ""))
105
+ allow(described_class).to receive_messages(:run! => double(:output => ""))
108
106
  lv = described_class.create '/dev/lv', @vg, 256.gigabytes
109
- lv.name.should == "lv"
107
+ expect(lv.name).to eq("lv")
110
108
  end
111
109
  end
112
110
 
113
111
  context "path is specified as Pathname" do
114
112
  it "sets name" do
115
113
  require 'pathname'
116
- LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
117
- described_class.stub(:run! => double(:output => ""))
114
+ allow(LinuxAdmin::VolumeGroup).to receive_messages(:run! => double(:output => ""))
115
+ allow(described_class).to receive_messages(:run! => double(:output => ""))
118
116
  lv = described_class.create Pathname.new("/dev/#{@vg.name}/lv"), @vg, 256.gigabytes
119
- lv.name.should == "lv"
120
- lv.path.should == "/dev/vg/lv"
117
+ expect(lv.name).to eq("lv")
118
+ expect(lv.path).to eq("/dev/vg/lv")
121
119
  end
122
120
  end
123
121
 
124
122
  it "adds logical volume to local registry" do
125
- LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
126
- described_class.stub(:run! => double(:output => ""))
123
+ allow(LinuxAdmin::VolumeGroup).to receive_messages(:run! => double(:output => ""))
124
+ allow(described_class).to receive_messages(:run! => double(:output => ""))
127
125
  lv = described_class.create 'lv', @vg, 256.gigabytes
128
- described_class.scan.should include(lv)
126
+ expect(described_class.scan).to include(lv)
129
127
  end
130
128
  end
131
129
 
132
130
  describe "#scan" do
133
131
  it "uses lvdisplay" do
134
- described_class.should_receive(:run!).
132
+ expect(described_class).to receive(:run!).
135
133
  with(LinuxAdmin.cmd(:lvdisplay),
136
134
  :params => { '-c' => nil}).
137
135
  and_return(double(:output => @logical_volumes))
138
- LinuxAdmin::VolumeGroup.should_receive(:run!).and_return(double(:output => @groups)) # stub out call to vgdisplay
136
+ expect(LinuxAdmin::VolumeGroup).to receive(:run!).and_return(double(:output => @groups)) # stub out call to vgdisplay
139
137
  described_class.scan
140
138
  end
141
139
 
142
140
  it "returns local logical volumes" do
143
- described_class.should_receive(:run!).and_return(double(:output => @logical_volumes))
144
- LinuxAdmin::VolumeGroup.should_receive(:run!).and_return(double(:output => @groups))
141
+ expect(described_class).to receive(:run!).and_return(double(:output => @logical_volumes))
142
+ expect(LinuxAdmin::VolumeGroup).to receive(:run!).and_return(double(:output => @groups))
145
143
  lvs = described_class.scan
146
144
 
147
- lvs[0].should be_an_instance_of(described_class)
148
- lvs[0].path.should == '/dev/vg_foobar/lv_swap'
149
- lvs[0].name.should == 'lv_swap'
150
- lvs[0].sectors.should == 4128768
145
+ expect(lvs[0]).to be_an_instance_of(described_class)
146
+ expect(lvs[0].path).to eq('/dev/vg_foobar/lv_swap')
147
+ expect(lvs[0].name).to eq('lv_swap')
148
+ expect(lvs[0].sectors).to eq(4128768)
151
149
 
152
- lvs[1].should be_an_instance_of(described_class)
153
- lvs[1].path.should == '/dev/vg_foobar/lv_root'
154
- lvs[1].name.should == 'lv_root'
155
- lvs[1].sectors.should == 19988480
150
+ expect(lvs[1]).to be_an_instance_of(described_class)
151
+ expect(lvs[1].path).to eq('/dev/vg_foobar/lv_root')
152
+ expect(lvs[1].name).to eq('lv_root')
153
+ expect(lvs[1].sectors).to eq(19988480)
156
154
  end
157
155
 
158
156
  it "resolves volume group references" do
159
- described_class.should_receive(:run!).and_return(double(:output => @logical_volumes))
160
- LinuxAdmin::VolumeGroup.should_receive(:run!).and_return(double(:output => @groups))
157
+ expect(described_class).to receive(:run!).and_return(double(:output => @logical_volumes))
158
+ expect(LinuxAdmin::VolumeGroup).to receive(:run!).and_return(double(:output => @groups))
161
159
  lvs = described_class.scan
162
- lvs[0].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup)
163
- lvs[0].volume_group.name.should == 'vg_foobar'
164
- lvs[1].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup)
165
- lvs[1].volume_group.name.should == 'vg_foobar'
160
+ expect(lvs[0].volume_group).to be_an_instance_of(LinuxAdmin::VolumeGroup)
161
+ expect(lvs[0].volume_group.name).to eq('vg_foobar')
162
+ expect(lvs[1].volume_group).to be_an_instance_of(LinuxAdmin::VolumeGroup)
163
+ expect(lvs[1].volume_group.name).to eq('vg_foobar')
166
164
  end
167
165
  end
168
166
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  class TestMountable < LinuxAdmin
4
2
  include LinuxAdmin::Mountable
5
3
 
@@ -13,8 +11,8 @@ describe LinuxAdmin::Mountable do
13
11
  @mountable = TestMountable.new
14
12
 
15
13
  # stub out calls that modify system
16
- FileUtils.stub(:mkdir)
17
- @mountable.stub(:run!)
14
+ allow(FileUtils).to receive(:mkdir)
15
+ allow(@mountable).to receive(:run!)
18
16
 
19
17
  @mount_out1 = <<eos
20
18
  /dev/sda on /mnt/usb type vfat (rw)
@@ -27,92 +25,92 @@ eos
27
25
 
28
26
  describe "#mount_point_exists?" do
29
27
  it "uses mount" do
30
- TestMountable.should_receive(:run!).with(TestMountable.cmd(:mount)).and_return(double(:output => ""))
28
+ expect(TestMountable).to receive(:run!).with(TestMountable.cmd(:mount)).and_return(double(:output => ""))
31
29
  TestMountable.mount_point_exists?('/mnt/usb')
32
30
  end
33
31
 
34
32
  context "disk mounted at specified location" do
35
33
  it "returns true" do
36
- TestMountable.should_receive(:run!).and_return(double(:output => @mount_out1))
37
- TestMountable.mount_point_exists?('/mnt/usb').should be_true
34
+ expect(TestMountable).to receive(:run!).and_return(double(:output => @mount_out1))
35
+ expect(TestMountable.mount_point_exists?('/mnt/usb')).to be_truthy
38
36
  end
39
37
  end
40
38
 
41
39
  context "no disk mounted at specified location" do
42
40
  it "returns false" do
43
- TestMountable.should_receive(:run!).and_return(double(:output => @mount_out2))
44
- TestMountable.mount_point_exists?('/mnt/usb').should be_false
41
+ expect(TestMountable).to receive(:run!).and_return(double(:output => @mount_out2))
42
+ expect(TestMountable.mount_point_exists?('/mnt/usb')).to be_falsey
45
43
  end
46
44
  end
47
45
  end
48
46
 
49
47
  describe "#mount_point_available?" do
50
48
  it "uses mount" do
51
- TestMountable.should_receive(:run!).with(TestMountable.cmd(:mount)).and_return(double(:output => ""))
49
+ expect(TestMountable).to receive(:run!).with(TestMountable.cmd(:mount)).and_return(double(:output => ""))
52
50
  TestMountable.mount_point_available?('/mnt/usb')
53
51
  end
54
52
 
55
53
  context "disk mounted at specified location" do
56
54
  it "returns false" do
57
- TestMountable.should_receive(:run!).and_return(double(:output => @mount_out1))
58
- TestMountable.mount_point_available?('/mnt/usb').should be_false
55
+ expect(TestMountable).to receive(:run!).and_return(double(:output => @mount_out1))
56
+ expect(TestMountable.mount_point_available?('/mnt/usb')).to be_falsey
59
57
  end
60
58
  end
61
59
 
62
60
  context "no disk mounted at specified location" do
63
61
  it "returns true" do
64
- TestMountable.should_receive(:run!).and_return(double(:output => @mount_out2))
65
- TestMountable.mount_point_available?('/mnt/usb').should be_true
62
+ expect(TestMountable).to receive(:run!).and_return(double(:output => @mount_out2))
63
+ expect(TestMountable.mount_point_available?('/mnt/usb')).to be_truthy
66
64
  end
67
65
  end
68
66
  end
69
67
 
70
68
  describe "#format_to" do
71
69
  it "uses mke2fs" do
72
- @mountable.should_receive(:run!).
70
+ expect(@mountable).to receive(:run!).
73
71
  with(@mountable.cmd(:mke2fs),
74
72
  :params => { '-t' => 'ext4', nil => '/dev/foo'})
75
73
  @mountable.format_to('ext4')
76
74
  end
77
75
 
78
76
  it "sets fs type" do
79
- @mountable.should_receive(:run!) # ignore actual formatting cmd
77
+ expect(@mountable).to receive(:run!) # ignore actual formatting cmd
80
78
  @mountable.format_to('ext4')
81
- @mountable.fs_type.should == 'ext4'
79
+ expect(@mountable.fs_type).to eq('ext4')
82
80
  end
83
81
  end
84
82
 
85
83
  describe "#mount" do
86
84
  it "sets mount point" do
87
85
  # ignore actual mount cmds
88
- @mountable.should_receive(:run!).and_return(double(:output => ""))
89
- TestMountable.should_receive(:run!).and_return(double(:output => ""))
86
+ expect(@mountable).to receive(:run!).and_return(double(:output => ""))
87
+ expect(TestMountable).to receive(:run!).and_return(double(:output => ""))
90
88
 
91
- @mountable.mount('/mnt/sda2').should == '/mnt/sda2'
92
- @mountable.mount_point.should == '/mnt/sda2'
89
+ expect(@mountable.mount('/mnt/sda2')).to eq('/mnt/sda2')
90
+ expect(@mountable.mount_point).to eq('/mnt/sda2')
93
91
  end
94
92
 
95
93
  context "mountpoint does not exist" do
96
94
  it "creates mountpoint" do
97
- TestMountable.should_receive(:mount_point_exists?).and_return(false)
98
- File.should_receive(:directory?).with('/mnt/sda2').and_return(false)
99
- FileUtils.should_receive(:mkdir).with('/mnt/sda2')
100
- @mountable.should_receive(:run!) # ignore actual mount cmd
95
+ expect(TestMountable).to receive(:mount_point_exists?).and_return(false)
96
+ expect(File).to receive(:directory?).with('/mnt/sda2').and_return(false)
97
+ expect(FileUtils).to receive(:mkdir).with('/mnt/sda2')
98
+ expect(@mountable).to receive(:run!) # ignore actual mount cmd
101
99
  @mountable.mount '/mnt/sda2'
102
100
  end
103
101
  end
104
102
 
105
103
  context "disk mounted at mountpoint" do
106
104
  it "raises argument error" do
107
- TestMountable.should_receive(:mount_point_exists?).and_return(true)
108
- File.should_receive(:directory?).with('/mnt/sda2').and_return(true)
105
+ expect(TestMountable).to receive(:mount_point_exists?).and_return(true)
106
+ expect(File).to receive(:directory?).with('/mnt/sda2').and_return(true)
109
107
  expect { @mountable.mount '/mnt/sda2' }.to raise_error(ArgumentError, "disk already mounted at /mnt/sda2")
110
108
  end
111
109
  end
112
110
 
113
111
  it "mounts partition" do
114
- TestMountable.should_receive(:mount_point_exists?).and_return(false)
115
- @mountable.should_receive(:run!).
112
+ expect(TestMountable).to receive(:mount_point_exists?).and_return(false)
113
+ expect(@mountable).to receive(:run!).
116
114
  with(@mountable.cmd(:mount),
117
115
  :params => { nil => ['/dev/foo', '/mnt/sda2']})
118
116
  @mountable.mount '/mnt/sda2'
@@ -122,7 +120,7 @@ eos
122
120
  describe "#umount" do
123
121
  it "unmounts partition" do
124
122
  @mountable.mount_point = '/mnt/sda2'
125
- @mountable.should_receive(:run!).with(@mountable.cmd(:umount), :params => { nil => ['/mnt/sda2']})
123
+ expect(@mountable).to receive(:run!).with(@mountable.cmd(:umount), :params => { nil => ['/mnt/sda2']})
126
124
  @mountable.umount
127
125
  end
128
126
  end