Skip to content

LDContext equality #224

@jgarber-cisco

Description

@jgarber-cisco

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions