Skip to content

Commit

Permalink
Merge 76b022e into 6412917
Browse files Browse the repository at this point in the history
  • Loading branch information
garriguv committed Sep 22, 2015
2 parents 6412917 + 76b022e commit 8b0f3a0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/flip_the_switch/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def self.defaults
end

public
class_option :input, type: :string, aliases: '-i', default: defaults[:input], desc: 'Location of the directory containing features.yml file to read'
class_option :input, type: :string, aliases: '-i', default: defaults[:input], desc: 'Filename or directory containing features.yml file to read'
class_option :environment, type: :string, aliases: '-n', default: defaults[:environment], desc: 'Name of environment to read from in features.yml file'

desc 'plist', 'Auto-generates a Features.plist file for enabled/disabled features'
method_option :output, type: :string, aliases: '-o', default: defaults[:plist_output], desc: 'Location of the directory in which Features.plist file will be created'
method_option :output, type: :string, aliases: '-o', default: defaults[:plist_output], desc: 'Filename or directory in which Features.plist file will be created'

def plist
plist_generator.generate
Expand Down
6 changes: 5 additions & 1 deletion lib/flip_the_switch/generator/plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def feature_hash(feature)
end

def output_file
File.join(output, 'Features.plist')
if File.directory?(output)
File.join(output, 'Features.plist')
else
output
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/flip_the_switch/reader/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def file_states
end

def input_file
File.join(input, 'features.yml')
if File.directory?(input)
File.join(input, 'features.yml')
else
input
end
end
end
end
Expand Down
20 changes: 16 additions & 4 deletions spec/flip_the_switch/generator/plist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe FlipTheSwitch::Generator::Plist do
subject(:plist) { described_class.new(output, features) }
let(:output) { 'tmp' }
let(:features) { [
FlipTheSwitch::Feature.new('enabled_feature', true, nil),
FlipTheSwitch::Feature.new('disabled_feature', false, 'is disabled description')
Expand All @@ -15,9 +14,22 @@
File.delete(output_file) if File.exists?(output_file)
end

it 'writes a Features.plist file with the enabled features set' do
subject.generate
shared_examples "a plist writer" do |output, output_file|
let(:output) { output }
let(:output_file) { output_file }

expect(actual_output_file).to eql(expected_plist_file)
it "writes a #{File.basename(output_file)} file with the features set" do
subject.generate

expect(File.read(output_file)).to eql(expected_plist_file)
end
end

context 'When the output is a directory' do
it_behaves_like "a plist writer", 'spec/resources', 'spec/resources/Features.plist'
end

context 'when the output is a file' do
it_behaves_like "a plist writer", 'spec/resources/DasPlist.plist', 'spec/resources/DasPlist.plist'
end
end
39 changes: 37 additions & 2 deletions spec/flip_the_switch/reader/features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
subject(:reader) { described_class.new(input, environment) }
let(:environment) { 'beta' }

context 'when given a real file' do
context 'when input is a directory containing a valid features.yml file' do
let(:input) { 'spec/resources/real' }

context 'when given an valid environment' do
context 'when given adirectory containing features.yml as input' do
it 'reads the enabled/disabled states of the features for the environment' do
expect(subject.features).to eql([
FlipTheSwitch::Feature.new('enabled_feature', true, 'This feature is enabled', [
Expand All @@ -29,6 +29,41 @@
end
end

context 'when input is a valid file' do
let(:input) { 'spec/resources/real/features.yml' }

context 'when given adirectory containing features.yml as input' do
it 'reads the enabled/disabled states of the features for the environment' do
expect(subject.features).to eql([
FlipTheSwitch::Feature.new('enabled_feature', true, 'This feature is enabled', [
FlipTheSwitch::Feature.new('sub_feature', false)
]),
FlipTheSwitch::Feature.new('disabled_feature', false)
])
end
end

context 'when given an invalid environment' do
let(:environment) { 'invalid' }

specify do
expect {
subject.features
}.to raise_error(FlipTheSwitch::Error::InvalidEnvironment)
end
end
end

context 'when input is an invalid file' do
let(:input) { 'spec/resources/invalid_type/features.yml' }

specify do
expect {
subject.features
}.to raise_error(FlipTheSwitch::Error::InvalidFile)
end
end

context 'when given a non-existent file' do
let(:input) { 'spec/resources/non-existent' }

Expand Down

0 comments on commit 8b0f3a0

Please sign in to comment.