Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: doudou/flexmock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0
Choose a base ref
...
head repository: doudou/flexmock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Sep 8, 2024

  1. Copy the full SHA
    437d302 View commit details
  2. Copy the full SHA
    958849b View commit details

Commits on Sep 9, 2024

  1. Merge pull request #26 from doudou/pass_thru_block_handling_3_0

    fix: handling of blocks in pass_thru (v3.0)
    doudou authored Sep 9, 2024
    Copy the full SHA
    f9cddbb View commit details
  2. release 3.0.1

    doudou committed Sep 9, 2024
    Copy the full SHA
    c35195f View commit details
Showing with 21 additions and 15 deletions.
  1. +0 −1 .github/workflows/test.yml
  2. +1 −1 lib/flexmock/core.rb
  3. +2 −2 lib/flexmock/expectation.rb
  4. +3 −10 lib/flexmock/partial_mock.rb
  5. +1 −1 lib/flexmock/version.rb
  6. +14 −0 test/partial_mock_test.rb
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ jobs:
- "3.2"
- "3.1"
- "3.0"
- "2.7"

steps:
- uses: actions/checkout@v2
2 changes: 1 addition & 1 deletion lib/flexmock/core.rb
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ def flexmock_calls

# Invocke the original non-mocked functionality for the given
# symbol.
def flexmock_invoke_original(method_name, args, kw = {})
def flexmock_invoke_original(method_name, args, kw = {}, orig_block = nil)
return FlexMock.undefined
end

4 changes: 2 additions & 2 deletions lib/flexmock/expectation.rb
Original file line number Diff line number Diff line change
@@ -392,9 +392,9 @@ def and_throw(sym, value=nil)

def pass_thru(&block)
block ||= lambda { |value| value }
and_return { |*args, **kw|
and_return { |*args, **kw, &orig_block|
begin
block.call(@mock.flexmock_invoke_original(@sym, args, kw))
block.call(@mock.flexmock_invoke_original(@sym, args, kw, orig_block))
rescue NoMethodError => e
if e.name == @sym
raise e, "#{e.message} while performing #pass_thru in expectation object #{self}"
13 changes: 3 additions & 10 deletions lib/flexmock/partial_mock.rb
Original file line number Diff line number Diff line change
@@ -162,10 +162,7 @@ def should_expect(*args)
#
# Usually called in a #and_return statement
def invoke_original(m, *args, **kw, &block)
if block
args << block
end
flexmock_invoke_original(m, args, kw)
flexmock_invoke_original(m, args, kw, block)
end

# Whether the given method's original definition has been stored
@@ -336,7 +333,7 @@ def initialize_stub_remove
# (3) Apply any recorded expecations
#
def create_new_mocked_object(allocate_method, args, kw, recorder, block)
new_obj = flexmock_invoke_original(allocate_method, args, kw)
new_obj = flexmock_invoke_original(allocate_method, args, kw, nil)
mock = flexmock_container.flexmock(new_obj)
block.call(mock) unless block.nil?
recorder.apply(mock)
@@ -346,12 +343,8 @@ def create_new_mocked_object(allocate_method, args, kw, recorder, block)

# Invoke the original definition of method on the object supported by
# the stub.
def flexmock_invoke_original(method, args, kw)
def flexmock_invoke_original(method, args, kw, block)
if (original_method = find_original_method(method))
if Proc === args.last
block = args.last
args = args[0..-2]
end
original_method.call(*args, **kw, &block)
else
@obj.__send__(:method_missing, method, *args, **kw, &block)
2 changes: 1 addition & 1 deletion lib/flexmock/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class FlexMock
VERSION = "3.0.0"
VERSION = "3.0.1"
end
14 changes: 14 additions & 0 deletions test/partial_mock_test.rb
Original file line number Diff line number Diff line change
@@ -752,6 +752,20 @@ def call(value); @value += 1 end
assert_equal 1, obj.value
end

def test_pass_thru_forwards_a_given_block
obj = Class.new do
attr_reader :block
def mocked_method(&block)
@block = block
end
end.new
flexmock(obj).should_receive(:mocked_method).with_block.pass_thru

block = obj.mocked_method { 42 }
assert_kind_of Proc, block
assert_equal block, obj.block
end

def test_should_expect
flexmock(obj = Dog.new).should_expect do |e|
e.bark