rspec_api_documentation 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d028dba15444ec4ec3da4d6be2f55832bfe1348f
4
- data.tar.gz: 299d1b2d9bd7d9600975fbfd5982999405cab9cf
3
+ metadata.gz: 5643d0ed3b32b595746931b4dddf583a56e31ed5
4
+ data.tar.gz: 87115d7eac49ebc0f51fbfec49fdc9780f9e4332
5
5
  SHA512:
6
- metadata.gz: a74792e3e273c9522f4047e8edac0819abffb4bdb1a82d8984ad6ca3077a06869361b28d95207ae2efd3696ffb2cb611d1fe19c7bc9fdd6d034c73bbe1cd967d
7
- data.tar.gz: 397c2218f5cfaf98654ea1ba251b4156388d4ec3341f07ebd9b741af19fe2551860a7ab6e3b3746db067a28f8572a8a91164d85498d8e92022700b21030a15b0
6
+ metadata.gz: f15ff0825beca5eca22adc6dc15a044682ea9c835280246a5759bb94e5cf04360e4ba6aa0c5b554cf8c67cd6005ecbe7e2a05ea331efcf390dd08adbc1bb087e
7
+ data.tar.gz: 9c0aefe90889c51b51e3ae671a3b77f5c0cba7a5d4aa38c7faa90aeb26f9a228493a8615ba772b46137fa4d51b94db98caad30e1bca5ab470492ba841e53b416
@@ -89,10 +89,9 @@ module RspecApiDocumentation
89
89
  return nil if response_body.empty?
90
90
  if response_body.encoding == Encoding::ASCII_8BIT
91
91
  "[binary data]"
92
- elsif response_content_type =~ /application\/json/
93
- JSON.pretty_generate(JSON.parse(response_body))
94
92
  else
95
- response_body
93
+ formatter = RspecApiDocumentation.configuration.response_body_formatter
94
+ return formatter.call(response_content_type, response_body)
96
95
  end
97
96
  end
98
97
 
@@ -80,18 +80,42 @@ module RspecApiDocumentation
80
80
  add_setting :response_headers_to_include, :default => nil
81
81
  add_setting :html_embedded_css_file, :default => nil
82
82
 
83
+ # renamed to request_body_formatter. here for backwards compatibility
84
+ add_setting :post_body_formatter, :default => nil
85
+
83
86
  # Change how the post body is formatted by default, you can still override by `raw_post`
84
87
  # Can be :json, :xml, or a proc that will be passed the params
85
88
  #
86
89
  # RspecApiDocumentation.configure do |config|
87
- # config.post_body_formatter = Proc.new do |params|
90
+ # config.request_body_formatter = Proc.new do |params|
88
91
  # # convert to whatever you want
89
92
  # params.to_s
90
93
  # end
91
94
  # end
92
95
  #
93
96
  # See RspecApiDocumentation::DSL::Endpoint#do_request
94
- add_setting :post_body_formatter, :default => Proc.new { |_| Proc.new { |params| params } }
97
+ add_setting :request_body_formatter, :default => Proc.new { |_| RspecApiDocumentation.configuration.post_body_formatter || Proc.new { |params| params } }
98
+
99
+ # Change how the response body is formatted
100
+ # Can be a proc that will be passed the response body
101
+ #
102
+ # RspecApiDocumentation.configure do |config|
103
+ # config.response_body_formatter = Proc.new do |content_type, response_body|
104
+ # # convert to whatever you want
105
+ # response_body
106
+ # end
107
+ # end
108
+ #
109
+ # See RspecApiDocumentation::DSL::Endpoint#do_request
110
+ add_setting :response_body_formatter, default: Proc.new { |_, _|
111
+ Proc.new do |content_type, response_body|
112
+ if content_type =~ /application\/json/
113
+ JSON.pretty_generate(JSON.parse(response_body))
114
+ else
115
+ response_body
116
+ end
117
+ end
118
+ }
95
119
 
96
120
  def client_method=(new_client_method)
97
121
  RspecApiDocumentation::DSL::Resource.module_eval <<-RUBY
@@ -18,9 +18,9 @@ module RspecApiDocumentation
18
18
  # +block+:: Block to pass into describe
19
19
  #
20
20
  def resource(*args, &block)
21
- options = if args.last.is_a?(Hash) then args.pop else {} end
21
+ options = args.last.is_a?(Hash) ? args.pop : {}
22
22
  options[:api_doc_dsl] = :resource
23
- options[:resource_name] = args.first
23
+ options[:resource_name] = args.first.to_s
24
24
  options[:document] ||= :all
25
25
  args.push(options)
26
26
  describe(*args, &block)
@@ -36,7 +36,7 @@ RSpec.configuration.include RspecApiDocumentation::DSL::Endpoint, :api_doc_dsl =
36
36
  RSpec.configuration.include RspecApiDocumentation::DSL::Callback, :api_doc_dsl => :callback
37
37
  RSpec.configuration.backtrace_exclusion_patterns << %r{lib/rspec_api_documentation/dsl/}
38
38
 
39
- if defined? RSpec::Rails
39
+ if defined? RSpec::Rails::DIRECTORY_MAPPINGS
40
40
  RSpec::Rails::DIRECTORY_MAPPINGS[:acceptance] = %w[spec acceptance]
41
41
  RSpec.configuration.infer_spec_type_from_file_location!
42
42
  end
@@ -41,7 +41,7 @@ module RspecApiDocumentation::DSL
41
41
  if respond_to?(:raw_post)
42
42
  params_or_body = raw_post
43
43
  else
44
- formatter = RspecApiDocumentation.configuration.post_body_formatter
44
+ formatter = RspecApiDocumentation.configuration.request_body_formatter
45
45
  case formatter
46
46
  when :json
47
47
  params_or_body = params.empty? ? nil : params.to_json
@@ -9,5 +9,5 @@ end
9
9
  desc 'Generate API request documentation from API specs (ordered)'
10
10
  RSpec::Core::RakeTask.new('docs:generate:ordered') do |t|
11
11
  t.pattern = 'spec/acceptance/**/*_spec.rb'
12
- t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter", "--order default"]
12
+ t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter", "--order defined"]
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.0
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Cahoon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-04 00:00:00.000000000 Z
13
+ date: 2016-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  version: 1.3.6
324
324
  requirements: []
325
325
  rubyforge_project:
326
- rubygems_version: 2.2.2
326
+ rubygems_version: 2.4.5
327
327
  signing_key:
328
328
  specification_version: 4
329
329
  summary: A double black belt for your docs