Rubocop fixes for test/test_new_command.rb
This commit is contained in:
parent
ad98883843
commit
c76b458dd5
|
|
@ -76,7 +76,6 @@ AllCops:
|
||||||
- test/test_filters.rb
|
- test/test_filters.rb
|
||||||
- test/test_kramdown.rb
|
- test/test_kramdown.rb
|
||||||
- test/test_liquid_renderer.rb
|
- test/test_liquid_renderer.rb
|
||||||
- test/test_new_command.rb
|
|
||||||
- test/test_page.rb
|
- test/test_page.rb
|
||||||
- test/test_path_sanitization.rb
|
- test/test_path_sanitization.rb
|
||||||
- test/test_plugin_manager.rb
|
- test/test_plugin_manager.rb
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
require 'jekyll/commands/new'
|
require "jekyll/commands/new"
|
||||||
|
|
||||||
class TestNewCommand < JekyllUnitTest
|
class TestNewCommand < JekyllUnitTest
|
||||||
def dir_contents(path)
|
def dir_contents(path)
|
||||||
Dir["#{path}/**/*"].each do |file|
|
Dir["#{path}/**/*"].each do |file|
|
||||||
file.gsub! path, ''
|
file.gsub! path, ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -12,9 +12,9 @@ class TestNewCommand < JekyllUnitTest
|
||||||
File.expand_path("../lib/site_template", File.dirname(__FILE__))
|
File.expand_path("../lib/site_template", File.dirname(__FILE__))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when args contains a path' do
|
context "when args contains a path" do
|
||||||
setup do
|
setup do
|
||||||
@path = 'new-site'
|
@path = "new-site"
|
||||||
@args = [@path]
|
@args = [@path]
|
||||||
@full_path = File.expand_path(@path, Dir.pwd)
|
@full_path = File.expand_path(@path, Dir.pwd)
|
||||||
end
|
end
|
||||||
|
|
@ -23,7 +23,7 @@ class TestNewCommand < JekyllUnitTest
|
||||||
FileUtils.rm_r @full_path
|
FileUtils.rm_r @full_path
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'create a new directory' do
|
should "create a new directory" do
|
||||||
refute_exist @full_path
|
refute_exist @full_path
|
||||||
Jekyll::Commands::New.process(@args)
|
Jekyll::Commands::New.process(@args)
|
||||||
assert_exist @full_path
|
assert_exist @full_path
|
||||||
|
|
@ -34,43 +34,43 @@ class TestNewCommand < JekyllUnitTest
|
||||||
refute_exist @full_path
|
refute_exist @full_path
|
||||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||||
assert_exist gemfile
|
assert_exist gemfile
|
||||||
assert_match /gem "jekyll", "#{Jekyll::VERSION}"/, File.read(gemfile)
|
assert_match(/gem "jekyll", "#{Jekyll::VERSION}"/, File.read(gemfile))
|
||||||
assert_match /gem "github-pages"/, File.read(gemfile)
|
assert_match(/gem "github-pages"/, File.read(gemfile))
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'display a success message' do
|
should "display a success message" do
|
||||||
Jekyll::Commands::New.process(@args)
|
Jekyll::Commands::New.process(@args)
|
||||||
output = Jekyll.logger.messages.last
|
output = Jekyll.logger.messages.last
|
||||||
success_message = "New jekyll site installed in #{@full_path}."
|
success_message = "New jekyll site installed in #{@full_path}."
|
||||||
assert_includes output, success_message
|
assert_includes output, success_message
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'copy the static files in site template to the new directory' do
|
should "copy the static files in site template to the new directory" do
|
||||||
static_template_files = dir_contents(site_template).reject do |f|
|
static_template_files = dir_contents(site_template).reject do |f|
|
||||||
File.extname(f) == '.erb'
|
File.extname(f) == ".erb"
|
||||||
end
|
end
|
||||||
static_template_files << "/Gemfile"
|
static_template_files << "/Gemfile"
|
||||||
|
|
||||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||||
|
|
||||||
new_site_files = dir_contents(@full_path).reject do |f|
|
new_site_files = dir_contents(@full_path).reject do |f|
|
||||||
File.extname(f) == '.markdown'
|
File.extname(f) == ".markdown"
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_same_elements static_template_files, new_site_files
|
assert_same_elements static_template_files, new_site_files
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'process any ERB files' do
|
should "process any ERB files" do
|
||||||
erb_template_files = dir_contents(site_template).select do |f|
|
erb_template_files = dir_contents(site_template).select do |f|
|
||||||
File.extname(f) == '.erb'
|
File.extname(f) == ".erb"
|
||||||
end
|
end
|
||||||
|
|
||||||
stubbed_date = '2013-01-01'
|
stubbed_date = "2013-01-01"
|
||||||
allow_any_instance_of(Time).to receive(:strftime) { stubbed_date }
|
allow_any_instance_of(Time).to receive(:strftime) { stubbed_date }
|
||||||
|
|
||||||
erb_template_files.each do |f|
|
erb_template_files.each do |f|
|
||||||
f.chomp! '.erb'
|
f.chomp! ".erb"
|
||||||
f.gsub! '0000-00-00', stubbed_date
|
f.gsub! "0000-00-00", stubbed_date
|
||||||
end
|
end
|
||||||
|
|
||||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||||
|
|
@ -82,22 +82,22 @@ class TestNewCommand < JekyllUnitTest
|
||||||
assert_same_elements erb_template_files, new_site_files
|
assert_same_elements erb_template_files, new_site_files
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'create blank project' do
|
should "create blank project" do
|
||||||
blank_contents = %w(/_drafts /_layouts /_posts /index.html)
|
blank_contents = %w(/_drafts /_layouts /_posts /index.html)
|
||||||
capture_stdout { Jekyll::Commands::New.process(@args, '--blank') }
|
capture_stdout { Jekyll::Commands::New.process(@args, "--blank") }
|
||||||
assert_same_elements blank_contents, dir_contents(@full_path)
|
assert_same_elements blank_contents, dir_contents(@full_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'force created folder' do
|
should "force created folder" do
|
||||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||||
output = capture_stdout { Jekyll::Commands::New.process(@args, '--force') }
|
output = capture_stdout { Jekyll::Commands::New.process(@args, "--force") }
|
||||||
assert_match(/New jekyll site installed in/, output)
|
assert_match(/New jekyll site installed in/, output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when multiple args are given' do
|
context "when multiple args are given" do
|
||||||
setup do
|
setup do
|
||||||
@site_name_with_spaces = 'new site name'
|
@site_name_with_spaces = "new site name"
|
||||||
@multiple_args = @site_name_with_spaces.split
|
@multiple_args = @site_name_with_spaces.split
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -105,23 +105,23 @@ class TestNewCommand < JekyllUnitTest
|
||||||
FileUtils.rm_r File.expand_path(@site_name_with_spaces, Dir.pwd)
|
FileUtils.rm_r File.expand_path(@site_name_with_spaces, Dir.pwd)
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'create a new directory' do
|
should "create a new directory" do
|
||||||
refute_exist @site_name_with_spaces
|
refute_exist @site_name_with_spaces
|
||||||
capture_stdout { Jekyll::Commands::New.process(@multiple_args) }
|
capture_stdout { Jekyll::Commands::New.process(@multiple_args) }
|
||||||
assert_exist @site_name_with_spaces
|
assert_exist @site_name_with_spaces
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when no args are given' do
|
context "when no args are given" do
|
||||||
setup do
|
setup do
|
||||||
@empty_args = []
|
@empty_args = []
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'raise an ArgumentError' do
|
should "raise an ArgumentError" do
|
||||||
exception = assert_raises ArgumentError do
|
exception = assert_raises ArgumentError do
|
||||||
Jekyll::Commands::New.process(@empty_args)
|
Jekyll::Commands::New.process(@empty_args)
|
||||||
end
|
end
|
||||||
assert_equal 'You must specify a path.', exception.message
|
assert_equal "You must specify a path.", exception.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue