honey 0.0.6

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.
Files changed (59) hide show
  1. data/.gitignore +14 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +22 -0
  6. data/README.md +55 -0
  7. data/Rakefile +26 -0
  8. data/bin/apiary +12 -0
  9. data/bin/honey +12 -0
  10. data/doc/Apiary.html +131 -0
  11. data/doc/Apiary/CLI.html +480 -0
  12. data/doc/Apiary/Command.html +117 -0
  13. data/doc/Apiary/Command/Help.html +331 -0
  14. data/doc/Apiary/Command/Preview.html +1102 -0
  15. data/doc/Apiary/Command/Runner.html +201 -0
  16. data/doc/Apiary/Command/Version.html +201 -0
  17. data/doc/_index.html +192 -0
  18. data/doc/class_list.html +53 -0
  19. data/doc/css/common.css +1 -0
  20. data/doc/css/full_list.css +57 -0
  21. data/doc/css/style.css +328 -0
  22. data/doc/file.README.html +119 -0
  23. data/doc/file_list.html +55 -0
  24. data/doc/frames.html +28 -0
  25. data/doc/index.html +119 -0
  26. data/doc/js/app.js +214 -0
  27. data/doc/js/full_list.js +173 -0
  28. data/doc/js/jquery.js +4 -0
  29. data/doc/method_list.html +252 -0
  30. data/doc/top-level-namespace.html +112 -0
  31. data/honey.gemspec +27 -0
  32. data/lib/honey.rb +7 -0
  33. data/lib/honey/cli.rb +70 -0
  34. data/lib/honey/command/help.rb +36 -0
  35. data/lib/honey/command/preview.rb +103 -0
  36. data/lib/honey/command/publish.rb +74 -0
  37. data/lib/honey/command/runner.rb +13 -0
  38. data/lib/honey/command/version.rb +13 -0
  39. data/lib/honey/version.rb +3 -0
  40. data/lib/okapi.rb +13 -0
  41. data/lib/okapi/apiary_connector.rb +98 -0
  42. data/lib/okapi/cli.rb +122 -0
  43. data/lib/okapi/config.rb +13 -0
  44. data/lib/okapi/examples/apiary.apib +59 -0
  45. data/lib/okapi/examples/apiary.yaml +5 -0
  46. data/lib/okapi/examples/tests.spec +6 -0
  47. data/lib/okapi/examples/tests2.spec +3 -0
  48. data/lib/okapi/exceptions.rb +0 -0
  49. data/lib/okapi/help.rb +36 -0
  50. data/lib/okapi/okapi +43 -0
  51. data/lib/okapi/output.rb +14 -0
  52. data/lib/okapi/outputs/base.rb +91 -0
  53. data/lib/okapi/outputs/tap.rb +44 -0
  54. data/lib/okapi/resources.rb +53 -0
  55. data/lib/okapi/spec_parser.rb +82 -0
  56. data/lib/okapi/test.rb +141 -0
  57. data/spec/cli_spec.rb +9 -0
  58. data/spec/spec_helper.rb +2 -0
  59. metadata +205 -0
data/lib/okapi/test.rb ADDED
@@ -0,0 +1,141 @@
1
+ # encoding: utf-8
2
+ require 'rest_client'
3
+
4
+ module Honey
5
+ module Okapi
6
+ class Test
7
+ def initialize(blueprint_path, test_spec_path, test_url, output, apiary_url)
8
+ @blueprint_path = blueprint_path
9
+ @test_spec_path = test_spec_path
10
+ @test_url = test_url
11
+ @output_format = output
12
+ @apiary_url = apiary_url
13
+ @req_path = GET_REQUESTS_PATH
14
+ @res_path = GET_RESULTS_PATH
15
+ @connector = Honey::Okapi::ApiaryConnector.new(@apiary_url, @req_path, @res_path)
16
+ @proces_all_bp_resources = false
17
+ @output = []
18
+ @resources = []
19
+ @error = nil
20
+ end
21
+
22
+ def run
23
+ begin
24
+ test()
25
+ rescue Exception => e
26
+ @resources = []
27
+ @error = e
28
+ end
29
+ Honey::Okapi::Output.get(@output_format, @resources, @error)
30
+ end
31
+
32
+ def test
33
+ prepare()
34
+ if not @resources.empty?
35
+ get_responses
36
+ evaluate
37
+ else
38
+ raise Exception, 'No resources provided'
39
+ end
40
+ end
41
+
42
+ def prepare
43
+ @resources = []
44
+ parser = get_test_spec_parser(@test_spec_path)
45
+ resources = parser.resources
46
+ counter = 0
47
+
48
+ resources.each { |res|
49
+ counter += 1
50
+ raise Exception, "Rresource not defined for item #{counter.to_d} in #{@test_spec_path}" unless res["resource"]
51
+ raise Exception, "Method not defined for resource #{res["resource"].to_s} in #{@test_spec_path}" unless res["method"]
52
+ }
53
+
54
+ @proces_all_bp_resources = parser.proces_all_bp_resources
55
+ data = get_requests_spec(resources, parser.global_vars)
56
+
57
+ if data[:error] or data[:code] != 200
58
+ raise Exception, 'Can not get request data from Apiary: ' + data[:error] ? data[:error] : ''
59
+ end
60
+
61
+ data[:data].each do |res|
62
+ raise Exception, 'Resource error "' + res['error'] + '" for resource "' + res["method"] + ' ' + res["uri"] + '"' if res['error']
63
+ @resources << Honey::Okapi::Resource.new(res["uri"], res["method"], res["params"], res["expandedUri"], res["headers"], res["body"])
64
+ end
65
+
66
+ @resources
67
+ end
68
+
69
+ def blueprint
70
+ @blueprint ||= parse_blueprint(@blueprint_path)
71
+ end
72
+
73
+ def get_responses
74
+ @resources.each { |resource|
75
+ params = {:method => resource.method, :url => @test_url + resource.expanded_uri['url'], :headers => resource.headers || {}, :payload=> resource.body}
76
+ begin
77
+ response = RestClient::Request.execute(params)
78
+
79
+ raw_headers = response.raw_headers.inject({}) do |out, (key, value)|
80
+ out[key] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
81
+ out
82
+ end
83
+
84
+ resource.response = Honey::Okapi::Response.new(response.code, raw_headers, response.body)
85
+ rescue Exception => e
86
+ raise Exception, 'Can not get response for: ' + params.to_json + ' (' + e.to_s + ')'
87
+ end
88
+ }
89
+
90
+ end
91
+
92
+ def evaluate
93
+
94
+ data = @connector.get_results(@resources, blueprint)
95
+ if data[:error] or data[:code] != 200
96
+ raise Exception, 'Can not get evaluation data from apiary: ' + data[:error] ? data[:error] : ''
97
+ end
98
+
99
+ data[:data].each { |validation|
100
+ @resources.each { |resource|
101
+ if validation['resource']['uri'] == resource.uri and validation['resource']['method'] == resource.method
102
+ resource.validation_result = Honey::Okapi::ValidationResult.new()
103
+ resource.validation_result.error = validation['errors']
104
+ resource.validation_result.schema_res = validation["validations"]['reqSchemaValidations']
105
+ resource.validation_result.body_pass = !validation["validations"]['reqData']['body']['isDifferent']
106
+ resource.validation_result.body_diff = validation["validations"]['reqData']['body']['diff']
107
+ resource.validation_result.header_pass = !validation["validations"]['reqData']['headers']['isDifferent']
108
+ resource.validation_result.header_diff = validation["validations"]['reqData']['headers']['diff']
109
+
110
+ resource.response.validation_result = Honey::Okapi::ValidationResult.new()
111
+ resource.response.validation_result.error = validation['errors']
112
+ resource.response.validation_result.schema_res = validation["validations"]['resSchemaValidations']
113
+ resource.response.validation_result.body_pass = !validation["validations"]['resData']['body']['isDifferent']
114
+ resource.response.validation_result.body_diff = validation["validations"]['resData']['body']['diff']
115
+ resource.response.validation_result.header_pass = !validation["validations"]['resData']['headers']['isDifferent']
116
+ resource.response.validation_result.header_diff = validation["validations"]['resData']['headers']['diff']
117
+ end
118
+
119
+ }
120
+ }
121
+ end
122
+
123
+ def get_test_spec_parser(test_spec)
124
+ Honey::Okapi::Parser.new(test_spec)
125
+ end
126
+
127
+ def parse_blueprint(blueprint_path)
128
+ if not File.exist? blueprint_path
129
+ raise Exception, "Blueprint file '#{blueprint_path}' not found"
130
+ end
131
+ File.read(blueprint_path)
132
+ end
133
+
134
+ def get_requests_spec(resources, global_vars)
135
+ @connector.get_requests(resources, blueprint, @proces_all_bp_resources, global_vars)
136
+ end
137
+
138
+ end
139
+ end
140
+ end
141
+
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Honey::CLI do
4
+
5
+ it 'pass the test' do
6
+ true.should be_true
7
+ end
8
+
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'honey'
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Apiary Ltd.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.4.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.11.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.11.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.2.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.2.1
110
+ description: Apiary.io CLI
111
+ email:
112
+ - team@apiary.io
113
+ executables:
114
+ - apiary
115
+ - honey
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - .travis.yml
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - bin/apiary
127
+ - bin/honey
128
+ - doc/Apiary.html
129
+ - doc/Apiary/CLI.html
130
+ - doc/Apiary/Command.html
131
+ - doc/Apiary/Command/Help.html
132
+ - doc/Apiary/Command/Preview.html
133
+ - doc/Apiary/Command/Runner.html
134
+ - doc/Apiary/Command/Version.html
135
+ - doc/_index.html
136
+ - doc/class_list.html
137
+ - doc/css/common.css
138
+ - doc/css/full_list.css
139
+ - doc/css/style.css
140
+ - doc/file.README.html
141
+ - doc/file_list.html
142
+ - doc/frames.html
143
+ - doc/index.html
144
+ - doc/js/app.js
145
+ - doc/js/full_list.js
146
+ - doc/js/jquery.js
147
+ - doc/method_list.html
148
+ - doc/top-level-namespace.html
149
+ - honey.gemspec
150
+ - lib/honey.rb
151
+ - lib/honey/cli.rb
152
+ - lib/honey/command/help.rb
153
+ - lib/honey/command/preview.rb
154
+ - lib/honey/command/publish.rb
155
+ - lib/honey/command/runner.rb
156
+ - lib/honey/command/version.rb
157
+ - lib/honey/version.rb
158
+ - lib/okapi.rb
159
+ - lib/okapi/apiary_connector.rb
160
+ - lib/okapi/cli.rb
161
+ - lib/okapi/config.rb
162
+ - lib/okapi/examples/apiary.apib
163
+ - lib/okapi/examples/apiary.yaml
164
+ - lib/okapi/examples/tests.spec
165
+ - lib/okapi/examples/tests2.spec
166
+ - lib/okapi/exceptions.rb
167
+ - lib/okapi/help.rb
168
+ - lib/okapi/okapi
169
+ - lib/okapi/output.rb
170
+ - lib/okapi/outputs/base.rb
171
+ - lib/okapi/outputs/tap.rb
172
+ - lib/okapi/resources.rb
173
+ - lib/okapi/spec_parser.rb
174
+ - lib/okapi/test.rb
175
+ - spec/cli_spec.rb
176
+ - spec/spec_helper.rb
177
+ homepage: http://apiary.io
178
+ licenses:
179
+ - MIT
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 1.8.24
199
+ signing_key:
200
+ specification_version: 3
201
+ summary: Apiary.io CLI
202
+ test_files:
203
+ - spec/cli_spec.rb
204
+ - spec/spec_helper.rb
205
+ has_rdoc: