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

Unable to set headers in before block #86

Closed
jejacks0n opened this issue Aug 31, 2013 · 9 comments
Closed

Unable to set headers in before block #86

jejacks0n opened this issue Aug 31, 2013 · 9 comments

Comments

@jejacks0n
Copy link

I wanted to use the typical RSpec before filters, so I tagged several of my resources as:

resource_spec.rb

resource "Resource Name", api: :json do
  # specs...
end

spec_helper.rb

RSpec.configure do |config|
  config.before(:each, api: :json) do
    header 'Authorization', "Bearer [access token]"
    header 'Content-Type', 'application/json'
    header 'Accept', 'application/json'
  end
end

It fails on the header, because that's part of the DSL, and doesn't seem to be available any other way. I dug around a good bit, but there doesn't seem to be a way to specify headers/params within a before filter -- which would be nice, because I have to duplicate this at the top of all of the specs.

Thanks for a great library, it's been working really well for me and has been a pleasure to work with.

@oestrich
Copy link
Contributor

header is an example group level DSL method, you're trying to call it at the example level.

shared_context :json_headers do
  header 'Authorization', "Bearer [access token]"
  header 'Content-Type', 'application/json'
  header 'Accept', 'application/json'
end
resource "Resource Name" do
  include_context :json_headers
end

@jejacks0n
Copy link
Author

I get that, and in fact explain that I get that. =) I appreciate the example though, that's definitely useful.

@oestrich
Copy link
Contributor

Ah sorry. Just trying to clear out some of the old issues. You want a way to set them at the example level, gotcha. Let me reopen this.

@oestrich oestrich reopened this Oct 14, 2013
@jejacks0n
Copy link
Author

I do, but it's ok if you disagree. we can provide your solution in the documentation if that works.

But yes, I would like to hook into the concept of setup/teardown in global terms, as that was what seemed natural for me to try -- however if an implementation of that wouldn't be pretty I think documenting how to do it works.

@oestrich
Copy link
Contributor

I think this makes sense. A lot of people seem to try it so might be a natural thing to add.

@jejacks0n
Copy link
Author

I think a solution for this could be very opinionated as well. The only thing that seems relevant (or a good idea) to set globally are headers, so that might simplify it?

@jejacks0n
Copy link
Author

btw, I should mention that I created a simple rails engine for displaying documentation from the JSON that rspec_api_documentation generates.. Apitome

@oestrich
Copy link
Contributor

That looks really nice. Definitely will give it a look. I can add it to the README as another option.

@jejacks0n
Copy link
Author

Yeah, check it out. I needed more customization, and would've contributed to the Raddocs project, but wanted something specific to rails so it would be easier in that land. I'm fine with it being included in the docs, but you'll probably want to specify that it's rails specific.

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