Skip to content
Browse files

Don't throw an exception if no argument is passed to new

  • Loading branch information...
1 parent df6d990 commit 9addd4acf56ce4df44e52e72876404ad35db1574 @oscardelben committed May 1, 2012
Showing with 7 additions and 1 deletion.
  1. +2 −1 lib/sheet/write.rb
  2. +5 −0 spec/sheet/write_spec.rb
View
3 lib/sheet/write.rb
@@ -3,11 +3,12 @@ class Sheet::Write
attr_accessor :name
- def initialize(name)
+ def initialize(name=nil)
@name = name
end
def write
+ return Sheet.write("Please specify a name") unless name
create_dir_if_doesnt_exist
if editor_is_set?
Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
View
5 spec/sheet/write_spec.rb
@@ -8,6 +8,11 @@
Sheet.stub(:sheets_directory_exists?) { true }
end
+ it 'shows an error message if no argument is passed' do
+ Sheet.should_receive(:write).with('Please specify a name')
+ Sheet::Write.new.write
+ end
+
it 'opens a new file for writing' do
cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
Sheet.should_receive(:exec).with(cmd, true)

0 comments on commit 9addd4a

Please sign in to comment.
Something went wrong with that request. Please try again.