Open excid3 opened 5 years ago
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.
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.