Skip to content

Commit 5bdda7c

Browse files
committed
Add tests for command options.
--date, --layout, --type options were mostly untested
1 parent 6df5e9b commit 5bdda7c

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

spec/draft_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
expect(drafts_dir).to exist
4141
end
4242

43+
it 'creates the draft with a specified extension' do
44+
html_path = drafts_dir.join 'a-test-post.html'
45+
expect(html_path).not_to exist
46+
capture_stdout { described_class.process(args, 'type' => 'html') }
47+
expect(html_path).to exist
48+
end
49+
50+
it 'creates a new draft with the specified layout' do
51+
capture_stdout { described_class.process(args, 'layout' => 'other-layout') }
52+
expect(File.read(path)).to match(/layout: other-layout/)
53+
end
54+
4355
context 'when the draft already exists' do
4456
let(:name) { 'An existing draft' }
4557
let(:path) { drafts_dir.join('an-existing-draft.md') }

spec/page_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
expect(path).to exist
2020
end
2121

22+
it 'creates a new page with the specified type' do
23+
html_path = Pathname.new(source_dir).join 'a-test-page.html'
24+
FileUtils.rm html_path if File.exist? html_path
25+
capture_stdout { described_class.process(args, 'type' => 'html') }
26+
expect(html_path).to exist
27+
end
28+
29+
it 'creates a new page with the specified layout' do
30+
capture_stdout { described_class.process(args, 'layout' => 'other-layout') }
31+
expect(File.read(path)).to match(/layout: other-layout/)
32+
end
33+
2234
it 'should write a helpful message when successful' do
2335
output = capture_stdout { described_class.process(args) }
2436
expect(output).to eql("New page created at #{filename}.\n")

spec/post_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
let(:name) { 'A test post' }
33
let(:args) { [name] }
44
let(:posts_dir) { Pathname.new source_dir('_posts') }
5-
let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-a-test-post.md" }
5+
let(:datestamp) { Time.now.strftime('%Y-%m-%d') }
6+
let(:filename) { "#{datestamp}-a-test-post.md" }
67
let(:path) { posts_dir.join(filename) }
78

89
before(:all) do
@@ -31,6 +32,18 @@
3132
expect(path).to exist
3233
end
3334

35+
it 'creates the post with a specified extension' do
36+
html_path = posts_dir.join "#{datestamp}-a-test-post.html"
37+
expect(html_path).not_to exist
38+
capture_stdout { described_class.process(args, 'type' => 'html') }
39+
expect(html_path).to exist
40+
end
41+
42+
it 'creates a new post with the specified layout' do
43+
capture_stdout { described_class.process(args, 'layout' => 'other-layout') }
44+
expect(File.read(path)).to match(/layout: other-layout/)
45+
end
46+
3447
it 'should write a helpful message when successful' do
3548
output = capture_stdout { described_class.process(args) }
3649
expect(output).to eql("New post created at _posts/#{filename}.\n")

spec/publish_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
RSpec.describe(Jekyll::Commands::Publish) do
22
let(:drafts_dir) { source_dir('_drafts') }
33
let(:posts_dir) { source_dir('_posts') }
4-
let(:draft_to_publish) { 'a-test-post.markdown' }
5-
let(:post_filename) { "#{Time.now.strftime('%Y-%m-%d')}-#{draft_to_publish}" }
4+
let(:draft_to_publish) { 'a-test-post.md' }
5+
let(:datestamp) { Time.now.strftime('%Y-%m-%d') }
6+
let(:post_filename) { "#{datestamp}-#{draft_to_publish}" }
67
let(:args) { ["_drafts/#{draft_to_publish}"] }
78

89
let(:draft_path) { Pathname.new(File.join(drafts_dir, draft_to_publish)) }
@@ -38,6 +39,12 @@
3839
output = capture_stdout { described_class.process(args) }
3940
expect(output).to eql("Draft _drafts/#{draft_to_publish} was published to _posts/#{post_filename}\n")
4041
end
42+
43+
it 'publishes a draft on the specified date' do
44+
path = Pathname.new(posts_dir).join "2012-03-04-a-test-post.md"
45+
capture_stdout { described_class.process(args, {"date" => '2012-3-4'}) }
46+
expect(path).to exist
47+
end
4148

4249
it 'creates the posts folder if necessary' do
4350
FileUtils.rm_r posts_dir if File.directory? posts_dir

0 commit comments

Comments
 (0)