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

Fix never expectation deprecation warning logic #686

Conversation

floehopper
Copy link
Member

@floehopper floehopper commented Nov 27, 2024

In #681 I added logic to display a deprecation warning about a change I planned to make in #679. However, it turns out the logic in both was faulty as demonstrated in this example where the deprecation warning was incorrectly displayed for the 2nd call to Foo.create_if:

    class Foo
      def self.create_if(condition)
        new if condition
      end
    end

    test "it creates only if condition is true" do
      Foo.expects(:new).never
      Foo.create_if(false)

      Foo.expects(:new).once
      Foo.create_if(true)
    end

This commit adds a new acceptance test to cover an example where the logic was incorrect and updates the logic in Mock#handle_method_call to fix the logic so this new test passes and none of the existing tests fail. Unfortunately the implementation is now rather complicated and hard to follow, but I think it will do for now. I have a couple of ideas for ways to simplify it, but I don't have time to work on that now.

I have updated the equivalent logic in #679 to match the new logic implemented here.

In #681 I added logic to display a deprecation warning about a change I
planned to make in #679. However, it turns out the logic in both was
faulty as demonstrated in this example [1] where the deprecation
warning was incorrectly displayed for the 2nd call to `Foo.create_if`:

    class Foo
      def self.create_if(condition)
        new if condition
      end
    end

    test "it creates only if condition is true" do
      Foo.expects(:new).never
      Foo.create_if(false)

      Foo.expects(:new).once
      Foo.create_if(true)
    end

This commit adds a new acceptance test to cover an example where the
logic was incorrect and updates the logic in `Mock#handle_method_call`
to fix the logic so this new test passes and none of the existing tests
fail. Unfortunately the implementation is now rather complicated and
hard to follow, but I think it will do for now. I have a couple of ideas
for ways to simplify it, but I don't have time to work on that now.

I plan to update the equivalent logic in #679 to match the new logic
implemented here.

[1]: #679 (comment)
@floehopper floehopper merged commit 0b2923f into main Nov 28, 2024
16 checks passed
@floehopper floehopper deleted the fix-deprecation-warning-logic-for-expectation-with-never-cardinality branch November 28, 2024 14:48
@floehopper
Copy link
Member Author

Released in v2.6.1.

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

Successfully merging this pull request may close these issues.

1 participant