Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Show a message when listing sheets and sheets directory doesn't exist

  • Loading branch information...
commit bb3b8691be615926aaa25b16822ee1bb3f9c6f4f 1 parent c354949
@oscardelben authored
View
5 lib/sheet.rb
@@ -78,6 +78,11 @@ def command_available?(cmd)
%x!type #{cmd}!.chomp.length > 0 rescue false
end
+ # Returns true if ~/.sheets exists
+ def sheets_directory_exists?
+ File.directory?(Sheet.sheets_dir)
+ end
+
end
# Creates a new instance of Sheet, usually followed by a call to {#process}
View
6 lib/sheet/list.rb
@@ -3,7 +3,11 @@ class Sheet
class List
def list
- Sheet.exec("ls -1 #{Sheet.sheets_dir}", true)
+ if Sheet.sheets_directory_exists?
+ Sheet.exec("ls -1 #{Sheet.sheets_dir}", true)
+ else
+ Sheet.write("No sheet found. Create a new sheet with `sheet new <name>`")
+ end
end
end
end
View
2  lib/sheet/write.rb
@@ -23,7 +23,7 @@ def editor_is_set?
end
def create_dir_if_doesnt_exist
- if ! File.directory?(Sheet.sheets_dir)
+ if ! Sheet.sheets_directory_exists?
Dir.mkdir(Sheet.sheets_dir)
end
end
View
25 spec/sheet/list_spec.rb
@@ -3,11 +3,28 @@
describe Sheet::List do
- it 'calls system ls' do
- cmd = "ls -1 #{Sheet.sheets_dir}"
- Sheet.should_receive(:exec).with(cmd, true)
+ context 'when sheets directory exists' do
+ before do
+ Sheet.stub(:sheets_directory_exists?) { true }
+ end
- Sheet::List.new.list
+ it 'calls system ls' do
+ cmd = "ls -1 #{Sheet.sheets_dir}"
+ Sheet.should_receive(:exec).with(cmd, true)
+
+ Sheet::List.new.list
+ end
end
+ context 'when sheets directory doesn\'t exist' do
+ before do
+ Sheet.stub(:sheets_directory_exists?) { false }
+ end
+
+ it 'shows a message' do
+ Sheet.should_receive(:write).with("No sheet found. Create a new sheet with `sheet new <name>`")
+
+ Sheet::List.new.list
+ end
+ end
end
View
4 spec/sheet/write_spec.rb
@@ -4,6 +4,10 @@
let (:editor) { 'vim' }
+ before do
+ Sheet.stub(:sheets_directory_exists?) { true }
+ end
+
it 'opens a new file for writing' do
cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
Sheet.should_receive(:exec).with(cmd, true)
Please sign in to comment.
Something went wrong with that request. Please try again.