spec/object_spec.rb in nil_conditional-0.0.1 vs spec/object_spec.rb in nil_conditional-1.0.0

- old
+ new

@@ -1,25 +1,30 @@ describe Object do context 'test method' do - it 'should not raise error when receiving test_method_?' do + it 'should raise error when receiving test_method' do expect { Object.new.test_method }.to raise_error(NoMethodError) end - it 'should not raise error when receiving test_method_?' do - expect { Object.new.test_method_? }.to_not raise_error + it 'should not raise error when receiving __test_method' do + expect { Object.new.__test_method }.to_not raise_error end - it 'should return nil when received non existent method with nil conditional' do - expect(Object.new.test_method_?).to be nil + it 'should return NilConditional instance when received non existent method with preceding __' do + expect(Object.new.__test_method).to be_a(NilConditional) end it 'should support chained methods with nil conditional' do - expect { Object.new.test_method_?.foo_?.bar_?.car_?.cow_? }.to_not raise_error - expect(Object.new.test_method_?.foo_?.bar_?.car_?.cow_?).to be nil + expect { Object.new.__test_method.foo_?.bar_?.car_?.cow_? }.to_not raise_error + expect(Object.new.__test_method.foo_?.bar_?.car_?.cow_?).to be_a(NilConditional) end it 'should support methods with arguments' do - expect { Object.test_method_with_args_?(1, 2, 3) }.to_not raise_error - expect(Object.test_method_with_args_?(1, 2, 3)).to be nil + expect { Object.__test_method_with_args(1, 2, 3) }.to_not raise_error + expect(Object.__test_method_with_args(1, 2, 3)).to be_a(NilConditional) + end + + it 'should support methods with blocks' do + expect(Object.__test_method_with_block{ a = 'b' }).to be_a(NilConditional) + expect(['a', 'b'].__delete_if { |i| i == 'b' }).to eq([ 'a' ]) end end end