Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expectations block not evaluated when using and_call_original #814

Closed
dmitry-a-l opened this issue Nov 12, 2014 · 1 comment
Closed

Expectations block not evaluated when using and_call_original #814

dmitry-a-l opened this issue Nov 12, 2014 · 1 comment

Comments

@dmitry-a-l
Copy link

class SomeClass
  def print_hello
    puts "Hello"
  end
end

RSpec.describe do
  specify do
    object = SomeClass.new
    expect(object).to receive(:print_hello) do
      expect(true).to be_false
    end.and_call_original
    object.print_hello
  end
end

This test will always be passed (same issue for RSpec2). I found only one way to correctly run similar tests:

object = SomeClass.new
method = object.method(:print_hello)

expect(object).to receive(:print_hello) do
    expect(true).to be_false
    method.call
end

object.print_hello

Version with expect_any_instance_of:

object = SomeClass.new
method = SomeClass.instance_method(:print_hello)

expect_any_instance_of(SomeClass).to receive(:print_hello) do |obj|
    expect(true).to be_false
    method.bind(obj).call
end

object.print_hello
@dmitry-a-l
Copy link
Author

Opps, it duplicates #382. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant