lg 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Guardfile +20 -0
- data/README.md +117 -0
- data/Rakefile +1 -0
- data/bin/lg +13 -0
- data/lib/gist_store/cacert.pem +116 -0
- data/lib/gist_store/gist.rb +255 -0
- data/lib/gist_store/gist_store.rb +62 -0
- data/lib/gist_store/net_http_ext.rb +56 -0
- data/lib/logbook.rb +14 -0
- data/lib/logbook/book.rb +79 -0
- data/lib/logbook/cli.rb +127 -0
- data/lib/logbook/version.rb +3 -0
- data/logbook.gemspec +29 -0
- data/spec/gist_store/gist_store_spec.rb +86 -0
- data/spec/logbook/book_spec.rb +82 -0
- data/spec/logbook/cli_spec.rb +134 -0
- data/spec/spec_helper.rb +58 -0
- metadata +131 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logbook'
|
3
|
+
|
4
|
+
def stamp
|
5
|
+
@stamp ||= Time.new(1981, 9, 8)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Logbook::Book do
|
9
|
+
|
10
|
+
it "should create and add an entry given no page existed" do
|
11
|
+
gs= Object.new
|
12
|
+
Logbook.store = gs
|
13
|
+
|
14
|
+
stub(gs).valid?{ true }
|
15
|
+
mock(gs).create("The Neverending Story") { "book-id" }
|
16
|
+
mock(gs).get("book-id", stamp) { nil }
|
17
|
+
mock(gs).update("book-id", stamp, "testing 123") { stamp }
|
18
|
+
|
19
|
+
@bk = Logbook::Book.new
|
20
|
+
@bk.create "The Neverending Story"
|
21
|
+
@bk.add(stamp, "testing 123")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should add an entry given a page existed" do
|
25
|
+
gs= Object.new
|
26
|
+
Logbook.store = gs
|
27
|
+
stub(gs).valid?{ true }
|
28
|
+
mock(gs).create("#{ENV['USER']}'s log.") { "book-id" }
|
29
|
+
mock(gs).get("book-id", stamp) { "testing 123" }
|
30
|
+
mock(gs).update("book-id", stamp, "testing 123\ntesting 456") { stamp }
|
31
|
+
|
32
|
+
@bk = Logbook::Book.new
|
33
|
+
@bk.create
|
34
|
+
@bk.add(stamp, "testing 456")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get an entry" do
|
38
|
+
gs= Object.new
|
39
|
+
Logbook.store = gs
|
40
|
+
|
41
|
+
@bk = Logbook::Book.new('book-id')
|
42
|
+
mock(gs).valid?{ true }
|
43
|
+
mock(gs).get("book-id", stamp) { "testing 123" }
|
44
|
+
|
45
|
+
@bk.get(stamp).must_equal "testing 123"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
it "Should fetch all of the book" do
|
50
|
+
gs= Object.new
|
51
|
+
Logbook.store = gs
|
52
|
+
|
53
|
+
@bk = Logbook::Book.new('book-id')
|
54
|
+
stub(gs).valid?{ true }
|
55
|
+
mock(gs).all('book-id') {
|
56
|
+
{
|
57
|
+
:cover => "The Neverending Story",
|
58
|
+
:entries => [{
|
59
|
+
:content => "testing 123\ntesting 456",
|
60
|
+
:date => stamp
|
61
|
+
}]
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
book = @bk.all
|
66
|
+
book[:cover].must_equal "The Neverending Story"
|
67
|
+
book[:entries].count.must_equal 1 # excluding book cover file
|
68
|
+
book[:entries][0][:content].must_equal "testing 123\ntesting 456"
|
69
|
+
book[:entries][0][:date].must_equal stamp
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should handle store not being valid" do
|
73
|
+
gs= Object.new
|
74
|
+
Logbook.store = gs
|
75
|
+
|
76
|
+
@bk = Logbook::Book.new('book-id')
|
77
|
+
stub(gs).valid?{ false }
|
78
|
+
stub(gs).error{ "test error" }
|
79
|
+
|
80
|
+
proc { @bk.all }.must_raise RuntimeError, "test error"
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logbook/cli'
|
3
|
+
|
4
|
+
|
5
|
+
def stamp
|
6
|
+
@stamp ||= DateTime.new(1981,9,8)
|
7
|
+
end
|
8
|
+
describe Logbook::CLI do
|
9
|
+
before do
|
10
|
+
FakeFS.activate!
|
11
|
+
FakeFS::FileSystem.clear
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
FakeFS.deactivate!
|
15
|
+
FakeFS::FileSystem.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should show indicate no book is set on fresh env" do
|
19
|
+
out = capture_io{ Logbook::CLI.start ['book?'] }.join ''
|
20
|
+
out.must_match /No book is set. Create one/
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it "should not add when no book" do
|
25
|
+
out = capture_io{ Logbook::CLI.start %w{ add so long, and thanks for all the fish. } }.join ''
|
26
|
+
out.must_match /No book is set./
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should create a book given nothing is set and we call book" do
|
30
|
+
any_instance_of(Logbook::CLI) do |cli|
|
31
|
+
mock(cli).yes?(anything){ true }
|
32
|
+
end
|
33
|
+
book = mock(Object).create('Robinson') { 'deadbeef' }
|
34
|
+
mock(Logbook::Book).new{ book }
|
35
|
+
|
36
|
+
out = capture_io{ Logbook::CLI.start ['book', 'Robinson'] }.join ''
|
37
|
+
|
38
|
+
out.must_match /Robinson/
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create a book given nothing is set and we call book" do
|
42
|
+
any_instance_of(Logbook::CLI) do |cli|
|
43
|
+
mock(cli).yes?(anything){ true }
|
44
|
+
end
|
45
|
+
book = mock(Object).create('Robinson') { 'deadbeef' }
|
46
|
+
mock(Logbook::Book).new{ book }
|
47
|
+
|
48
|
+
out = capture_io{ Logbook::CLI.start ['book', 'Robinson'] }.join ''
|
49
|
+
|
50
|
+
out.must_match /Robinson/
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "given errornous book" do
|
54
|
+
before do
|
55
|
+
any_instance_of(Logbook::Book) do |ins|
|
56
|
+
stub(ins).create(anything){ raise "error" }
|
57
|
+
stub(ins).add_temporal(anything){ raise "error" }
|
58
|
+
stub(ins).all{ raise "error" }
|
59
|
+
end
|
60
|
+
any_instance_of(Logbook::CLI) do |cli|
|
61
|
+
stub(cli).current_book{ Logbook::Book.new 'id' }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should error when trying to create a new book" do
|
66
|
+
any_instance_of(Logbook::CLI) do |cli|
|
67
|
+
mock(cli).yes?(anything){ true }
|
68
|
+
end
|
69
|
+
|
70
|
+
out = capture_io{ Logbook::CLI.start ['book', 'Robinson'] }.join ''
|
71
|
+
out.must_match /error/
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should error when adding" do
|
75
|
+
out = capture_io{ Logbook::CLI.start ["add","so long, and thanks for all the fish."] }.join ''
|
76
|
+
out.must_match /error/
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should error when listing" do
|
80
|
+
out = capture_io{ Logbook::CLI.start ["all"] }.join ''
|
81
|
+
out.must_match /error/
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
describe "given a book" do
|
89
|
+
before do
|
90
|
+
u = UserConfig.new(".logbook")
|
91
|
+
u['logbook.yaml'][:current_book] = "deadbeef"
|
92
|
+
u['logbook.yaml'][:books] = {
|
93
|
+
"deadbeef" => "Captain's log, stardate 3323426-0/1",
|
94
|
+
"c0debabe" => "The log"
|
95
|
+
}
|
96
|
+
u['logbook.yaml'].save
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should show current book" do
|
100
|
+
out = capture_io{ Logbook::CLI.start ['book?'] }.join ''
|
101
|
+
out.must_match /Captain's log, stardate/
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should add to book" do
|
105
|
+
book = mock(Object).add_temporal(anything) { stamp }
|
106
|
+
|
107
|
+
# thor is being a bit hard here. since it's static, and
|
108
|
+
# it won't even give pass through dispatch/invoke instance
|
109
|
+
# methods, we're going to be dirty and mock ctors :(
|
110
|
+
mock(Logbook::Book).new("deadbeef") { book }
|
111
|
+
|
112
|
+
out = capture_io{ Logbook::CLI.start ["add","so long, and thanks for all the fish."] }.join ''
|
113
|
+
out.must_match /OK, at.*1981-09-08/
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should switch a book directly given an id" do
|
117
|
+
out = capture_io{ Logbook::CLI.start ["book","c0debabe"] }.join ''
|
118
|
+
out.must_match /switched/
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should provide an option to pick a book from a menu" do
|
122
|
+
any_instance_of(Logbook::CLI) do |cli|
|
123
|
+
mock(cli).ask(anything){ "2" }
|
124
|
+
end
|
125
|
+
out = capture_io{ Logbook::CLI.start ["book"]}.join ''
|
126
|
+
|
127
|
+
lines = out.lines.to_a
|
128
|
+
lines[0].must_match /1 deadbeef Captain's log, stardate 3323426-0/
|
129
|
+
lines[1].must_match /2 c0debabe The log/
|
130
|
+
lines[2].must_match /OK, selected/
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#require 'simplecov'
|
2
|
+
#SimpleCov.start if ENV["COVERAGE"]
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
require 'rr'
|
9
|
+
require 'fakefs/safe'
|
10
|
+
require 'user_config'
|
11
|
+
|
12
|
+
|
13
|
+
class MiniTest::Unit::TestCase
|
14
|
+
include RR::Adapters::MiniTest
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_content(file)
|
18
|
+
File.read(File.expand_path("files/"+file, File.dirname(__FILE__)))
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'thor'
|
22
|
+
# This is to silence the 'task' warning for the mocks.
|
23
|
+
#
|
24
|
+
class Thor
|
25
|
+
class << self
|
26
|
+
def create_task(meth) #:nodoc:
|
27
|
+
if @usage && @desc
|
28
|
+
base_class = @hide ? Thor::HiddenTask : Thor::Task
|
29
|
+
tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
|
30
|
+
@usage, @desc, @long_desc, @method_options, @hide = nil
|
31
|
+
true
|
32
|
+
elsif self.all_tasks[meth] || meth == "method_missing"
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# UserConfig does chmod
|
42
|
+
module FakeFS::FileUtils
|
43
|
+
def chmod(f, m)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# FakeFS does not fake Kernel.open
|
48
|
+
class UserConfig::YAMLFile
|
49
|
+
def save
|
50
|
+
unless File.exist?((dir = File.dirname(path)))
|
51
|
+
FileUtils.mkdir_p(dir)
|
52
|
+
end
|
53
|
+
#replace Kernel.open with File.open
|
54
|
+
File.open(path, 'w') do |f|
|
55
|
+
YAML.dump(@cache, f)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dotan Nahum
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rr
|
16
|
+
requirement: &80608610 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *80608610
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fakefs
|
27
|
+
requirement: &80607630 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *80607630
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard-minitest
|
38
|
+
requirement: &80604680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *80604680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: user_config
|
49
|
+
requirement: &80603720 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *80603720
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: thor
|
60
|
+
requirement: &80602730 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *80602730
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chronic
|
71
|
+
requirement: &80601670 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *80601670
|
80
|
+
description: log your memories onto virtual logbooks made of Gists
|
81
|
+
email:
|
82
|
+
- jondotan@gmail.com
|
83
|
+
executables:
|
84
|
+
- lg
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- Guardfile
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- bin/lg
|
94
|
+
- lib/gist_store/cacert.pem
|
95
|
+
- lib/gist_store/gist.rb
|
96
|
+
- lib/gist_store/gist_store.rb
|
97
|
+
- lib/gist_store/net_http_ext.rb
|
98
|
+
- lib/logbook.rb
|
99
|
+
- lib/logbook/book.rb
|
100
|
+
- lib/logbook/cli.rb
|
101
|
+
- lib/logbook/version.rb
|
102
|
+
- logbook.gemspec
|
103
|
+
- spec/gist_store/gist_store_spec.rb
|
104
|
+
- spec/logbook/book_spec.rb
|
105
|
+
- spec/logbook/cli_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses: []
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project: lg
|
127
|
+
rubygems_version: 1.8.7
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: log your memories onto virtual logbooks made of Gists
|
131
|
+
test_files: []
|