rconf 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rconf CHANGED
@@ -158,6 +158,7 @@ where [options] are:
158
158
  begin
159
159
  lang = Language.load(options[:config])
160
160
  report_fatal("Validation of configuration file failed:\n -#{lang.validation_errors.join("\n -").map(&:red)}") unless lang.validation_errors.empty?
161
+ report_error(lang.warnings.join(', ').green) unless lang.warnings.empty?
161
162
  aborted = false
162
163
  Dir.chdir(File.dirname(options[:config])) do
163
164
  lang.configurators.each do |c|
@@ -32,7 +32,7 @@ module RightConf
32
32
  #
33
33
  # === Return
34
34
  # true:: Always return true
35
- def run
35
+ def run_linux
36
36
  if only_if.nil? || instance_eval(only_if)
37
37
  message("Building #{path}") if message.nil?
38
38
  report_check message
@@ -51,6 +51,15 @@ module RightConf
51
51
  end
52
52
  true
53
53
  end
54
+ alias :run_darwin :run_linux
55
+
56
+ # Run command line on Windows
57
+ #
58
+ # === Return
59
+ # true:: Always return true
60
+ def run_windows
61
+ true # TBD
62
+ end
54
63
 
55
64
  protected
56
65
 
@@ -33,7 +33,7 @@ module RightConf
33
33
  #
34
34
  # === Return
35
35
  # true:: Always return true
36
- def run
36
+ def run_linux
37
37
  install_path(default_install_path) if install_path.nil?
38
38
  abort_on_failure(false) if abort_on_failure.nil?
39
39
  unless cassandra_installed
@@ -53,6 +53,7 @@ module RightConf
53
53
  report_success
54
54
  end
55
55
  end
56
+ alias :run_darwin :run_linux
56
57
 
57
58
  # Install Windows software
58
59
  #
@@ -30,7 +30,7 @@ module RightConf
30
30
  #
31
31
  # === Return
32
32
  # true:: Always return true
33
- def run
33
+ def run_linux
34
34
  report_check message if message
35
35
  args = command_line.split(' ')
36
36
  args += [ { :abort_on_failure => abort_on_failure } ] if abort_on_failure
@@ -38,6 +38,15 @@ module RightConf
38
38
  report_success if message
39
39
  true
40
40
  end
41
+ alias :run_darwin :run_linux
42
+
43
+ # Run command line on Windows
44
+ #
45
+ # === Return
46
+ # true:: Always return true
47
+ def run_windows
48
+ true # TBD
49
+ end
41
50
 
42
51
  end
43
52
  end
@@ -29,7 +29,7 @@ module RightConf
29
29
  #
30
30
  # === Return
31
31
  # true:: Always return true
32
- def run
32
+ def run_linux
33
33
  if File.exist?(path)
34
34
  unless File.exist?(File.join(path, '.git'))
35
35
  FileUtils.mv(path, "#{path}_old")
@@ -52,6 +52,16 @@ module RightConf
52
52
  end
53
53
  true
54
54
  end
55
+ alias :run_darwin :run_linux
56
+
57
+ # Clone git repo and run build commands if given on Windows
58
+ #
59
+ # === Return
60
+ # true:: Always return true
61
+ def run_windows
62
+ true # TBD
63
+ end
64
+
55
65
 
56
66
  end
57
67
  end
@@ -20,6 +20,9 @@ module RightConf
20
20
  # Errors generated by configurators validations if any
21
21
  attr_reader :validation_errors
22
22
 
23
+ # Warnings
24
+ attr_reader :warnings
25
+
23
26
  # Load given file and run content to retrieve configurators
24
27
  #
25
28
  # === Parameters
@@ -56,6 +59,7 @@ module RightConf
56
59
  def initialize
57
60
  @configurators = Array.new
58
61
  @validation_errors = Array.new
62
+ @warnings = Array.new
59
63
  end
60
64
 
61
65
  # Each missing method should correspond to a configurator section.
@@ -79,7 +83,7 @@ module RightConf
79
83
  @validation_errors << error if error
80
84
  @configurators << configurator
81
85
  else
82
- @validation_errors << "Unknown configurator '#{meth}'"
86
+ @warnings << "Unknown configurator '#{meth}'"
83
87
  end
84
88
  else
85
89
  @validation_errors << "Invalid syntax, expecting block after '#{meth}'"
@@ -22,7 +22,7 @@ module RightConf
22
22
  def self.included(base)
23
23
  @@reporters ||= []
24
24
  [ :report_section, :report, :report_check, :report_success,
25
- :report_failure, :report_fatal, :report_result ].each do |meth|
25
+ :report_failure, :report_error, :report_fatal, :report_result ].each do |meth|
26
26
  meta_def(meth) { |*args| @@reporters.each { |r| r.__send__(meth, *args) } }
27
27
  end
28
28
  end
data/lib/rconf/version.rb CHANGED
@@ -13,7 +13,7 @@ module RightConf
13
13
 
14
14
  MAJOR = 0
15
15
  MINOR = 7
16
- BUILD = 8
16
+ BUILD = 9
17
17
 
18
18
  VERSION = [MAJOR, MINOR, BUILD].map(&:to_s).join('.')
19
19
 
@@ -14,12 +14,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
14
14
  describe RightConf::BuildConfigurator do
15
15
 
16
16
  before(:each) do
17
- lang = RightConf::Language.parse('build { path "../source" }')
18
- @configurator = lang.configurators.first
19
- [:report_check, :report_result, :report_success].each do |meth|
20
- flexmock(@configurator).should_receive(meth)
21
- end
22
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
17
+ @configurator = create_configurator('build { path "../source" }')
23
18
  end
24
19
 
25
20
  it 'should build' do
@@ -18,12 +18,7 @@ describe RightConf::BundlerConfigurator do
18
18
  end
19
19
 
20
20
  before(:each) do
21
- lang = RightConf::Language.parse('bundler { version "0" }')
22
- @configurator = lang.configurators.first
23
- [:report_check, :report_result, :report_success].each do |meth|
24
- flexmock(@configurator).should_receive(meth)
25
- end
26
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
21
+ @configurator = create_configurator('bundler { version "0" }')
27
22
  RightConf::Command.instance.instance_variable_set(:@rvm_prefix, 'r@g')
28
23
  end
29
24
 
@@ -14,33 +14,30 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
14
14
  describe RightConf::GitRepoConfigurator do
15
15
 
16
16
  before(:each) do
17
- lang = RightConf::Language.parse('git_repo { repo "git"; path "./git" }')
18
- @configurator = lang.configurators.first
19
- [:report_check, :report_result, :report_success].each do |meth|
20
- flexmock(@configurator).should_receive(meth)
21
- end
22
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
17
+ @configurator = create_configurator('git_repo { repo "git"; path "./git" }')
23
18
  @abf = { :abort_on_failure => 'Failed to clone git into ./git' }
24
19
  end
25
20
 
26
21
  it 'should clone' do
22
+ flexmock(File).should_receive(:exist?).with('./git').and_return(false)
27
23
  should_execute('git', 'clone', 'git', './git', @abf).once
28
- @configurator.run
24
+ @configurator.run_linux
29
25
  end
30
26
 
31
27
  it 'should checkout the right tag' do
28
+ flexmock(File).should_receive(:exist?).with('./git').and_return(false)
32
29
  @configurator.instance_eval { tag('tag') }
33
30
  should_execute('git', 'clone', 'git', './git', @abf).once
34
31
  flexmock(Dir).should_receive(:chdir).with('./git', Proc).and_yield
35
32
  should_execute('git', 'checkout', 'tag', {:abort_on_failure=>"Failed to checkout tag"}).once
36
- @configurator.run
33
+ @configurator.run_linux
37
34
  end
38
35
 
39
36
  it 'should skip checkout if directory already exists and contains a .git subdirectory' do
40
37
  flexmock(File).should_receive(:exist?).with('./git').twice.and_return(true)
41
38
  flexmock(File).should_receive(:exist?).with('./git/.git').once.and_return(true)
42
39
  should_execute.and_return { raise 'Command.execute should not be called' }
43
- @configurator.run
40
+ @configurator.run_linux
44
41
  end
45
42
 
46
43
  it 'should move directory if already exists but not a git repo' do
@@ -49,7 +46,7 @@ describe RightConf::GitRepoConfigurator do
49
46
  flexmock(File).should_receive(:exist?).with('./git').once.ordered.and_return(false)
50
47
  flexmock(FileUtils).should_receive(:mv).once
51
48
  should_execute('git', 'clone', 'git', './git', @abf).once
52
- @configurator.run
49
+ @configurator.run_linux
53
50
  end
54
51
 
55
52
  end
@@ -18,12 +18,7 @@ describe RightConf::PackagesConfigurator do
18
18
  end
19
19
 
20
20
  before(:each) do
21
- lang = RightConf::Language.parse('packages { debian %w(deb1 deb2); centos %w(cent1 cent2); darwin %w(mac1 mac2) }')
22
- @configurator = lang.configurators.first
23
- [:report_check, :report_result, :report_success].each do |meth|
24
- flexmock(@configurator).should_receive(meth)
25
- end
26
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
21
+ @configurator = create_configurator('packages { debian %w(deb1 deb2); centos %w(cent1 cent2); darwin %w(mac1 mac2) }')
27
22
  end
28
23
 
29
24
  it 'should install packages on Ubuntu' do
@@ -14,15 +14,20 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
14
14
  describe RightConf::PassengerConfigurator do
15
15
 
16
16
  before(:each) do
17
- lang = RightConf::Language.parse('passenger {}')
18
- @configurator = lang.configurators.first
19
- [:report_check, :report_result, :report_success].each do |meth|
20
- flexmock(@configurator).should_receive(meth)
21
- end
22
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
17
+ @configurator = create_configurator('passenger {}')
18
+ end
19
+
20
+ it 'should default to /opt/nginx when possible' do
21
+ flexmock(File).should_receive(:exist?).with('/opt/nginx').once.and_return(true)
22
+ flexmock(File).should_receive(:exist?).with('/opt').once.and_return(true)
23
+ flexmock(File).should_receive(:writable?).with('/opt/nginx').once.and_return(true)
24
+ @configurator.__send__(:default_install_path).should == '/opt/nginx'
23
25
  end
24
26
 
25
27
  it 'should set defaults' do
28
+ flexmock(File).should_receive(:exist?).with('/opt/nginx').twice.and_return(true)
29
+ flexmock(File).should_receive(:exist?).with('/opt').twice.and_return(true)
30
+ flexmock(File).should_receive(:writable?).with('/opt/nginx').twice.and_return(true)
26
31
  @configurator.__send__(:set_defaults)
27
32
  @configurator.right_site_src_path.should == Dir.getwd
28
33
  @configurator.library_src_path.should == File.expand_path(File.join(Dir.getwd, '..', 'library'))
@@ -31,15 +36,5 @@ describe RightConf::PassengerConfigurator do
31
36
  @configurator.user.should == ENV['USER']
32
37
  end
33
38
 
34
- it 'should default to /opt/nginx when possible' do
35
- to_check = File.exist?('/opt/nginx') ? '/opt/nginx' :
36
- (File.exist?('/opt') ? '/opt' : '/')
37
- if File.writable?(to_check)
38
- @configurator.__send__(:default_install_path).should == '/opt/nginx'
39
- else
40
- pending '/opt/nginx not writable'
41
- end
42
- end
43
-
44
39
  end
45
40
 
@@ -20,12 +20,8 @@ describe RightConf::RubyConfigurator do
20
20
  end
21
21
 
22
22
  before(:each) do
23
- lang = RightConf::Language.parse('ruby { version "0"; rubygems "1" }')
24
- @configurator = lang.configurators.first
25
- [:report_check, :report_result, :report_success, :report].each do |meth|
26
- flexmock(@configurator).should_receive(meth)
27
- end
28
- flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
23
+ @configurator = create_configurator('ruby { version "0"; rubygems "1" }')
24
+ flexmock(File).should_receive(:exist?).with('.rvmrc').and_return(true)
29
25
  end
30
26
 
31
27
  it 'should succeed on linux when rvm succeeds' do
@@ -61,32 +57,35 @@ describe RightConf::RubyConfigurator do
61
57
  {:abort_on_failure=>'Failed to install rubygems'}).once.and_return(success_result)
62
58
  @configurator.run_linux
63
59
  end
60
+ end
64
61
 
65
- describe 'bashrc update' do
62
+ describe 'bashrc update' do
66
63
 
67
- before(:each) do
68
- flexmock(File).should_receive(:exist?).once.with(File.join(ENV['HOME'], '.bashrc')).once.and_return(true)
69
- flexmock(FileUtils).should_receive(:mv).and_return(true)
70
- f = flexmock('f')
71
- f.should_receive(:puts).and_return { |c| @bashrc_content = c }
72
- flexmock(File).should_receive(:open).and_yield(f)
73
- @rvm_bash_activation = @configurator.__send__(:rvm_bash_activation)
74
- end
64
+ before(:each) do
65
+ flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.bashrc')).once.and_return(true)
66
+ flexmock(File).should_receive(:exist?).with('.rvmrc').and_return(true)
67
+ flexmock(FileUtils).should_receive(:mv).and_return(true)
68
+ f = flexmock('f')
69
+ f.should_receive(:puts).and_return { |c| @bashrc_content = c }
70
+ flexmock(File).should_receive(:open).and_yield(f)
71
+ @configurator = create_configurator('ruby { version "0"; rubygems "1" }', :enable_updater => true)
72
+ @rvm_bash_activation = @configurator.__send__(:rvm_bash_activation)
73
+ end
75
74
 
76
- it 'should install rvm hook in bashrc when not present' do
77
- flexmock(IO).should_receive(:read).and_return('test')
78
- @configurator.__send__(:setup_bashrc)
79
- @bashrc_content.should == "#{@rvm_bash_activation}\ntest"
80
- end
75
+ it 'should install rvm hook in bashrc when not present' do
76
+ flexmock(IO).should_receive(:read).and_return('test')
77
+ @configurator.__send__(:setup_bashrc)
78
+ @bashrc_content.should == "#{@rvm_bash_activation}\ntest"
79
+ end
81
80
 
82
- it 'should not install rvm hook in bashrc when present' do
83
- flexmock(IO).should_receive(:read).and_return('test' + @rvm_bash_activation)
84
- @configurator.__send__(:setup_bashrc)
85
- @bashrc_content.should be_nil
86
- end
81
+ it 'should not install rvm hook in bashrc when present' do
82
+ flexmock(IO).should_receive(:read).and_return('test' + @rvm_bash_activation)
83
+ @configurator.__send__(:setup_bashrc)
84
+ @bashrc_content.should be_nil
85
+ end
87
86
 
88
- it 'should install rvm hook after path is set' do
89
- flexmock(IO).should_receive(:read).and_return(<<-EOS
87
+ it 'should install rvm hook after path is set' do
88
+ flexmock(IO).should_receive(:read).and_return(<<-EOS
90
89
  echo 'zobi la mouche'
91
90
  radio killed the radio star
92
91
  #PATH=something:should be fine
@@ -94,9 +93,9 @@ this should not:
94
93
  PATH=something
95
94
  AFTER
96
95
  EOS
97
- )
98
- @configurator.__send__(:setup_bashrc)
99
- @bashrc_content.should == <<-EOS
96
+ )
97
+ @configurator.__send__(:setup_bashrc)
98
+ @bashrc_content.should == <<-EOS
100
99
  echo 'zobi la mouche'
101
100
  radio killed the radio star
102
101
  #PATH=something:should be fine
@@ -104,9 +103,7 @@ this should not:
104
103
  PATH=something
105
104
  #{@rvm_bash_activation}
106
105
  AFTER
107
- EOS
108
- end
109
-
106
+ EOS
110
107
  end
111
108
 
112
109
  end
@@ -19,10 +19,10 @@ describe RightConf::Language do
19
19
  lang.validation_errors.first.should == "Invalid syntax, expecting block after 'toto'"
20
20
  end
21
21
 
22
- it 'should invalidate non-existent configurator' do
22
+ it 'should warn about non-existent configurator' do
23
23
  lang = RightConf::Language.parse('toto { 42 }')
24
- lang.validation_errors.size.should == 1
25
- lang.validation_errors.first.should == "Unknown configurator 'toto'"
24
+ lang.warnings.size.should == 1
25
+ lang.warnings.first.should == "Unknown configurator 'toto'"
26
26
  end
27
27
 
28
28
  it 'should parse correctly' do
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,26 @@ RSpec.configure do |c|
19
19
  c.mock_with(:flexmock)
20
20
  end
21
21
 
22
+ # Create configurator for testing and setup common mocks
23
+ #
24
+ # === Parameters
25
+ # code(String):: Code using rconf language syntax used to initialize configurator
26
+ # opts[:enable_updater](TrueClass|FalseClass):: Don't mock out environment updater if set
27
+ #
28
+ # === Return
29
+ # configurator(RightConf::Configurator):: Created configurator
30
+ def create_configurator(code, opts={})
31
+ lang = RightConf::Language.parse(code)
32
+ configurator = lang.configurators.first
33
+ [:report_check, :report_error, :report_result, :report_success].each do |meth|
34
+ flexmock(configurator).should_receive(meth)
35
+ end
36
+ flexmock(configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
37
+ flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rconf')).and_return(false)
38
+ flexmock(RightConf::EnvironmentUpdater).should_receive(:update) unless opts[:enable_updater]
39
+ configurator
40
+ end
41
+
22
42
  # Helper method to mock Command.execute
23
43
  #
24
44
  # === Parameters
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rconf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.8
5
+ version: 0.7.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Raphael Simon