Skip to content

response_data can't be used multiple times in 1 spec #15

@natematykiewicz

Description

@natematykiewicz

The response_data helper is really nice, but since it uses add_helper, it's memoized. This is problematic because it's not memoized based on the arguments provided. If you use it multiple times in 1 spec, the subsequent calls don't return what you'd expect.

To work around this, we've added the following to our RSpec config to undo the memoization:

fix_response_data = Module.new do
  def response_data(*)
    raise 'Make sure this is still necessary' unless RSpec::GraphQLResponse::VERSION == '0.5.0'

    remove_instance_variable(:@response_data) if instance_variable_defined?(:@response_data)
    super
  end
end
config.prepend fix_response_data, type: :graphql

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