Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
154 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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,11 @@ | ||
module Nanoc | ||
# @api private | ||
module Feature | ||
TRUES = %w(y yes 1 t true).freeze | ||
|
||
def self.enabled?(name) | ||
env_name = "NANOC_FEATURE_#{name.upcase}" | ||
TRUES.include?(ENV.fetch(env_name, 'f').downcase) | ||
end | ||
end | ||
end |
This file contains 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 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 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 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,29 @@ | ||
describe Nanoc::Feature do | ||
describe '.enabled?' do | ||
subject { described_class.enabled?(feature_name) } | ||
|
||
let(:feature_name) { 'magic' } | ||
|
||
context 'disabled' do | ||
context 'not set' do | ||
it { is_expected.not_to be } | ||
end | ||
|
||
%w(0 n N no No NO false False fAlSe FALSE donkey).each do |val| | ||
context "set to #{val}" do | ||
before { ENV['NANOC_FEATURE_MAGIC'] = val } | ||
it { is_expected.not_to be } | ||
end | ||
end | ||
end | ||
|
||
context 'enabled' do | ||
%w(1 y Y yes yEs YES t True tRuE TRUE).each do |val| | ||
context "set to #{val}" do | ||
before { ENV['NANOC_FEATURE_MAGIC'] = val } | ||
it { is_expected.to be } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,64 @@ | ||
describe Nanoc::CLI::Commands::Compile::Listener do | ||
let(:klass) do | ||
Class.new(described_class) do | ||
attr_reader :started | ||
attr_reader :stopped | ||
|
||
def initialize | ||
@started = false | ||
@stopped = false | ||
end | ||
|
||
def start | ||
@started = true | ||
end | ||
|
||
def stop | ||
@stopped = true | ||
end | ||
end | ||
end | ||
|
||
subject { klass.new } | ||
|
||
it 'starts' do | ||
subject.start | ||
expect(subject.started).to be | ||
end | ||
|
||
it 'stops' do | ||
subject.start | ||
subject.stop | ||
expect(subject.stopped).to be | ||
end | ||
|
||
it 'starts safely' do | ||
subject.start_safely | ||
expect(subject.started).to be | ||
end | ||
|
||
it 'stops safely' do | ||
subject.start_safely | ||
subject.stop_safely | ||
expect(subject.stopped).to be | ||
end | ||
|
||
context 'listener that does not start or stop properly' do | ||
let(:klass) do | ||
Class.new(described_class) do | ||
def start | ||
raise 'boom' | ||
end | ||
|
||
def stop | ||
raise 'boom' | ||
end | ||
end | ||
end | ||
|
||
it 'raises on start, but not stop' do | ||
expect { subject.start_safely }.to raise_error(RuntimeError) | ||
expect { subject.stop_safely }.not_to raise_error | ||
end | ||
end | ||
end |