|
1 | 1 | RSpec.describe(Jekyll::Commands::Publish) do |
2 | | - let(:drafts_dir) { source_dir('_drafts') } |
3 | | - let(:posts_dir) { source_dir('_posts') } |
| 2 | + let(:drafts_dir) { Pathname.new source_dir('_drafts') } |
| 3 | + let(:posts_dir) { Pathname.new source_dir('_posts') } |
4 | 4 | let(:draft_to_publish) { 'a-test-post.md' } |
5 | 5 | let(:datestamp) { Time.now.strftime('%Y-%m-%d') } |
6 | 6 | let(:post_filename) { "#{datestamp}-#{draft_to_publish}" } |
7 | 7 | let(:args) { ["_drafts/#{draft_to_publish}"] } |
8 | 8 |
|
9 | | - let(:draft_path) { Pathname.new(File.join(drafts_dir, draft_to_publish)) } |
10 | | - let(:post_path) { Pathname.new(File.join(posts_dir, post_filename))} |
| 9 | + let(:draft_path) { drafts_dir.join draft_to_publish } |
| 10 | + let(:post_path) { posts_dir.join post_filename } |
11 | 11 |
|
12 | 12 | before(:all) do |
13 | 13 | FileUtils.mkdir_p source_dir unless File.directory? source_dir |
|
28 | 28 | end |
29 | 29 |
|
30 | 30 | it 'publishes a draft post' do |
31 | | - expect(Pathname.new(post_path)).not_to exist |
32 | | - expect(Pathname.new(draft_path)).to exist |
| 31 | + expect(post_path).not_to exist |
| 32 | + expect(draft_path).to exist |
33 | 33 | capture_stdout { described_class.process(args) } |
34 | | - expect(Pathname.new(post_path)).to exist |
| 34 | + expect(post_path).to exist |
| 35 | + end |
| 36 | + |
| 37 | + it 'publishes with a specified date' do |
| 38 | + path = posts_dir.join "2012-03-04-#{draft_to_publish}" |
| 39 | + expect(path).not_to exist |
| 40 | + capture_stdout { described_class.process(args, {'date'=>'2012-3-4'}) } |
| 41 | + expect(path).to exist |
35 | 42 | end |
36 | 43 |
|
37 | 44 | it 'writes a helpful message on success' do |
38 | | - expect(Pathname.new(draft_path)).to exist |
| 45 | + expect(draft_path).to exist |
39 | 46 | output = capture_stdout { described_class.process(args) } |
40 | | - expect(output).to eql("Draft _drafts/#{draft_to_publish} was published to _posts/#{post_filename}\n") |
| 47 | + expect(output).to eql("Draft _drafts/#{draft_to_publish} was moved to _posts/#{post_filename}\n") |
41 | 48 | end |
42 | 49 |
|
43 | 50 | it 'publishes a draft on the specified date' do |
44 | | - path = Pathname.new(posts_dir).join "2012-03-04-a-test-post.md" |
| 51 | + path = posts_dir.join "2012-03-04-a-test-post.md" |
45 | 52 | capture_stdout { described_class.process(args, {"date" => '2012-3-4'}) } |
46 | 53 | expect(path).to exist |
47 | 54 | end |
48 | 55 |
|
49 | 56 | it 'creates the posts folder if necessary' do |
50 | 57 | FileUtils.rm_r posts_dir if File.directory? posts_dir |
51 | 58 | capture_stdout { described_class.process(args) } |
52 | | - expect(Pathname.new(posts_dir)).to exist |
| 59 | + expect(posts_dir).to exist |
53 | 60 | end |
54 | 61 |
|
55 | 62 | it 'errors if there is no argument' do |
|
0 commit comments