-
Notifications
You must be signed in to change notification settings - Fork 83
Rewrite tests #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ lib/bundler/man | |
| pkg | ||
| rdoc | ||
| spec/reports | ||
| spec/source | ||
| test/tmp | ||
| test/version_tmp | ||
| tmp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| language: ruby | ||
| rvm: | ||
| - 2.2 | ||
| - 2.1 | ||
| - 2.0 | ||
| script: script/cibuild | ||
| sudo: false | ||
| cache: bundler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1 @@ | ||
| require "bundler/gem_tasks" | ||
| require 'rake/testtask' | ||
| Rake::TestTask.new(:test) do |test| | ||
| test.libs << 'lib' << 'test' | ||
| test.pattern = 'test/**/test_*.rb' | ||
| test.verbose = true | ||
| end | ||
|
|
||
| task :default => :test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require "jekyll-compose/version" | ||
|
|
||
| module Jekyll | ||
| module Compose | ||
| end | ||
| end | ||
|
|
||
| %w{draft post publish}.each do |file| | ||
| require File.expand_path("jekyll/commands/#{file}.rb", File.dirname(__FILE__)) | ||
| end |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| bundle install --jobs=8 --retry=3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| script/test --format progress $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/bash | ||
| bundle exec rspec --color --require spec_helper $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| RSpec.describe(Jekyll::Commands::Draft) do | ||
| let(:name) { 'A test post' } | ||
| let(:args) { [name] } | ||
| let(:drafts_dir) { Pathname.new source_dir('_drafts') } | ||
| let(:path) { drafts_dir.join('a-test-post.markdown') } | ||
|
|
||
| before(:all) do | ||
| FileUtils.mkdir_p source_dir unless File.directory? source_dir | ||
| Dir.chdir source_dir | ||
| end | ||
|
|
||
| before(:each) do | ||
| FileUtils.mkdir_p drafts_dir unless File.directory? drafts_dir | ||
| end | ||
|
|
||
| after(:each) do | ||
| FileUtils.rm_r drafts_dir if File.directory? drafts_dir | ||
| end | ||
|
|
||
| it 'creates a new draft' do | ||
| expect(path).not_to exist | ||
| capture_stdout { described_class.process(args) } | ||
| expect(path).to exist | ||
| end | ||
|
|
||
| it 'writes a helpful success message' do | ||
| output = capture_stdout { described_class.process(args) } | ||
| expect(output).to eql("New draft created at ./_drafts/a-test-post.markdown.\n") | ||
| end | ||
|
|
||
| it 'errors with no arguments' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process } | ||
| }).to raise_error('You must specify a name.') | ||
| end | ||
|
|
||
| context 'when the draft already exists' do | ||
| let(:name) { 'An existing draft' } | ||
| let(:path) { drafts_dir.join('an-existing-draft.markdown') } | ||
|
|
||
| before(:each) do | ||
| FileUtils.touch path | ||
| end | ||
|
|
||
| it 'raises an error' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process(args) } | ||
| }).to raise_error("A draft already exists at ./_drafts/an-existing-draft.markdown") | ||
| end | ||
|
|
||
| it 'overwrites if --force is given' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process(args, 'force' => true) } | ||
| }).not_to raise_error | ||
| expect(File.read(path)).to match(/layout: post/) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| RSpec.describe(Jekyll::Commands::Post) do | ||
| let(:name) { 'A test post' } | ||
| let(:args) { [name] } | ||
| let(:posts_dir) { Pathname.new source_dir('_posts') } | ||
| let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-a-test-post.markdown" } | ||
| let(:path) { posts_dir.join(filename) } | ||
|
|
||
| before(:all) do | ||
| FileUtils.mkdir_p source_dir unless File.directory? source_dir | ||
| Dir.chdir source_dir | ||
| end | ||
|
|
||
| before(:each) do | ||
| FileUtils.mkdir_p posts_dir unless File.directory? posts_dir | ||
| end | ||
|
|
||
| after(:each) do | ||
| FileUtils.rm_r posts_dir if File.directory? posts_dir | ||
| end | ||
|
|
||
| it 'creates a new post' 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) } | ||
| expect(output).to eql("New post created at ./_posts/#{filename}.\n") | ||
| end | ||
|
|
||
| it 'errors with no arguments' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process } | ||
| }).to raise_error('You must specify a name.') | ||
| end | ||
|
|
||
| context 'when the post already exists' do | ||
| let(:name) { 'An existing post' } | ||
| let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-an-existing-post.markdown" } | ||
|
|
||
| before(:each) do | ||
| FileUtils.touch path | ||
| end | ||
|
|
||
| it 'raises an error' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process(args) } | ||
| }).to raise_error("A post already exists at ./_posts/#{filename}") | ||
| end | ||
|
|
||
| it 'overwrites if --force is given' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process(args, 'force' => true) } | ||
| }).not_to raise_error | ||
| expect(File.read(path)).to match(/layout: post/) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| RSpec.describe(Jekyll::Commands::Publish) do | ||
| let(:drafts_dir) { source_dir('_drafts') } | ||
| let(:posts_dir) { source_dir('_posts') } | ||
| let(:draft_to_publish) { 'a-test-post.markdown' } | ||
| let(:post_filename) { "#{Time.now.strftime('%Y-%m-%d')}-#{draft_to_publish}" } | ||
| let(:args) { ["_drafts/#{draft_to_publish}"] } | ||
|
|
||
| let(:draft_path) { Pathname.new(File.join(drafts_dir, draft_to_publish)) } | ||
| let(:post_path) { Pathname.new(File.join(posts_dir, post_filename))} | ||
|
|
||
| before(:all) do | ||
| FileUtils.mkdir_p source_dir unless File.directory? source_dir | ||
| Dir.chdir source_dir | ||
| end | ||
|
|
||
| before(:each) do | ||
| FileUtils.mkdir_p drafts_dir unless File.directory? drafts_dir | ||
| FileUtils.mkdir_p posts_dir unless File.directory? posts_dir | ||
| FileUtils.touch draft_path | ||
| end | ||
|
|
||
| after(:each) do | ||
| FileUtils.rm_r drafts_dir if File.directory? drafts_dir | ||
| FileUtils.rm_r posts_dir if File.directory? posts_dir | ||
| FileUtils.rm_r draft_path if File.file? draft_path | ||
| FileUtils.rm_r post_path if File.file? post_path | ||
| end | ||
|
|
||
| it 'publishes a draft post' do | ||
| expect(Pathname.new(post_path)).not_to exist | ||
| expect(Pathname.new(draft_path)).to exist | ||
| capture_stdout { described_class.process(args) } | ||
| expect(Pathname.new(post_path)).to exist | ||
| end | ||
|
|
||
| it 'writes a helpful message on success' do | ||
| expect(Pathname.new(draft_path)).to exist | ||
| output = capture_stdout { described_class.process(args) } | ||
| expect(output).to eql("Draft _drafts/#{draft_to_publish} was published to ./_posts/#{post_filename}\n") | ||
| end | ||
|
|
||
| it 'errors if there is no argument' do | ||
| expect(-> { | ||
| capture_stdout { described_class.process } | ||
| }).to raise_error('You must specify a draft path.') | ||
| end | ||
|
|
||
| it 'errors if no file exists at given path' do | ||
| weird_path = '_drafts/i-do-not-exist.markdown' | ||
| expect(-> { | ||
| capture_stdout { described_class.process [weird_path] } | ||
| }).to raise_error("There was no draft found at '_drafts/i-do-not-exist.markdown'.") | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| require 'jekyll' | ||
| require File.expand_path('../../lib/jekyll-compose.rb', __FILE__) | ||
|
|
||
| RSpec.configure do |config| | ||
| config.expect_with :rspec do |expectations| | ||
| expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
| end | ||
| config.mock_with :rspec do |mocks| | ||
| mocks.verify_partial_doubles = true | ||
| end | ||
|
|
||
| config.filter_run :focus | ||
| config.run_all_when_everything_filtered = true | ||
|
|
||
| config.disable_monkey_patching! | ||
|
|
||
| config.warnings = true | ||
|
|
||
| if config.files_to_run.one? | ||
| config.default_formatter = 'doc' | ||
| end | ||
|
|
||
| config.profile_examples = 3 | ||
|
|
||
| config.order = :random | ||
|
|
||
| Kernel.srand config.seed | ||
|
|
||
| ### | ||
| ### Helper methods | ||
| ### | ||
| TEST_DIR = File.expand_path('../', __FILE__) | ||
| def test_dir(*files) | ||
| File.expand_path(File.join(TEST_DIR, *files)) | ||
| end | ||
|
|
||
| def source_dir(*files) | ||
| test_dir('source', *files) | ||
| end | ||
|
|
||
| def fixture_site | ||
| Jekyll::Site.new(Jekyll::Utils.deep_merge_hashes( | ||
| Jekyll::Configuration::DEFAULTS, | ||
| { 'source' => source_dir, 'destination' => test_dir('dest') } | ||
| )) | ||
| end | ||
|
|
||
| def capture_stdout | ||
| $old_stdout = $stdout | ||
| $stdout = StringIO.new | ||
| yield | ||
| $stdout.rewind | ||
| return $stdout.string | ||
| ensure | ||
| $stdout = $old_stdout | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider: