Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI#edit edits a file and returns the contents
- Loading branch information
Josep M. Bach
committed
Dec 8, 2011
1 parent
68ae61c
commit 84a6f4d
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require_relative "springpad/version" | ||
require_relative "springpad/api" | ||
require_relative "springpad/blocks" | ||
require_relative "springpad/cli" | ||
|
||
module Springpad | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'tempfile' | ||
|
||
module Springpad | ||
class CLI | ||
# Public: Edits a file with $EDITOR and returns the contents. | ||
# | ||
# Returns an Array with the first line and an array of the other lines. | ||
def edit | ||
temp_file = Tempfile.new('block') | ||
system("$EDITOR #{temp_file.path}") | ||
contents = temp_file.read.chomp.split("\n").reject(&:empty?).map(&:strip) | ||
[contents.first, contents[1..-1]] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'test_helper' | ||
|
||
module Springpad | ||
describe CLI do | ||
describe "#edit" do | ||
it 'edits a file and returns the contents' do | ||
cli = CLI.new | ||
|
||
Tempfile.stubs(:new).returns file = stub_everything | ||
file.stubs(:path).returns "/tmp/something" | ||
file.stubs(:read).returns """Name of the task \n\n This is a description of the task\nThis is more body for the task\n" | ||
cli.expects(:system).with("$EDITOR /tmp/something") | ||
|
||
cli.edit.must_equal [ | ||
"Name of the task", | ||
[ | ||
"This is a description of the task", | ||
"This is more body for the task", | ||
] | ||
] | ||
end | ||
end | ||
end | ||
end |