README.md in rspec-rails-api-0.1.4 vs README.md in rspec-rails-api-0.1.5

- old
+ new

@@ -1,6 +1,6 @@ -# RspecRailsApiDoc +# RSpecRailsApiDoc > An RSpec plugin to test Rails api responses and generate swagger > documentation **This is a work in progress** but you're welcome to help, test, submit @@ -32,11 +32,11 @@ ```rb require 'rails_helper' require 'rspec_rails_api' RSpec.configure do |config| - config.include Rspec::Rails::Api::DSL::Example + config.include RSpec::Rails::Api::DSL::Example end renderer = RSpec::Rails::Api::OpenApiRenderer.new renderer.api_servers = [{ url: 'https://example.com' }] renderer.api_title = 'A nice API for a nice application' @@ -50,11 +50,11 @@ renderer.merge_context context.class.metadata[:rrad].to_h end RSpec.configuration.after(:suite) do # Default path is 'tmp/rspec_rails_api_output.json/yaml' - renderer.write_files Rails.root.join('public', 'swagger_doc'), only: :json + renderer.write_files Rails.root.join('public', 'swagger_doc'), only: [:json] end ``` **spec/rails_helper.rb** @@ -69,12 +69,73 @@ end ``` ## Configuration -TODO +**TODO: This section is incomplete and the gem has no generator yet** +### Integration with Devise + +To use `sign_in` and `sign_out` from Devise in the acceptance tests, create a Devise support file: + +```rb +# spec/support/devise.rb +module DeviseAcceptanceSpecHelpers + include Warden::Test::Helpers + + def sign_in(resource_or_scope, resource = nil) + resource ||= resource_or_scope + scope = Devise::Mapping.find_scope!(resource_or_scope) + login_as(resource, scope: scope) + end + + def sign_out(resource_or_scope) + scope = Devise::Mapping.find_scope!(resource_or_scope) + logout(scope) + end +end +``` + +Load this file in `rails_helper.rb`: + +```rb +#... +# Add additional requires below this line. Rails is not loaded until this point! +require 'support/devise' +#... +``` + +Include the helper for acceptance specs: + +```rb +RSpec.configure do |config| + config.include DeviseAcceptanceSpecHelpers, type: :acceptance +end +``` + +You can now use the methods as usual: + +```rb +# In a before block +before do + sign_in #... +end + +# In examples +#... + for_code 200, 'Success' do |example| + sing_in #... + visit example + + #... + end +#... +``` + +This solution comes from [this article](https://makandracards.com/makandra/37161-rspec-devise-how-to-sign-in-users-in-request-specs) +by Arne Hartherz (MIT license). + ## Usage Write some spec files and run RSpec as you would usually do. If you want to generate the documentation without testing the endpoints @@ -455,8 +516,8 @@ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct -Everyone interacting in the RspecRailsApiDoc project’s codebases, issue +Everyone interacting in the RSpecRailsApiDoc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/experimentslabs/rspec-rails-api/blob/master/CODE_OF_CONDUCT.md).