Skip to content

Commit

Permalink
Don't throw an exception if no argument is passed to new
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed May 1, 2012
1 parent df6d990 commit 9addd4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sheet/write.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ class Sheet::Write


attr_accessor :name attr_accessor :name


def initialize(name) def initialize(name=nil)
@name = name @name = name
end end


def write def write
return Sheet.write("Please specify a name") unless name
create_dir_if_doesnt_exist create_dir_if_doesnt_exist
if editor_is_set? if editor_is_set?
Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true) Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
Expand Down
5 changes: 5 additions & 0 deletions spec/sheet/write_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
Sheet.stub(:sheets_directory_exists?) { true } Sheet.stub(:sheets_directory_exists?) { true }
end 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 it 'opens a new file for writing' do
cmd = "#{editor} #{Sheet.sheet_path('tmux')}" cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
Sheet.should_receive(:exec).with(cmd, true) Sheet.should_receive(:exec).with(cmd, true)
Expand Down

0 comments on commit 9addd4a

Please sign in to comment.