|
87 | 87 | let(:config) { source_dir("_config.yml") } |
88 | 88 | let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) } |
89 | 89 | let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) } |
90 | | - |
91 | | - let(:args) { ["site/_posts/#{post_filename}"] } |
| 90 | + let(:config_data) do |
| 91 | + %( |
| 92 | + source: site |
| 93 | + ) |
| 94 | + end |
92 | 95 |
|
93 | 96 | before(:each) do |
94 | 97 | File.open(config, "w") do |f| |
95 | | - f.write(%( |
96 | | -source: site |
97 | | -)) |
| 98 | + f.write(config_data) |
98 | 99 | end |
99 | 100 | end |
100 | 101 |
|
|
109 | 110 | expect(post_path).not_to exist |
110 | 111 | expect(draft_path).to exist |
111 | 112 | end |
| 113 | + |
| 114 | + context "and collections_dir is set" do |
| 115 | + let(:collections_dir) { "my_collections" } |
| 116 | + let(:drafts_dir) { Pathname.new(source_dir("site", collections_dir, "_drafts")) } |
| 117 | + let(:posts_dir) { Pathname.new(source_dir("site", collections_dir, "_posts")) } |
| 118 | + let(:config_data) do |
| 119 | + %( |
| 120 | + source: site |
| 121 | + collections_dir: #{collections_dir} |
| 122 | + ) |
| 123 | + end |
| 124 | + |
| 125 | + it "should move posts to the correct location" do |
| 126 | + expect(post_path).to exist |
| 127 | + expect(draft_path).not_to exist |
| 128 | + capture_stdout { described_class.process(args) } |
| 129 | + expect(draft_path).to exist |
| 130 | + end |
| 131 | + |
| 132 | + it "should write a helpful message when successful" do |
| 133 | + output = capture_stdout { described_class.process(args) } |
| 134 | + post_filepath = File.join("site", collections_dir, "_posts", post_filename) |
| 135 | + draft_filepath = File.join("site", collections_dir, "_drafts", post_name) |
| 136 | + expect(output).to include("Post #{post_filepath} was moved to #{draft_filepath}") |
| 137 | + end |
| 138 | + end |
112 | 139 | end |
113 | 140 |
|
114 | 141 | context "when source option is set" do |
115 | 142 | let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) } |
116 | 143 | let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) } |
117 | 144 |
|
118 | | - let(:args) { ["site/_posts/#{post_filename}"] } |
119 | | - |
120 | 145 | it "should use source directory set by command line option" do |
121 | 146 | expect(post_path).to exist |
122 | 147 | expect(draft_path).not_to exist |
|
0 commit comments