rspec_api_blueprint 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6bc265809b6e399dfc015efa0e7ade0949289b88
4
+ data.tar.gz: e011a97ca96abe52352a134a471fde29e9275181
5
+ SHA512:
6
+ metadata.gz: 91a5e8e729247dd890b00367b6fb1034c87e2117c7ef81ec0a8f86e968dc12400449015a820ec2772accc97e194ef460c9dff503b452256c7779752bee2077e4
7
+ data.tar.gz: a7f795abb665477c1ddc9d8af3e997bc5f3b33b81f251e17af68e3e698c1a999987facbb006ff06389b1c3ee2b336fda035e81738d5a309029024173f00df174
data/README.md CHANGED
@@ -58,7 +58,6 @@ The output:
58
58
  }
59
59
  }
60
60
 
61
-
62
61
  ## Caveats
63
62
 
64
63
  401, 403 and 301 statuses are ignored since rspec produces a undesired output.
@@ -0,0 +1,14 @@
1
+ unless "".respond_to?(:indent)
2
+ class String
3
+ def indent(count, char = ' ')
4
+ gsub(/([^\n]*)(\n|$)/) do |match|
5
+ last_iteration = ($1 == "" && $2 == "")
6
+ line = ""
7
+ line << (char * count) unless last_iteration
8
+ line << $1
9
+ line << $2
10
+ line
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module RspecApiBlueprint
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,23 +1,15 @@
1
1
  require "rspec_api_blueprint/version"
2
+ require "rspec_api_blueprint/string_extensions"
2
3
 
3
- unless "".respond_to?(:indent)
4
- class String
5
- def indent(count, char = ' ')
6
- gsub(/([^\n]*)(\n|$)/) do |match|
7
- last_iteration = ($1 == "" && $2 == "")
8
- line = ""
9
- line << (char * count) unless last_iteration
10
- line << $1
11
- line << $2
12
- line
13
- end
14
- end
15
- end
16
- end
17
4
 
18
5
  RSpec.configure do |config|
19
6
  config.before(:suite) do
20
- api_docs_folder_path = File.join(Rails.root, '/api_docs/')
7
+ if defined? Rails
8
+ api_docs_folder_path = File.join(Rails.root, '/api_docs/')
9
+ else
10
+ api_docs_folder_path = File.join(File.expand_path('.'), '/api_docs/')
11
+ end
12
+
21
13
  Dir.mkdir(api_docs_folder_path) unless Dir.exists?(api_docs_folder_path)
22
14
 
23
15
  Dir.glob(File.join(api_docs_folder_path, '*')).each do |f|
@@ -26,6 +18,9 @@ RSpec.configure do |config|
26
18
  end
27
19
 
28
20
  config.after(:each, type: :request) do
21
+ response ||= last_response
22
+ request ||= last_request
23
+
29
24
  if response
30
25
  example_group = example.metadata[:example_group]
31
26
  example_groups = []
@@ -39,13 +34,19 @@ RSpec.configure do |config|
39
34
  example_groups[-1][:description_args].first.match(/(\w+)\sRequests/)
40
35
  file_name = $1.underscore
41
36
 
42
- File.open(File.join(Rails.root, "/api_docs/#{file_name}.txt"), 'a') do |f|
37
+ if defined? Rails
38
+ file = File.join(Rails.root, "/api_docs/#{file_name}.txt")
39
+ else
40
+ file = File.join(File.expand_path('.'), "/api_docs/#{file_name}.txt")
41
+ end
42
+
43
+ File.open(file, 'a') do |f|
43
44
  # Resource & Action
44
45
  f.write "# #{action}\n\n"
45
46
 
46
47
  # Request
47
48
  request_body = request.body.read
48
- authorization_header = request.headers['Authorization']
49
+ authorization_header = request.env ? request.env['Authorization'] : request.headers['Authorization']
49
50
 
50
51
  if request_body.present? || authorization_header.present?
51
52
  f.write "+ Request #{request.content_type}\n\n"
@@ -66,7 +67,7 @@ RSpec.configure do |config|
66
67
  # Response
67
68
  f.write "+ Response #{response.status} #{response.content_type}\n\n"
68
69
 
69
- if response.body.present? && request.content_type == 'application/json'
70
+ if response.body.present? && response.content_type == 'application/json'
70
71
  f.write "#{JSON.pretty_generate(JSON.parse(response.body))}\n\n".indent(8)
71
72
  end
72
73
  end unless response.status == 401 || response.status == 403 || response.status == 301
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_blueprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matteo Depalo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,33 +27,29 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec-rails
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Autogeneration of documentation from request specs
@@ -72,31 +65,32 @@ files:
72
65
  - README.md
73
66
  - Rakefile
74
67
  - lib/rspec_api_blueprint.rb
68
+ - lib/rspec_api_blueprint/string_extensions.rb
75
69
  - lib/rspec_api_blueprint/version.rb
76
70
  - rspec_api_blueprint.gemspec
77
71
  homepage: ''
78
72
  licenses:
79
73
  - MIT
74
+ metadata: {}
80
75
  post_install_message:
81
76
  rdoc_options: []
82
77
  require_paths:
83
78
  - lib
84
79
  required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
80
  requirements:
87
- - - ! '>='
81
+ - - '>='
88
82
  - !ruby/object:Gem::Version
89
83
  version: '0'
90
84
  required_rubygems_version: !ruby/object:Gem::Requirement
91
- none: false
92
85
  requirements:
93
- - - ! '>='
86
+ - - '>='
94
87
  - !ruby/object:Gem::Version
95
88
  version: '0'
96
89
  requirements: []
97
90
  rubyforge_project:
98
- rubygems_version: 1.8.24
91
+ rubygems_version: 2.2.1
99
92
  signing_key:
100
- specification_version: 3
93
+ specification_version: 4
101
94
  summary: Autogeneration of documentation from request specs
102
95
  test_files: []
96
+ has_rdoc: