configliere 0.4.14 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,15 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 1.9.2
5
- - jruby-19mode # JRuby in 1.9 mode
5
+ - jruby-19mode
6
6
  - rbx-19mode
7
+ - ruby-head
8
+ - jruby-head
9
+ # 1.8 still works! keep it that way
10
+ - jruby-18mode
11
+ - rbx-18mode
12
+ - 1.8.7
13
+ - ree
7
14
 
8
15
  bundler_args: --without docs support
9
16
 
data/Gemfile CHANGED
@@ -3,41 +3,38 @@ source 'http://rubygems.org'
3
3
  gem 'multi_json', ">= 1.1"
4
4
 
5
5
  # Only necessary if you want to use Configliere::Prompt
6
- gem 'highline', ">= 1.5.2"
7
- gem 'jruby-openssl', :platform => :jruby # if RUBY_PLATFORM =~ /java/
8
-
9
- puts [RUBY_PLATFORM, RUBY_ENGINE, RUBY_DESCRIPTION]
6
+ gem 'highline', ">= 1.5.2", :require => false
7
+ gem 'jruby-openssl', :platform => [:jruby] if RUBY_PLATFORM =~ /java/
10
8
 
11
9
  # Only gems that you want listed as development dependencies in the gemspec
12
10
  group :development do
13
11
  gem 'bundler', "~> 1.1"
14
- gem 'rake'
15
- gem 'yard', ">= 0.7"
16
- gem 'rspec', ">= 2.8"
17
- gem 'jeweler', ">= 1.6"
12
+ gem 'rake', :require => false
13
+ gem 'yard', ">= 0.7", :require => false
14
+ gem 'rspec', ">= 2.8", :require => false
15
+ gem 'jeweler', ">= 1.6", :require => false
18
16
  end
19
17
 
20
18
  group :docs do
21
- gem 'RedCloth', ">= 4.2", :require => "redcloth"
22
- gem 'redcarpet', ">= 2.1", :platform => [:mri, :rbx]
23
- gem 'kramdown', :platform => :jruby
19
+ gem 'RedCloth', ">= 4.2", :require => "redcloth"
20
+ gem 'redcarpet', ">= 2.1", :platform => [:ruby]
21
+ gem 'kramdown', :platform => [:jruby]
24
22
  end
25
23
 
26
24
  # Gems for testing and coverage
27
25
  group :test do
28
- gem 'simplecov', ">= 0.5", :platform => :ruby_19
29
- #
30
- gem 'oj', ">= 1.2", :platform => [:mri, :rbx]
31
- gem 'json', :platform => :jruby
26
+ gem 'simplecov', ">= 0.5", :platform => [:ruby_19], :require => false
27
+ gem 'json'
32
28
  end
33
29
 
34
30
  # Gems you would use if hacking on this gem (rather than with it)
35
31
  group :support do
36
32
  gem 'pry'
37
- gem 'guard', ">= 1.0"
38
- gem 'guard-rspec', ">= 0.6"
39
- gem 'guard-yard'
33
+ #
34
+ gem 'guard', ">= 1.0", :platform => [:ruby_19]
35
+ gem 'guard-rspec', ">= 0.6", :platform => [:ruby_19]
36
+ gem 'guard-yard', :platform => [:ruby_19]
40
37
  if RUBY_PLATFORM.include?('darwin')
41
- gem 'rb-fsevent', ">= 0.9"
38
+ gem 'rb-fsevent', ">= 0.9", :platform => [:ruby_19]
42
39
  end
43
40
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.14
1
+ 0.4.16
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "configliere"
8
- s.version = "0.4.14"
8
+ s.version = "0.4.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Infochimps"]
@@ -62,7 +62,6 @@ Gem::Specification.new do |s|
62
62
  "spec/configliere/commands_spec.rb",
63
63
  "spec/configliere/config_block_spec.rb",
64
64
  "spec/configliere/config_file_spec.rb",
65
- "spec/configliere/crypter_spec.rb",
66
65
  "spec/configliere/deep_hash_spec.rb",
67
66
  "spec/configliere/define_spec.rb",
68
67
  "spec/configliere/encrypted_spec.rb",
@@ -85,7 +84,6 @@ Gem::Specification.new do |s|
85
84
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
85
  s.add_runtime_dependency(%q<multi_json>, [">= 1.1"])
87
86
  s.add_runtime_dependency(%q<highline>, [">= 1.5.2"])
88
- s.add_runtime_dependency(%q<jruby-openssl>, [">= 0"])
89
87
  s.add_development_dependency(%q<bundler>, ["~> 1.1"])
90
88
  s.add_development_dependency(%q<rake>, [">= 0"])
91
89
  s.add_development_dependency(%q<yard>, [">= 0.7"])
@@ -94,7 +92,6 @@ Gem::Specification.new do |s|
94
92
  else
95
93
  s.add_dependency(%q<multi_json>, [">= 1.1"])
96
94
  s.add_dependency(%q<highline>, [">= 1.5.2"])
97
- s.add_dependency(%q<jruby-openssl>, [">= 0"])
98
95
  s.add_dependency(%q<bundler>, ["~> 1.1"])
99
96
  s.add_dependency(%q<rake>, [">= 0"])
100
97
  s.add_dependency(%q<yard>, [">= 0.7"])
@@ -104,7 +101,6 @@ Gem::Specification.new do |s|
104
101
  else
105
102
  s.add_dependency(%q<multi_json>, [">= 1.1"])
106
103
  s.add_dependency(%q<highline>, [">= 1.5.2"])
107
- s.add_dependency(%q<jruby-openssl>, [">= 0"])
108
104
  s.add_dependency(%q<bundler>, ["~> 1.1"])
109
105
  s.add_dependency(%q<rake>, [">= 0"])
110
106
  s.add_dependency(%q<yard>, [">= 0.7"])
@@ -42,7 +42,7 @@ module Configliere
42
42
  if command_name && commands[command_name]
43
43
  sub_config = commands[command_name][:config]
44
44
  adoptable = sub_config.send(:definitions).keys
45
- merge!(sub_config.select{|k,v| adoptable.include?(k) } )
45
+ merge!( Hash[sub_config.select{|k,v| adoptable.include?(k) }] )
46
46
  end
47
47
  self
48
48
  end
@@ -3,9 +3,9 @@ require 'pathname'
3
3
  module Configliere
4
4
  # Default locations where config files live
5
5
  DEFAULT_CONFIG_LOCATION = {
6
- machine: ->(scope){ Pathname('/etc').join(scope) },
7
- user: ->(scope){ Pathname(ENV['HOME'] || '/').join(".#{scope}") },
8
- app: ->(scope){ app_dir = Pathname('/') ; Pathname(Dir.pwd).ascend{ |path| app_dir = path.join('config') if path.join('config').exist? } ; app_dir }
6
+ :machine => lambda{|scope| Pathname('/etc').join(scope) },
7
+ :user => lambda{|scope| Pathname(ENV['HOME'] || '/').join(".#{scope}") },
8
+ :app => lambda{|scope| app_dir = Pathname('/') ; Pathname(Dir.pwd).ascend{ |path| app_dir = path.join('config') if path.join('config').exist? } ; app_dir }
9
9
  } unless defined?(DEFAULT_CONFIG_LOCATION)
10
10
 
11
11
  #
@@ -1,6 +1,16 @@
1
1
  module Configliere
2
2
  # for encryption
3
- require 'openssl'
3
+
4
+ begin
5
+ require 'openssl'
6
+ PLATFORM_ENCRYPTION_ERROR = nil
7
+ rescue LoadError => err
8
+ raise unless err.to_s.include?('openssl')
9
+ warn "Your ruby doesn't appear to have been built with OpenSSL."
10
+ warn "So you don't get to have Encryption."
11
+ PLATFORM_ENCRYPTION_ERROR = err
12
+ end
13
+
4
14
  require 'digest/sha2'
5
15
  # base64-encode the binary encrypted string
6
16
  require "base64"
@@ -11,6 +21,11 @@ module Configliere
11
21
  module Crypter
12
22
  CIPHER_TYPE = "aes-256-cbc" unless defined?(CIPHER_TYPE)
13
23
 
24
+ def self.check_platform_can_encrypt!
25
+ return true unless PLATFORM_ENCRYPTION_ERROR
26
+ raise PLATFORM_ENCRYPTION_ERROR.class, "Encryption broken on this platform: #{PLATFORM_ENCRYPTION_ERROR}"
27
+ end
28
+
14
29
  #
15
30
  # Encrypt the given string
16
31
  #
@@ -51,6 +66,7 @@ module Configliere
51
66
  # @param [String] encrypt_pass secret passphrase to decrypt with
52
67
  #
53
68
  def self.new_cipher direction, encrypt_pass, options={}
69
+ check_platform_can_encrypt!
54
70
  cipher = OpenSSL::Cipher::Cipher.new(CIPHER_TYPE)
55
71
  case direction when :encrypt then cipher.encrypt when :decrypt then cipher.decrypt else raise "Bad cipher direction #{direction}" end
56
72
  cipher.key = encrypt_key(encrypt_pass, options)
@@ -59,7 +75,9 @@ module Configliere
59
75
 
60
76
  # prepend the initialization vector to the encoded message
61
77
  def self.combine_iv_and_ciphertext iv, message
62
- iv.force_encoding("BINARY") + message.force_encoding("BINARY")
78
+ message.force_encoding("BINARY") if message.respond_to?(:force_encoding)
79
+ iv.force_encoding("BINARY") if iv.respond_to?(:force_encoding)
80
+ iv + message
63
81
  end
64
82
  # pull the initialization vector from the front of the encoded message
65
83
  def self.separate_iv_and_ciphertext cipher, iv_and_ciphertext
@@ -131,7 +131,7 @@ module Configliere
131
131
  when ((val.to_s == 'now') && (type == DateTime)) then val = DateTime.now
132
132
  when ((val.to_s == 'now') && (type == Time)) then val = Time.now
133
133
  when [Date, Time, DateTime].include?(type) then val = type.parse(val) rescue nil
134
- else warn("Unknown type #{type} given") # nothing
134
+ else raise ArgumentError, "Unknown type #{type} given"
135
135
  end
136
136
  self[param] = val
137
137
  end
@@ -1,7 +1,15 @@
1
1
  # Settings.use :prompt
2
2
  # you must install the highline gem
3
3
 
4
- require 'highline/import'
4
+ begin
5
+ require 'highline/import'
6
+ rescue LoadError, NameError => err
7
+ warn "************"
8
+ warn "Highline does not work with JRuby 1.7.0+ as of Mid 2012. See https://github.com/JEG2/highline/issues/41."
9
+ warn "************"
10
+ raise
11
+ end
12
+
5
13
  module Configliere
6
14
  #
7
15
  # Method to prompt for
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe "Configliere::Commandline" do
4
4
  before do
@@ -163,8 +163,8 @@ describe "Configliere::Commandline" do
163
163
  @config.define :dest_time, :type => DateTime, :description => "Arrival time", :required => true
164
164
  @config.define :takes_opt, :flag => 't', :description => "Takes a single-letter flag '-t'"
165
165
  @config.define :foobaz, :internal => true, :description => "You won't see me"
166
- @config.define 'delorean.power_source', :env_var => 'POWER_SOURCE', :description => 'Delorean subsytem supplying power to the Flux Capacitor.'
167
166
  @config.define :password, :required => true, :encrypted => true
167
+ @config.define 'delorean.power_source', :env_var => 'POWER_SOURCE', :description => 'Delorean subsytem supplying power to the Flux Capacitor.'
168
168
  @config.description = 'This is a sample script to demonstrate the help message. Notice how pretty everything lines up YAY'
169
169
 
170
170
  stderr_output = capture_help_message{ @config.resolve! }
@@ -1,14 +1,14 @@
1
- require 'spec_helper'
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
  require 'configliere/commands'
3
3
 
4
4
  describe Configliere::Commands do
5
-
5
+
6
6
  subject{ Configliere::Param.new.use(:commands) }
7
7
 
8
8
  after{ ::ARGV.replace [] }
9
9
 
10
10
  context 'when no commands are defined' do
11
-
11
+
12
12
  its(:commands){ should be_empty }
13
13
 
14
14
  let(:args) { %w[ not_command_but_arg another_arg ] }
@@ -35,14 +35,14 @@ describe Configliere::Commands do
35
35
  let(:args) { %w[ the_command --fuzziness=wuzzy extra_arg ] }
36
36
 
37
37
  before do
38
- subject.defaults(fuzziness: 'smooth')
39
- subject.define_command(:the_command, description: 'foobar')
38
+ subject.defaults(:fuzziness => 'smooth')
39
+ subject.define_command(:the_command, :description => 'foobar')
40
40
  end
41
41
 
42
42
  it "should continue to parse flags when the command is given" do
43
43
  ::ARGV.replace args
44
44
  subject.resolve!
45
- subject.should == { fuzziness: 'wuzzy' }
45
+ subject.should == { :fuzziness => 'wuzzy' }
46
46
  end
47
47
 
48
48
  it "should continue to set args when the command is given" do
@@ -90,23 +90,11 @@ describe Configliere::Commands do
90
90
  end
91
91
  end
92
92
 
93
- def capture_help_message
94
- stderr_output = ''
95
- subject.should_receive(:warn){|str| stderr_output << str }
96
- begin
97
- yield
98
- fail('should exit via system exit')
99
- rescue SystemExit
100
- true # pass
101
- end
102
- stderr_output
103
- end
104
-
105
93
  describe "the help message" do
106
94
  before do
107
95
  subject.define_command :run, :description => "forrest"
108
96
  subject.define_command :stop, :description => "hammertime"
109
- subject.define :reel, :type => Integer
97
+ subject.define :reel, :type => Integer
110
98
  end
111
99
 
112
100
  it "displays a modified usage" do
@@ -115,7 +103,7 @@ describe Configliere::Commands do
115
103
  stderr_output.should =~ %r{usage:.*\[command\]}m
116
104
  end
117
105
 
118
- it "displays the commands and their descriptions" do
106
+ it "displays the commands and their descriptions", :if => (RUBY_VERSION < "2.0") do
119
107
  ::ARGV.replace ['--help']
120
108
  stderr_output = capture_help_message{ subject.resolve! }
121
109
  stderr_output.should =~ %r{Available commands:\s+run\s*forrest\s+stop\s+hammertime}m
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
  Configliere.use :config_block
3
3
 
4
4
  describe "Configliere::ConfigBlock" do
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Configliere::ConfigFile do
4
- let(:default_params) { { my_param: 'default_val', also_a_param: true } }
4
+ let(:default_params) { { :my_param => 'default_val', :also_a_param => true } }
5
5
 
6
6
  subject{ Configliere::Param.new default_params }
7
7
 
@@ -10,7 +10,7 @@ describe Configliere::ConfigFile do
10
10
  end
11
11
 
12
12
  context '#read' do
13
- let(:file_params) { { my_param: 'val_from_file' } }
13
+ let(:file_params) { { :my_param => 'val_from_file' } }
14
14
  let(:file_string) { file_params.to_yaml }
15
15
  let(:file_path) { '/absolute/path.yaml' }
16
16
 
@@ -85,26 +85,26 @@ describe Configliere::ConfigFile do
85
85
  end
86
86
 
87
87
  context 'with options' do
88
- let(:file_params) { { development: { reload: true }, production: { reload: false } } }
88
+ let(:file_params) { { :development => { :reload => true }, :production => { :reload => false } } }
89
89
 
90
- before{ subject.merge!(reload: 'whatever') }
90
+ before{ subject.merge!(:reload => 'whatever') }
91
91
 
92
92
  context ':env key' do
93
93
  context 'valid :env' do
94
- let(:opts) { { env: :development } }
94
+ let(:opts) { { :env => :development } }
95
95
 
96
96
  it 'slices out a subhash given by :env' do
97
97
  subject.read(file_path, opts)
98
- subject.should == default_params.merge(reload: true)
98
+ subject.should == default_params.merge(:reload => true)
99
99
  end
100
100
  end
101
101
 
102
102
  context 'invalid :env' do
103
- let(:opts) { { env: :not_there } }
103
+ let(:opts) { { :env => :not_there } }
104
104
 
105
105
  it 'has no effect if the key given by :env option is absent' do
106
106
  subject.read(file_path, opts)
107
- subject.should == default_params.merge(reload: 'whatever')
107
+ subject.should == default_params.merge(:reload => 'whatever')
108
108
  end
109
109
  end
110
110
  end
@@ -114,7 +114,7 @@ describe Configliere::ConfigFile do
114
114
 
115
115
  it 'does no slicing without the :env option' do
116
116
  subject.read(file_path, opts)
117
- subject.should == default_params.merge(reload: 'whatever').merge(file_params)
117
+ subject.should == default_params.merge(:reload => 'whatever').merge(file_params)
118
118
  end
119
119
  end
120
120
  end
@@ -101,13 +101,7 @@ describe DeepHash do
101
101
  subject['moon.non'].should be_nil
102
102
  subject.should == orig_hash # shouldn't change from reading (specifically, shouldn't autovivify)
103
103
  end
104
- it 'indexing through a non-hash will raise an error' do
105
- begin ; p subject['hat'] ; rescue StandardError => err ; p [err, err.class] ; end
106
- begin ; p subject['hat.dog'] ; rescue StandardError => err ; p [err, err.class] ; end
107
- begin ; p subject['hat']['dog'] ; rescue StandardError => err ; p [err, err.class] ; end
108
- begin ; p :happy_sym['dog'] ; rescue StandardError => err ; p [err, err.class] ; end
109
- end
110
- it 'indexing through a non-hash will raise an error' do
104
+ it 'indexing through a non-hash will raise an error', :if => (defined?(RUBY_ENGINE) && (RUBY_ENGINE !~ /rbx/)) do
111
105
  err_klass = (RUBY_VERSION >= "1.9.0") ? TypeError : NoMethodError
112
106
  expect{ subject['hat.dog'] }.to raise_error(err_klass, /Symbol/)
113
107
  subject.should == orig_hash # shouldn't change from reading (specifically, shouldn't autovivify)
@@ -92,13 +92,19 @@ describe "Configliere::Define" do
92
92
  [Array, 'alone', ['alone'] ],
93
93
  [Array, '', [] ],
94
94
  [Array, nil, nil ],
95
- ['other', '5', '5'], ['other', 5, 5], ['other', nil, nil], ['other', '', nil],
96
95
  ].each do |type, orig, desired|
97
96
  it "for #{type} converts #{orig.inspect} to #{desired.inspect}" do
98
97
  @config.define :has_type, :type => type
99
98
  @config[:has_type] = orig ; @config.resolve! ; @config[:has_type].should == desired
100
99
  end
101
100
  end
101
+
102
+ it 'raises an error (FIXME: on resolve, which is not that great) if you define an unknown type' do
103
+ @config.define :has_type, :type => 'bogus, man'
104
+ @config[:has_type] = "WHOA" ;
105
+ expect{ @config.resolve! }.to raise_error(ArgumentError, /Unknown type.*bogus, man/)
106
+ end
107
+
102
108
  it 'converts :now to the current moment' do
103
109
  @config.define :has_type, :type => DateTime
104
110
  @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now)
@@ -1,6 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Configliere::Encrypted" do
3
+ module Configliere ; module Crypter ; CIPHER_TYPE = 'aes-128-cbc' ; end ; end
4
+
5
+ describe "Configliere::Encrypted", :if => check_openssl do
6
+ require 'configliere/crypter'
7
+
4
8
  before do
5
9
  @config = Configliere::Param.new :secret => 'encrypt_me', :normal_param => 'normal'
6
10
  @config.use :encrypted
@@ -8,6 +12,34 @@ describe "Configliere::Encrypted" do
8
12
  @config[:encrypt_pass] = 'pass'
9
13
  end
10
14
 
15
+ if Configliere::Crypter::CIPHER_TYPE == 'aes-256-cbc'
16
+ let(:encrypted_str){ "KohCTcXr1aAulopntmZ8f5Gqa7PzsBmz+R2vFGYrAeg=\n" }
17
+ let(:encrypted_foo_val){ "cc+Bp5jMUBHFCvPNZIfleeatB4IGaaXjVINl12HOpcs=\n" }
18
+ elsif Configliere::Crypter::CIPHER_TYPE == 'aes-128-cbc'
19
+ let(:encrypted_str){ "mHse6HRTANh8JpIfIuyANQ8b2rXAf0+/3pzQnYsd8LE=\n" }
20
+ let(:encrypted_foo_val){ "cc+Bp5jMUBHFCvPNZIfleZYRoDmLK1LSxPkAMemhDTQ=\n" }
21
+ else
22
+ warn "Can't make test strings for #{Configliere::Crypter::CIPHER_TYPE} cipher"
23
+ end
24
+ let(:foo_val_iv){ Base64.decode64(encrypted_foo_val)[0..15] }
25
+
26
+
27
+ describe "Crypter" do
28
+ it "encrypts" do
29
+ # Force the same initialization vector as used to prepare the test value
30
+ @cipher = Configliere::Crypter.send(:new_cipher, :encrypt, 'sekrit')
31
+ Configliere::Crypter.should_receive(:new_cipher).and_return(@cipher)
32
+ @cipher.should_receive(:random_iv).and_return foo_val_iv
33
+ # OK so do the test now.
34
+ Configliere::Crypter.encrypt('foo_val', 'sekrit').should == encrypted_foo_val
35
+ end
36
+
37
+ it "decrypts" do
38
+ Configliere::Crypter.decrypt(encrypted_foo_val, 'sekrit').should == 'foo_val'
39
+ end
40
+ end
41
+
42
+
11
43
  describe 'defines encrypted params' do
12
44
  it 'with :encrypted => true' do
13
45
  @config.send(:encrypted_params).should include(:secret)
@@ -63,18 +95,16 @@ describe "Configliere::Encrypted" do
63
95
  end
64
96
 
65
97
  describe 'loading a file' do
66
- before do
67
- @encrypted_str = "KohCTcXr1aAulopntmZ8f5Gqa7PzsBmz+R2vFGYrAeg=\n"
68
- end
69
98
  it 'encrypts' do
70
- Configliere::Crypter.should_receive(:encrypt).and_return(@encrypted_str)
99
+ Configliere::Crypter.should_receive(:encrypt).and_return(encrypted_str)
71
100
  FileUtils.stub(:mkdir_p)
72
101
  File.should_receive(:open).and_yield([])
73
- YAML.should_receive(:dump).with({ :normal_param => "normal", :encrypted_secret => @encrypted_str })
102
+ YAML.should_receive(:dump).with({ :normal_param => "normal", :encrypted_secret => encrypted_str })
74
103
  @config.save! '/fake/file'
75
104
  end
76
105
  it 'decrypts' do
77
- @hsh = { :loaded_param => "loaded", :encrypted_secret => @encrypted_str }
106
+ # encrypted_str = Configliere::Crypter.encrypt('decrypt_me', 'pass')
107
+ @hsh = { :loaded_param => "loaded", :encrypted_secret => encrypted_str }
78
108
  File.stub(:open)
79
109
  YAML.should_receive(:load).and_return(@hsh)
80
110
  @config.read 'file.yaml'
@@ -1,6 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Configliere::Prompt" do
3
+ # Highline does not work with JRuby 1.7.0+ as of Mid 2012. See https://github.com/JEG2/highline/issues/41.
4
+
5
+ describe "Configliere::Prompt", :if => load_sketchy_lib('highline/import') do
4
6
  before do
5
7
  @config = Configliere::Param.new
6
8
  @config.use :prompt
@@ -45,5 +47,4 @@ describe "Configliere::Prompt" do
45
47
  Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
46
48
  end
47
49
  end
48
-
49
50
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe "Configliere" do
4
4
  it 'creates a global variable Settings, for universality' do
@@ -1,6 +1,8 @@
1
1
  require 'bundler/setup' ; Bundler.require(:default, :development, :test)
2
2
  require 'rspec/autorun'
3
3
 
4
+ puts "Running specs in version #{RUBY_VERSION} on #{RUBY_PLATFORM} #{RUBY_DESCRIPTION}"
5
+
4
6
  if ENV['CONFIGLIERE_COV']
5
7
  require 'simplecov'
6
8
  SimpleCov.start
@@ -8,6 +10,51 @@ end
8
10
 
9
11
  RSpec.configure do |config|
10
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
13
+
14
+ def load_sketchy_lib(lib)
15
+ begin
16
+ require lib
17
+ yield if block_given?
18
+ return true
19
+ rescue LoadError, StandardError => err
20
+ warn "#{RUBY_DESCRIPTION} doesn't seem to like #{lib}: got error"
21
+ warn " #{err.class} #{err}"
22
+ warn "Skipping specs on '#{caller(2).first}'"
23
+ return false
24
+ end
25
+ end
26
+
27
+ def capture_help_message
28
+ stderr_output = ''
29
+ subject.should_receive(:warn){|str| stderr_output << str }
30
+ begin
31
+ yield
32
+ fail('should exit via system exit')
33
+ rescue SystemExit
34
+ true # pass
35
+ end
36
+ stderr_output
37
+ end
38
+
39
+ def check_openssl
40
+ load_sketchy_lib('openssl') do
41
+ cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
42
+ cipher.encrypt
43
+ cipher.key = Digest::SHA256.digest("HI JRUBY")
44
+ cipher.iv = iv = cipher.random_iv
45
+ ciphertext = cipher.update("O HAI TO YOU!")
46
+ ciphertext << cipher.final
47
+ # p [__LINE__, '128-bit encryption is OK', ciphertext]
48
+ # cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
49
+ # cipher.encrypt
50
+ # cipher.key = Digest::SHA256.digest("HI JRUBY")
51
+ # cipher.iv = iv = cipher.random_iv
52
+ # ciphertext = cipher.update("O HAI TO YOU!")
53
+ # ciphertext << cipher.final
54
+ # p [__LINE__, '256-bit encryption is OK', ciphertext]
55
+ end
56
+ end
57
+
11
58
  end
12
59
 
13
60
  require 'configliere'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configliere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14
4
+ version: 0.4.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 1.5.2
46
- - !ruby/object:Gem::Dependency
47
- name: jruby-openssl
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: bundler
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +185,6 @@ files:
201
185
  - spec/configliere/commands_spec.rb
202
186
  - spec/configliere/config_block_spec.rb
203
187
  - spec/configliere/config_file_spec.rb
204
- - spec/configliere/crypter_spec.rb
205
188
  - spec/configliere/deep_hash_spec.rb
206
189
  - spec/configliere/define_spec.rb
207
190
  - spec/configliere/encrypted_spec.rb
@@ -226,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
209
  version: '0'
227
210
  segments:
228
211
  - 0
229
- hash: 1408788613005433508
212
+ hash: 3171401032843387046
230
213
  required_rubygems_version: !ruby/object:Gem::Requirement
231
214
  none: false
232
215
  requirements:
@@ -1,19 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'configliere/crypter'
3
- include Configliere
4
-
5
- describe "Crypter" do
6
- ENCRYPTED_FOO_VAL = "cc+Bp5jMUBHFCvPNZIfleeatB4IGaaXjVINl12HOpcs=\n".force_encoding("BINARY")
7
- FOO_VAL_IV = Base64.decode64(ENCRYPTED_FOO_VAL)[0..15]
8
- it "encrypts" do
9
- # Force the same initialization vector as used to prepare the test value
10
- @cipher = Crypter.send(:new_cipher, :encrypt, 'sekrit')
11
- Crypter.should_receive(:new_cipher).and_return(@cipher)
12
- @cipher.should_receive(:random_iv).and_return FOO_VAL_IV
13
- # OK so do the test now.
14
- Crypter.encrypt('foo_val', 'sekrit').should == ENCRYPTED_FOO_VAL
15
- end
16
- it "decrypts" do
17
- Crypter.decrypt(ENCRYPTED_FOO_VAL, 'sekrit').should == 'foo_val'
18
- end
19
- end