Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/linux_admin/hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def reload
def save
cleanup_empty
@raw_lines = assemble_lines
File.write(@filename, @raw_lines.join("\n"))
File.write(@filename, @raw_lines.join("\n") + "\n")
end

def update_entry(address, hostname, comment = nil)
Expand Down
13 changes: 9 additions & 4 deletions spec/hosts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,28 @@
end

describe "#save" do
before do
allow(File).to receive(:write)
end

it "properly generates file with new content" do
allow(File).to receive(:write)
expected_array = ["", "#Some Comment", "127.0.0.1 localhost localhost.localdomain #with a comment", "127.0.1.1 my.domain.local", "1.2.3.4 test"]
@instance.update_entry("1.2.3.4", "test")
@instance.save
expect(@instance.raw_lines).to eq(expected_array)
end

it "properly generates file with removed content" do
allow(File).to receive(:write)
expected_array = ["", "#Some Comment", "127.0.0.1 localhost localhost.localdomain my.domain.local #with a comment"]
@instance.update_entry("127.0.0.1", "my.domain.local")
@instance.save
expect(@instance.raw_lines).to eq(expected_array)
end

it "ends the file with a new line" do
expect(File).to receive(:write) do |_file, contents|
expect(contents).to end_with("\n")
end
@instance.save
end
end

describe "#hostname=" do
Expand Down