Skip to content

Commit

Permalink
Test support for collections_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Oct 9, 2018
1 parent c166884 commit f4e8655
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
32 changes: 29 additions & 3 deletions spec/draft_spec.rb
Expand Up @@ -79,12 +79,15 @@
context "when a configuration file exists" do
let(:config) { source_dir("_config.yml") }
let(:drafts_dir) { Pathname.new source_dir(File.join("site", "_drafts")) }
let(:config_data) do
%(
source: site
)
end

before(:each) do
File.open(config, "w") do |f|
f.write(%(
source: site
))
f.write(config_data)
end
end

Expand All @@ -97,6 +100,29 @@
capture_stdout { described_class.process(args) }
expect(path).to exist
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:drafts_dir) { Pathname.new source_dir("site", collections_dir, "_drafts") }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should create drafts at the correct location" do
expect(path).not_to exist
capture_stdout { described_class.process(args) }
expect(path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
generated_path = File.join("site", collections_dir, "_drafts", "a-test-post.md").cyan
expect(output).to include("New draft created at #{generated_path}")
end
end
end

context "when source option is set" do
Expand Down
23 changes: 23 additions & 0 deletions spec/post_spec.rb
Expand Up @@ -150,6 +150,29 @@
end
end
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:posts_dir) { Pathname.new source_dir("site", collections_dir, "_posts") }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should create posts at the correct location" do
expect(path).not_to exist
capture_stdout { described_class.process(args) }
expect(path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
generated_path = File.join("site", collections_dir, "_posts", filename).cyan
expect(output).to include("New post created at #{generated_path}")
end
end
end

context "when source option is set" do
Expand Down
13 changes: 6 additions & 7 deletions spec/publish_spec.rb
Expand Up @@ -102,14 +102,15 @@
let(:config) { source_dir("_config.yml") }
let(:drafts_dir) { Pathname.new source_dir("site", "_drafts") }
let(:posts_dir) { Pathname.new source_dir("site", "_posts") }

let(:args) { ["site/_drafts/#{draft_to_publish}"] }
let(:config_data) do
%(
source: site
)
end

before(:each) do
File.open(config, "w") do |f|
f.write(%(
source: site
))
f.write(config_data)
end
end

Expand All @@ -129,8 +130,6 @@
let(:drafts_dir) { Pathname.new source_dir("site", "_drafts") }
let(:posts_dir) { Pathname.new source_dir("site", "_posts") }

let(:args) { ["site/_drafts/#{draft_to_publish}"] }

it "should use source directory set by command line option" do
expect(post_path).not_to exist
expect(draft_path).to exist
Expand Down
39 changes: 32 additions & 7 deletions spec/unpublish_spec.rb
Expand Up @@ -87,14 +87,15 @@
let(:config) { source_dir("_config.yml") }
let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) }

let(:args) { ["site/_posts/#{post_filename}"] }
let(:config_data) do
%(
source: site
)
end

before(:each) do
File.open(config, "w") do |f|
f.write(%(
source: site
))
f.write(config_data)
end
end

Expand All @@ -109,14 +110,38 @@
expect(post_path).not_to exist
expect(draft_path).to exist
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:drafts_dir) { Pathname.new(source_dir("site", collections_dir, "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", collections_dir, "_posts")) }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should move posts to the correct location" do
expect(post_path).to exist
expect(draft_path).not_to exist
capture_stdout { described_class.process(args) }
expect(draft_path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
post_filepath = File.join("site", collections_dir, "_posts", post_filename)
draft_filepath = File.join("site", collections_dir, "_drafts", post_name)
expect(output).to include("Post #{post_filepath} was moved to #{draft_filepath}")
end
end
end

context "when source option is set" do
let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) }

let(:args) { ["site/_posts/#{post_filename}"] }

it "should use source directory set by command line option" do
expect(post_path).to exist
expect(draft_path).not_to exist
Expand Down

0 comments on commit f4e8655

Please sign in to comment.