-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.rb
146 lines (114 loc) · 4.2 KB
/
spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
require 'rspec'
require 'open3'
require 'tmpdir'
def blogctl(args, stdin: "")
go_args = "ci-build/blogctl.test -test.run '^Test_'"\
" -test.coverprofile=coverage/#{rand 0..10_000}.out"
Open3.capture3({'TEST_ARGS' => args}, go_args, :stdin_data => stdin)
end
describe 'CLI' do
context 'Trivial test cases' do
it 'shows a version' do
out, err, _ = blogctl("--version")
expect(err).to eq ""
expect(out).to match(/BuildVersion:/)
expect(out).to match(/BuildDate:/)
end
it 'shows general help without any args' do
out,err,_ = blogctl("")
expect(err).to eq ""
expect(out).to include 'Blogctl manages blog markdown-based posts'\
' database-less and generates a static website on-demand'
expect(out).to include 'Usage'
expect(out).to include 'Available Commands'
expect(out).to include 'Use "blogctl [command] --help" for more information about a command.'
end
it 'shows post help without any subcommand' do
out,err,_ = blogctl("post")
expect(err).to eq ""
expect(out).to include("Manage posts")
expect(out).to include 'Usage'
expect(out).to include 'Available Commands'
expect(out).to include 'Use "blogctl post [command] --help" for more information about a command.'
end
end
context 'Basic test cases' do
let (:blog_path) { "/tmp/blog#{rand 0..10_0000}" }
after(:each) do
FileUtils.rm_rf(blog_path)
end
it 'initializes a new blog' do
_, err, _ = blogctl("init")
expect(err).to eq ""
expect(File.exist?("blog")).to be_truthy
ensure
FileUtils.rm_rf("blog")
end
it 'initializes a new blog with custom path' do
_, err, _ = blogctl("init -p #{blog_path}")
expect(err).to eq ""
expect(File.exist?(blog_path)).to be_truthy
end
it 'fails to initializes a blog twice' do
out,_,_ = blogctl("init -p #{blog_path}")
expect(out).not_to match(/Blog environment already exists/)
expect(File.exist?(blog_path)).to be_truthy
out, _, _ = blogctl("init -p #{blog_path}")
expect(out).to match(/Blog environment already exists/)
end
end
context 'Post test cases' do
let (:blog_path) { "/tmp/blog#{rand 0..10_0000}" }
before(:each) do
blogctl("init -p #{blog_path}")
end
after(:each) do
FileUtils.rm_rf(blog_path)
end
it 'fails to add a post without title' do
out, _, _ = blogctl("post add -p #{blog_path}")
expect(out).to match(/Title missing/)
end
it 'adds a post' do
out, _, _ = blogctl("post add --title 'test' -p #{blog_path}")
expect(out).to include "#{blog_path}/test/content.md"
end
it 'updates a post' do
blogctl("post add --title test -p #{blog_path}")
appendix = "I use RSpec to test my blog"
blogctl(
"post update --slug test -p #{blog_path} -a",
stdin: appendix
)
expect(File.read("#{blog_path}/test/content.md"))
.to include(appendix)
end
it 'lists zero posts' do
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^| CREATION DATE | STATUS | STATIC | TITLE |$/)
end
it 'lists one post' do
blogctl("post add --title test -p #{blog_path}")
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^.*|\s*draft\s*|\s*test\s*$/)
end
it 'publishs a post' do
blogctl("post add --title test -p #{blog_path}")
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^.*|\s*draft\s*|\s*test\s*$/)
blogctl("post publish -p #{blog_path} --slug test")
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^.*|\s*public\s*|\s*test\s*$/)
end
it 'drafts a post again' do
blogctl("post add --title test -p #{blog_path}")
out, _, _ = blogctl("list -p #{blog_path}")
blogctl("post publish -p #{blog_path} --slug test")
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^.*|\s*public\s*|\s*test\s*$/)
blogctl("post draft -p #{blog_path} --slug test")
out, _, _ = blogctl("list -p #{blog_path}")
expect(out).to match(/^.*|\s*draft\s*|\s*test\s*$/)
end
end
end