Commit d45186c8 authored by Youhei SASAKI's avatar Youhei SASAKI

Imported Upstream version 1.3.0

parent 0ccf6d11
--color
--require spec_helper
## 1.3.0 / 2015-09-23
* Lock to Listen 3.x (#25)
## 1.2.1 / 2015-01-24
* Show regen time & use the same `Site` object across regens (#21)
......
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
task default: :spec
......@@ -2,7 +2,7 @@
Gem::Specification.new do |spec|
spec.name = "jekyll-watch"
spec.version = "1.2.1"
spec.version = "1.3.0"
spec.authors = ["Parker Moore"]
spec.email = ["parkrmoore@gmail.com"]
spec.summary = %q{Rebuild your Jekyll site when a file changes with the `--watch` switch.}
......@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_runtime_dependency "listen", "~> 2.7"
spec.add_runtime_dependency "listen", "~> 3.0"
require 'rbconfig'
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
......@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "jekyll", "~> 2.0"
spec.add_development_dependency "jekyll", ">= 2.0"
end
require 'listen'
module Jekyll
module Watcher
extend self
......@@ -16,14 +18,14 @@ module Jekyll
exit 0
end
loop { sleep 1000 }
sleep_forever
end
rescue ThreadError => e
# You pressed Ctrl-C, oh my!
end
# TODO: shouldn't be public API
def build_listener(site, options)
require 'listen'
Listen.to(
options['source'],
:ignore => listen_ignore_paths(options),
......@@ -93,5 +95,8 @@ module Jekyll
end.compact + [/\.jekyll\-metadata/]
end
def sleep_forever
loop { sleep 1000 }
end
end
end
#!/bin/bash
bundle exec rspec --color --require spec_helper "$@"
bundle exec rspec "$@"
......@@ -71,11 +71,4 @@ RSpec.configure do |config|
def dest_dir(*files)
source_dir('_site', *files)
end
def site_from_options(options)
Jekyll::Site.new(Jekyll::Utils.deep_merge_hashes(
Jekyll::Configuration::DEFAULTS,
options
))
end
end
......@@ -7,37 +7,58 @@ describe(Jekyll::Watcher) do
'destination' => dest_dir
}
end
let(:options) { base_opts }
let(:site) { site_from_options(options) }
let(:site) { instance_double(Jekyll::Site) }
let(:default_ignored) { [/_config\.yml/, /_site/, /\.jekyll\-metadata/] }
subject { described_class }
before(:each) do
FileUtils.mkdir(options['destination']) if options['destination']
end
after(:each) do
FileUtils.rm_rf(options['destination']) if options['destination']
end
context "#build_listener" do
let(:listener) { subject.build_listener(site, options) }
describe "#watch" do
let(:listener) { instance_double(Listen::Listener) }
let(:opts) { { ignore: default_ignored, force_polling: options['force_polling'] } }
before do
allow(Listen).to receive(:to).with(options['source'], opts).and_return(listener)
allow(listener).to receive(:start)
allow(Jekyll::Site).to receive(:new).with(options).and_return(site)
allow(Jekyll.logger).to receive(:info)
allow(subject).to receive(:sleep_forever)
subject.watch(options)
end
it 'starts the listener' do
expect(listener).to have_received(:start)
end
it "returns a Listen::Listener" do
expect(listener).to be_a(Listen::Listener)
it 'sleeps' do
expect(subject).to have_received(:sleep_forever)
end
it "ignores the config and site by default" do
expect(listener.options[:ignore]).to eql(default_ignored)
expect(Listen).to have_received(:to).with(anything, hash_including(ignore: default_ignored))
end
it "defaults to no force_polling" do
expect(listener.options[:force_polling]).to be(nil)
expect(Listen).to have_received(:to).with(anything, hash_including(force_polling: nil))
end
context "with force_polling turned on" do
let(:options) { base_opts.merge('force_polling' => true) }
it "respects the custom value of force_polling" do
expect(listener.options[:force_polling]).to be(true)
expect(Listen).to have_received(:to).with(anything, hash_including(force_polling: true))
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment