rspec-api-blueprint-formatter 0.2.1 → 0.2.2

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: 66253fd5e90a63780a9c868ca055bace2d499990
4
- data.tar.gz: 0919dbc11129eed8dac2814a3c49ef6204c1f87b
3
+ metadata.gz: 68a3f26247af518145dd22bcb32ca8e724445311
4
+ data.tar.gz: 2dcd00052e7280ab6ad3cc4de602a423affd2ab9
5
5
  SHA512:
6
- metadata.gz: afdad4817e8b8129c495e0c6e1f65f4825ed7ea07017f3eedbcf173e02dc04d112fb876886bad992f57ea864e218825de629a4e0f68b2954ec9204d3fb7203cf
7
- data.tar.gz: a244c31492520e6fb16a2cd7b8f58f42eae995e7712d6b03feaefedc35d06228515201317ca493870140b83812cad9998f5b1a80ed6563f4f4a54be823a4a2a5
6
+ metadata.gz: 4087c2a9d82868d9cfddb61489235c59c4c52c6c02b5baa33a8717d24871e93b068a66a05dfa82cc9ec98f78f5c86035aaf1a55033c4dffba2454bf48b5a7382
7
+ data.tar.gz: 314532515763924052e2c9caa7a6581dec9a49dd6d02a203cd202ced631ad9236b70445c842ea28fa0dbe091186f5d3443a0d1297e7e4618ff60554a351e5c65
data/lib/api_blueprint.rb CHANGED
@@ -80,7 +80,7 @@ class ApiBlueprint < RSpec::Core::Formatters::BaseFormatter
80
80
  end
81
81
  output.puts "# #{resource_name}"
82
82
 
83
- http_verbs = actions.keys.map {|action| action.scan(/\[([A-Z]+).+\]/).flatten[0] }
83
+ http_verbs = actions.keys.map {|action| action.scan(/(GET|HEAD|POST|PATCH|PUT|DELETE|OPTIONS)/).flatten[0] }
84
84
 
85
85
  unless http_verbs.length == http_verbs.uniq.length
86
86
  raise "Action HTTP verbs are not unique #{actions.keys.inspect} for resource: '#{resource_name}'"
@@ -60,7 +60,7 @@ module ApiBlueprintFormatter
60
60
  end
61
61
 
62
62
  def action_header(param, data)
63
- param_signature = "#{param}#{param_attributes_string(data)}"
63
+ param_signature = "#{param}#{params_example_string(data)}#{param_attributes_string(data)}"
64
64
  multiline_description = !members(param).empty?
65
65
 
66
66
  header = "+ #{param_signature}"
@@ -75,6 +75,11 @@ module ApiBlueprintFormatter
75
75
  " (#{param_attributes.join(', ')})" unless param_attributes.empty?
76
76
  end
77
77
 
78
+ def params_example_string(data)
79
+ return '' unless data[:example]
80
+ ": #{data[:example]}"
81
+ end
82
+
78
83
  def members(param)
79
84
  @action_metadata[:parameters][param].fetch(:members, [])
80
85
  end
@@ -30,13 +30,17 @@ module ApiBlueprintFormatter
30
30
  "\n" \
31
31
  " #{example_metadata[:request][:parameters]}\n" \
32
32
  "\n" \
33
- " Location: #{example_metadata[:location]}\n" \
33
+ " Location: #{format_location}\n" \
34
34
  " Source code:\n" \
35
35
  "\n" \
36
36
  "#{indent_lines(8, example_metadata[:source])}\n" \
37
37
  "\n"
38
38
  end
39
39
 
40
+ def format_location
41
+ example_metadata[:location].gsub(/:\d+/,'') # remove line numbers from location
42
+ end
43
+
40
44
  def format_response
41
45
  "+ Response #{example_metadata[:response][:status]} (#{example_metadata[:request][:format]})\n" \
42
46
  "\n" \
@@ -1,3 +1,3 @@
1
1
  module ApiBlueprintFormatter
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -75,6 +75,24 @@ RSpec.describe ApiBlueprintFormatter::ActionFormatter do
75
75
  end
76
76
  end
77
77
 
78
+ context 'descriptive param with: type, optionality and example value' do
79
+ let(:action_parameters) do
80
+ {
81
+ amount: { description: 'Id of a post', type: :number, optional: true, example: 123 }
82
+ }
83
+ end
84
+
85
+ it do
86
+ is_expected.to eq <<-EOF
87
+ #{action_header}
88
+
89
+ + Parameters
90
+ + amount: 123 (number, optional) - Id of a post
91
+
92
+ EOF
93
+ end
94
+ end
95
+
78
96
  context 'descriptive param with: type, optionality, default value' do
79
97
  let(:action_parameters) do
80
98
  {
@@ -17,7 +17,7 @@ RSpec.describe ApiBlueprintFormatter::ExampleFormatter do
17
17
 
18
18
  let(:request_metadata) { { parameters: {}, format: 'application/json' } }
19
19
  let(:response_metadata) { { status: 200, body: JSON.generate({a:1, b:2, c:3}) } }
20
- let(:location) { "spec/api_blueprint/example_formatter_spec.rb" }
20
+ let(:location) { "spec/api_blueprint/example_formatter_spec.rb:42" }
21
21
  let(:source) { "it 'returns standard APi Blueprint format' do\n ;\nend" }
22
22
 
23
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-api-blueprint-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nam Chu Hoai