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

LDContext equality #224

Closed
jgarber-cisco opened this issue Aug 25, 2023 · 2 comments
Closed

LDContext equality #224

jgarber-cisco opened this issue Aug 25, 2023 · 2 comments

Comments

@jgarber-cisco
Copy link

Is your feature request related to a problem? Please describe.
I would like to mock LDClient#variation and expect it to be called with a particular context, but equality isn't implemented:

LaunchDarkly::LDContext.with_key("foo") == LaunchDarkly::LDContext.with_key("foo")
=> false

So if I try something like expect(ld_client).to receive(:variation).with('foo', my_context, false), I get a spec failure if my_context isn't the same exact Ruby object.

Describe the solution you'd like
LDContext should implement equality so two LDContexts can be compared. Even better, make LDContext quack like a hash so I can compare it to a hash, retrieve attributes like a hash, etc.

Describe alternatives you've considered
I've had to mock an alternate implementation for variation that returns the context key so I can check that variation was called with the right context. I'm also expecting the call with the feature flag name to ensure that it wasn't a different flag that was checked, but I have to use anything as a stand-in for the context.

expect(ld_client).to receive(:variation).with('foo', anything, false) # LDContexts don't have == implemented properly
@keelerm84
Copy link
Member

Thank you for filing this issue. Both of those seem pretty reasonable.

I have filed a ticket for this in our internal system: sc-214802 for reference. I will update you here when progress is made on this request.

Thank you again!

LaunchDarklyReleaseBot pushed a commit that referenced this issue Oct 16, 2023
These new context_ configuration options are meant to replace the
historic user_ options. If both are provided, the context_ variant will
take precedence.
@keelerm84
Copy link
Member

Context equality and [] access were both added in v8.1.0!

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

2 participants