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

Compatibility with ActiveSupport::TestCase / Minitest #10

Open
excid3 opened this issue Jun 6, 2019 · 1 comment
Open

Compatibility with ActiveSupport::TestCase / Minitest #10

excid3 opened this issue Jun 6, 2019 · 1 comment

Comments

@excid3
Copy link

excid3 commented Jun 6, 2019

Are these easy to include in a default Rails app that isn't using Rspec?

I noticed the resource generator probably also needs tweaks to generate rspec tests, only if rspec is installed.

Happy to work on some PRs, but pretty new to this code base so still getting familiar. If you have some pointers, I can take a stab at things.

@richmolj
Copy link
Contributor

richmolj commented Jun 7, 2019

Hey @excid3 sorry for the delay - I haven't done this myself, but shouldn't be too hard.

There are really two parts to this: first the test helpers like jsonapi_data that help you parse the response are already RSpec-agnostic. If you mixin GraphitiSpecHelpers and GraphitiSpecHelpers::Sugar, you can use these in a vanilla Rails integration test (I think).

That leaves GraphitiSpecHelpers::RSpec, which contains shared contexts that make test setup easier. Even this mixin has very little actual RSpec in it, just a way to register shared contexts. So for instance:

  def render(runtime_options = {})
    json = proxy.to_jsonapi(runtime_options)
    response.body = json
    json
  end

This is referencing other setup methods, but the premise is we're in a Resource spec, not an API spec, so we need a way to "render" JSON even though there's no request or response. So we're just wrapping the lower-level Graphiti API to do this.

I imagine there is very little to do other than copy/paste to get up and running. Happy to merge anything that facilitates the process - 95% of this lib has nothing to do with RSpec, it's just what I personally use so I haven't invested in other setups.

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