Skip to content

Commit

Permalink
using :allocate as allocator on new instances works again
Browse files Browse the repository at this point in the history
The commit that explicitely disabled it on 1.9+
(02c927c) was very unspecific as to
why it was so. The test passes on 2.0+, so I am reenabling it again.

Closes jimweirich#18
  • Loading branch information
doudou committed Jun 29, 2015
1 parent 89ecf6b commit 1dbcf94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
8 changes: 0 additions & 8 deletions lib/flexmock/partial_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def new_instances(*allocators, &block)
allocators = [:new] if allocators.empty?
expectation_recorder = ExpectationRecorder.new
allocators.each do |allocate_method|
check_allocate_method(allocate_method)
flexmock_define_expectation(location, allocate_method).and_return { |*args|
create_new_mocked_object(
allocate_method, args, expectation_recorder, block)
Expand Down Expand Up @@ -245,13 +244,6 @@ def flexmock_based_on(*args)

private

def check_allocate_method(allocate_method)
if allocate_method == :allocate && RUBY_VERSION >= "1.9"
fail UsageError,
"Cannot mock the allocation method using new_instances in Ruby 1.9"
end
end

# The singleton class of the object.
def target_singleton_class
@obj.singleton_class
Expand Down
20 changes: 5 additions & 15 deletions test/new_instances_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,12 @@ def test_does_not_by_default_stub_objects_created_with_allocate
assert_equal :woof, m.bark
end

if RUBY_VERSION >= "1.9"
def test_explicitly_mocking_allocation_in_new_instances_fails_in_ruby_19
assert_raise FlexMock::UsageError do
flexstub(Dog).new_instances(:allocate) do |obj|
obj.should_receive(:bark).and_return(:whimper)
end
end
end
else
def test_can_explicitly_stub_objects_created_with_allocate
flexstub(Dog).new_instances(:allocate) do |obj|
obj.should_receive(:bark).and_return(:whimper)
end
m = Dog.allocate
assert_equal :whimper, m.bark
def test_can_explicitly_stub_objects_created_with_allocate
flexstub(Dog).new_instances(:allocate) do |obj|
obj.should_receive(:bark).and_return(:whimper)
end
m = Dog.allocate
assert_equal :whimper, m.bark
end

def test_can_stub_objects_created_with_arbitrary_class_methods
Expand Down

0 comments on commit 1dbcf94

Please sign in to comment.