Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Jul 5, 2013
1 parent 5968f50 commit f0866e9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion god.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('gollum', '~> 1.3.1')
s.add_development_dependency('airbrake', '~> 3.1.7')
s.add_development_dependency('nokogiri', '~> 1.5.0')

s.add_development_dependency('activesupport', [ '>= 2.3.10', '< 4.0.0' ])
# = MANIFEST =
s.files = %w[
Announce.txt
Expand Down
6 changes: 5 additions & 1 deletion lib/god/event_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.watching_pid?(pid)
end

def self.start
Thread.new do
@@thread = Thread.new do
loop do
begin
@@handler.handle_events
Expand All @@ -72,6 +72,10 @@ def self.start
@@loaded = self.operational?
end

def self.stop
@@thread.kill if @@thread
end

def self.operational?
com = [false]

Expand Down
24 changes: 16 additions & 8 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,25 @@ def silence_warnings
$VERBOSE = old_verbose
end

LOG.instance_variable_set(:@io, StringIO.new('/dev/null'))
LOG.instance_variable_set(:@io, StringIO.new())

module Kernel
def abort(text)
raise SystemExit, text
end
def exit(code)
raise SystemExit, "Exit code: #{code}"
end
def output_logs
io = LOG.instance_variable_get(:@io)
LOG.instance_variable_set(:@io, $stderr)
yield
ensure
LOG.instance_variable_set(:@io, io)
end

# module Kernel
# def abort(text)
# raise SystemExit, text
# end
# def exit(code)
# raise SystemExit, "Exit code: #{code}"
# end
# end

module Test::Unit::Assertions
def assert_abort
assert_raise SystemExit do
Expand Down
2 changes: 2 additions & 0 deletions test/test_condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_generate_should_abort_on_event_condition_without_loaded_event_system
God::EventHandler.start
Condition.generate(:process_exits, nil).class
end
ensure
God::EventHandler.stop
end

def test_generate_should_return_a_good_error_message_for_invalid_types
Expand Down
18 changes: 12 additions & 6 deletions test/test_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def test_valid_should_return_true_if_uid_does_not_exists
def test_valid_should_return_true_if_gid_exists
@p.start = 'qux'
@p.log = '/tmp/foo.log'
@p.gid = 'mail'
@p.gid = Etc.getgrgid(::Process.gid).name

::Process.stubs(:groups=)

assert @p.valid?
end
Expand Down Expand Up @@ -104,12 +106,16 @@ def test_valid_should_return_false_with_bogus_chroot

def test_valid_should_return_true_with_chroot_and_valid_log
@p.start = 'qux'
@p.chroot = '/tmp'
@p.log = '/tmp/foo.log'
@p.chroot = Dir.pwd
@p.log = "#{@p.chroot}/foo.log"

File.expects(:exist?).with(@p.chroot).returns(true)
File.expects(:exist?).with(@p.log).returns(true)
File.expects(:exist?).with("#{@p.chroot}/dev/null").returns(true)

File.stubs(:writable?).with('/foo.log').returns(true)

File.expects(:exist?).with('/tmp').returns(true)
File.expects(:exist?).with('/tmp/foo.log').returns(true)
File.expects(:exist?).with('/tmp/dev/null').returns(true)
::Dir.stubs(:chroot)

assert @p.valid?
end
Expand Down

2 comments on commit f0866e9

@rcresswell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did this fix address? Thanks.

@eric
Copy link
Collaborator Author

@eric eric commented on f0866e9 Jul 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding Kernel.exit() and Kernel.abort() was causing the tests to not test what they should have in the forked processes.

Please sign in to comment.