Sha256: 840e7045bec4b542337cfc567706d2369a7db43f63a08d7a693763843c0f3e2e
Contents?: true
Size: 969 Bytes
Versions: 3
Compression:
Stored size: 969 Bytes
Contents
require File.dirname(__FILE__) + '/../lib/add_hook' def main_method first_arg, second_arg, *splat_of_args end describe Object, '#add_hook' do it 'should be able to add a hook to an object in the main scope' do times_called = 0 main_method 1, 2, 3, 4, 5 times_called.should == 0 add_hook(:main_method) do |obj, *args| # puts "called main_method on #{ obj } with args: #{ args.inspect }" times_called += 1 end times_called.should == 0 main_method 1, 2, 3, 4, 5 times_called.should == 1 end it 'should be able to add a hook to objects' do object = [] times_called = 0 object << 'x' times_called.should == 0 object.add_hook(:<<){|obj, *args| times_called += 1 } object << 'x' times_called.should == 1 object << 'x' times_called.should == 2 # should not effect other arrays object = [] object << 'x' times_called.should == 2 # should still be 2 end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
remi-add_hook-0.1.0 | spec/add_hook_spec.rb |
remi-add_hook_example-0.1.0 | spec/add_hook_spec.rb |
remi-add_hook_example-0.1.1 | spec/add_hook_spec.rb |