tenderlove (owner)

Fork Of

Revisions

gist: 191243 Download_button fork
public
Public Clone URL: git://gist.github.com/191243.git
Embed All Files: show embed
some_class.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
class SomeClass
  def initialize(options = {})
    load_config
    set_options(options)
  end
 
  def load_config
  end
 
  def set_options(options)
  end
end
 
test_some_class.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require 'test/unit'
require 'some_class'
 
class TestSomeClass < Test::Unit::TestCase
  def test_initialize_calls_stuff
    foo = Class.new(SomeClass) {
      attr_reader :shit_called
      def initialize *args
        @shit_called = []
        super
      end
 
      def load_config; @shit_called << 'load_config'; end
      def set_options(*args); @shit_called << 'set_options'; end
    }.new
 
    assert_equal %w{ load_config set_options }, foo.shit_called
  end
end