okapi 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+
2
+ *.DS_Store
3
+ *.gem
4
+ /.idea
5
+ /nbproject/
6
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tu1ly
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # OKApi
2
+
3
+ ## Installation
4
+
5
+ $ gem install okapi
6
+
7
+ ## Usage
8
+
9
+ $ okapi help
10
+
11
+ ## Contributing
12
+
13
+ 1. Fork it
14
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
15
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
16
+ 4. Push to the branch (`git push origin my-new-feature`)
17
+ 5. Create new Pull Request
data/Rakefile ADDED
File without changes
data/bin/okapi ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..','lib')))
3
+ require 'okapi'
4
+
5
+ trap(:INT) { abort "" }
6
+ Apiary::Okapi::CLI.new(ARGV)
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ module Apiary
6
+ module Okapi
7
+ class ApiaryConnector
8
+
9
+ attr_reader :apiary_url, :blueprint
10
+
11
+ def initialize(apiary_url, req_path, res_path)
12
+ @apiary_url = apiary_url
13
+ @req_path = req_path
14
+ @res_path = res_path
15
+ end
16
+
17
+ def get_requests(resources, blueprint)
18
+
19
+ resources_list = []
20
+
21
+ resources.each() do |res|
22
+ resources_list << {
23
+ :resource => res.uri,
24
+ :method => res.method,
25
+ :params => res.params,
26
+ }
27
+ end
28
+
29
+ data = {
30
+ :resources => resources_list,
31
+ :blueprint => blueprint
32
+ }.to_json()
33
+
34
+ begin
35
+ response = RestClient.post @apiary_url + @req_path, data, :content_type => :json, :accept => :json
36
+ data = JSON.parse(response.to_str)
37
+
38
+ {:resp => response, :data => data['requests'], :status => data['status'], :error => data['error']}
39
+ rescue Exception => e
40
+ {:resp => nil, :data => nil, :status => nil, :error => e}
41
+ end
42
+
43
+ end
44
+
45
+ def get_results(resources, blueprint)
46
+
47
+ resources_list = []
48
+ resources.each() do |res|
49
+ resources_list << {
50
+ :request => {
51
+ :uri => res.uri,
52
+ :expandedUri => res.expanded_uri,
53
+ :method => res.method,
54
+ :headers => res.headers,
55
+ :body => res.body,
56
+ },
57
+ :response => {
58
+ :status => res.response.status,
59
+ :headers => res.response.headers ,
60
+ :body => res.response.body
61
+ }
62
+ }
63
+ end
64
+
65
+ data = {
66
+ :resources => resources_list,
67
+ :blueprint => blueprint
68
+ }.to_json()
69
+
70
+ begin
71
+ response = RestClient.post @apiary_url + @res_path, data, :content_type => :json, :accept => :json
72
+
73
+ data = JSON.parse(response.to_str)
74
+
75
+ {:resp => response, :data => data['requests'], :status => data['status'], :error => data['error']}
76
+ rescue Exception => e
77
+ {:resp => nil, :data => nil, :status => nil, :error => e}
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
data/lib/okapi/cli.rb ADDED
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require 'optparse'
3
+
4
+ module Apiary
5
+ module Okapi
6
+ class CLI
7
+
8
+ def initialize(args)
9
+ case args.first
10
+ when 'help'
11
+ puts Apiary::Okapi::Help.show
12
+ when 'version'
13
+ puts VERSION
14
+ when 'okapi'
15
+ puts Apiary::Okapi::Help.okapi
16
+ else
17
+ run(parse_options!(args))
18
+ end
19
+
20
+
21
+ end
22
+
23
+ def run(options)
24
+ Apiary::Okapi::Test.new(options[:blueprint], options[:test_spec], options[:test_url], options[:output], options[:apiary_url]).run()
25
+
26
+ end
27
+
28
+ def parse_options!(args)
29
+ options = {}
30
+ options_parser = OptionParser.new do |opts|
31
+ opts.on("-b", "--blueprint BLUEPRINT",
32
+ "path to the blueprint (default: " + BLUEPRINT_PATH + " )") do |blueprint|
33
+ options[:blueprint] = blueprint
34
+ end
35
+
36
+ opts.on("-t","--test_spec TEST_SPEC",
37
+ "path to the test specification (default: " + TEST_SPEC_PATH + " )") do |test_spec|
38
+ options[:test_spec] = test_spec
39
+ end
40
+
41
+ opts.on("-o","--output OUTPUT",
42
+ "output format (default" + OUTPUT + ")") do |output|
43
+ options[:output] = output
44
+ end
45
+
46
+ opts.on("-u","--test_url TEST_URL",
47
+ "url to test (default" + TEST_URL + ")") do |test_url|
48
+ options[:test_url] = test_url
49
+ end
50
+
51
+ opts.on("-a","--apiary APIARY",
52
+ "apiary url (default" + APIARY_URL + ")") do |apiary|
53
+ options[:apiary_url] = apiary
54
+ end
55
+
56
+ end
57
+
58
+ options_parser.parse!
59
+ options[:blueprint] ||= BLUEPRINT_PATH
60
+ options[:test_spec] ||= TEST_SPEC_PATH
61
+ options[:output] ||= OUTPUT
62
+ options[:test_url] ||= TEST_URL
63
+ options[:apiary_url] ||= APIARY_URL
64
+
65
+ raise OptionParser::InvalidOption, 'Blueprint file "' + options[:blueprint] + '" does not exist' if not File.file?(options[:blueprint])
66
+ raise OptionParser::InvalidOption, 'Test specification file "' + options[:test_spec] + '" does not exist' if not File.file?(options[:test_spec])
67
+
68
+ options
69
+
70
+ rescue OptionParser::InvalidOption => e
71
+ puts e
72
+ puts Apiary::Okapi::Help.banner
73
+ exit 1
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Okapi
4
+ APIARY_URL = "https://api.apiary.io"
5
+ GET_REQUESTS_PATH = "/tests/get-requests"
6
+ GET_RESULTS_PATH = "/tests/get-test-results"
7
+ BLUEPRINT_PATH = "apiary.apib"
8
+ TEST_SPEC_PATH = "tests.spec"
9
+ OUTPUT = 'tap'
10
+ TEST_URL = "127.0.0.1"
11
+ end
12
+ end
File without changes
data/lib/okapi/help.rb ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Okapi
4
+ class Help
5
+ def self.show
6
+ banner
7
+ options
8
+ end
9
+
10
+ def self.banner
11
+ puts "\nUsage: okapi [options]"
12
+ puts "Try 'okapi help' for more information."
13
+ end
14
+
15
+ def self.options
16
+ puts "\nCurrently available okapi options are:\n\n"
17
+
18
+ puts "\t-b, --blueprint path to the blueprint (default: " + BLUEPRINT_PATH + " )"
19
+ puts "\t-t, --test_spec path to the test specification (default: " + TEST_SPEC_PATH + " )"
20
+ #puts "\t-o, --output output format (default: " + OUTPUT + ")"
21
+ puts "\t-u, --test_url url to test (default: " + TEST_URL + ")"
22
+ puts "\t-a, --apiary apiary url (default: " + APIARY_URL + ")"
23
+ puts "\n"
24
+ puts "\thelp Show this help"
25
+ puts "\n"
26
+ puts "\tversion Show version"
27
+ puts "\n"
28
+ end
29
+
30
+ def self.okapi
31
+ puts File.read(File.dirname(__FILE__) + '/okapi')
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/okapi/okapi ADDED
@@ -0,0 +1,43 @@
1
+
2
+ ,#.@:
3
+ @;#@@#
4
+ #+#@#@;
5
+ :+#;#'+@#@#`
6
+ @@##@+@;; ``` ,` ;,;@@@+',`
7
+ ;@###@@. ,+#@@@@@@@@#@@@@@@@@@@#``
8
+ #@@: `,@@#@#@#@@##@@@@@@@'#`+:+:`
9
+ .#@` #+ ` ::` :`,.+;#`,``'`@.##:#`+`##;` `
10
+ '@# ` , #+@#@+':@###@+;+.#@,@#`+`+#@@@#:.
11
+ +@@` + `;#;++`'@@###@@+ @@,@@`#;@@#@#@@@#;+'
12
+ :@@@@. `; ';#+@,##@####@;,@+,@#`:#':#+'@##@@#'@+`
13
+ `@@@@###; ` ' @;+#@@#@#.@@'@@@``.'` +#:@'@@#@#@#;
14
+ `,`#+`,#` `:;#;@#@;.#+;@@#:'`++ ` #.@@@:@,@@@#
15
+ `:;##@##@:##@.'+:@#,#`.@#@:@@;@##+`
16
+ #,#@+@@@##@##@#+:`#@@#@`+#;##++
17
+ @@@@@@@@@@;'@+@#`#.'@@@@``,.,:#,
18
+ ####@@@##'`#@'@@`#'#,@@@# `@#
19
+ ;#@@+@@#'+@'@+@#`#@+@@@@@## #,#
20
+ #@@##@#+##:@#@@,'@.@@@` :: ;#;
21
+ '#,#`#@#.'.#@@#+,####` ` `'#
22
+ + +:;+@@#@#.##@@#.@. `+`,
23
+ ' `#+###@@@@@#@@@+`.:` .'#
24
+ @` ##@#####@:@@##`` #,@
25
+ @#'` #@@##@#,'### ` @'#
26
+ ###' @ :##`#;;#, @.,
27
+ ,+,+ .. ` +#+': . ``++,
28
+ :':'@; +; `,,, `;
29
+ #; `: @;#'`; :+``
30
+
31
+ +` ` '+;' : .#`
32
+ @@,@+ .+. ; +##;
33
+ ;#,#@ ',+. `@##
34
+ :#:#
35
+ `+ .
36
+ ##.#` + #
37
+ #+,@. @ +
38
+ #+ .` # `
39
+ :; '`` `
40
+ +## ###
41
+ `@@: .##`
42
+ '## ##:
43
+ `# `
@@ -0,0 +1,11 @@
1
+ Dir["#{File.dirname(__FILE__)}/outputs/*.rb"].each { |f| require(f) }
2
+
3
+ module Apiary
4
+ module Okapi
5
+ class Output
6
+ def self.get(output,resources, error)
7
+ Apiary::Okapi::Outputs.const_get(output.to_s.capitalize).send(:new, resources, error).get()
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,87 @@
1
+ module Apiary
2
+ module Okapi
3
+ module Outputs
4
+ class BaseOutput
5
+ def initialize(resources, error)
6
+ @resources = resources
7
+ @error = error
8
+ @results = {
9
+ :count => 0,
10
+ :give_up => false,
11
+ }
12
+ get_results
13
+ end
14
+
15
+ def get
16
+ p '------------------------------------------------------------------'
17
+ p @results[:count].to_s + ' tests'
18
+ p @results[:give_up][:error].to_s if @results[:give_up]
19
+ @results[:tests].each { |test|
20
+ p '########################################'
21
+ p test[:test_no]
22
+ p test[:description]
23
+ if test[:pass]
24
+ p 'OK'
25
+ else
26
+ p "FAILED"
27
+ p test[:exp]
28
+ end
29
+ }
30
+ end
31
+
32
+ def get_results
33
+
34
+ @results[:count] = @resources.count
35
+ @results[:tests] = []
36
+ if @error
37
+ @results[:give_up] = {:error => @error}
38
+ else
39
+ counter = 0
40
+ @resources.each { |res|
41
+ counter += 1
42
+ test_res = {
43
+ :test_no=> counter,
44
+ :pass => (res.validation_result.status and res.response.validation_result.status),
45
+ :description => res.method + ' ' + res.uri
46
+ }
47
+ if not test_res[:pass]
48
+ test_res[:exp] = {:request => {:pass => false}, :response => {:pass => false}}
49
+ if res.validation_result.status
50
+ test_res[:exp][:request][:pass] = true
51
+ else
52
+ test_res[:exp][:request][:reasons] = get_fail_result(res.validation_result)
53
+ end
54
+
55
+ if res.response.validation_result.status
56
+ test_res[:exp][:response][:pass] = true
57
+ else
58
+ test_res[:exp][:response][:reasons] = get_fail_result(res.response.validation_result)
59
+ end
60
+ end
61
+ @results[:tests] << test_res
62
+ }
63
+ end
64
+ end
65
+
66
+ def get_fail_result(result)
67
+ res = []
68
+
69
+ if result.schema
70
+ result.schema_res["errors"]["length"].times {|i|
71
+ res << result.schema_res["errors"][i.to_s]["message"]
72
+ }
73
+ else
74
+ if not result.header_pass
75
+ res << 'Headers does not match'
76
+ end
77
+ if not result.body_pass
78
+ res << 'Body does not match'
79
+ end
80
+ end
81
+ res
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,39 @@
1
+ require "#{File.dirname(__FILE__)}/base.rb"
2
+ require 'yaml'
3
+
4
+ module Apiary
5
+ module Okapi
6
+ module Outputs
7
+ class Tap < Apiary::Okapi::Outputs::BaseOutput
8
+
9
+ def get
10
+ puts "TAP version 13"
11
+ puts "1..#{@results[:count].to_s}"
12
+ if @results[:give_up]
13
+ puts "Bail out! #{@results[:give_up][:error].to_s.tr("\n"," ")}"
14
+ return
15
+ end
16
+ @results[:tests].each { |test|
17
+ if test[:pass]
18
+ o = 'ok '
19
+ else
20
+ o = 'not ok '
21
+ end
22
+ puts o + test[:test_no].to_s + ' ' + test[:description]
23
+ if not test[:pass]
24
+ error_block(test)
25
+ end
26
+ }
27
+ end
28
+
29
+ def error_block(test)
30
+ test[:exp].to_yaml.split(/\n/).each { |line|
31
+ puts " #{line}"
32
+ }
33
+ puts " ..."
34
+
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Okapi
4
+ class Resource
5
+ attr_accessor :uri, :method, :params, :expanded_uri, :headers, :body, :response, :validation_result
6
+
7
+ def initialize(uri, method, params, expanded_uri = nil, headers = nil, body = nil, response = nil, validation_result = nil)
8
+ #p uri, method, params
9
+ @uri = uri
10
+ @method = method
11
+ @params = params
12
+ @expanded_uri = expanded_uri
13
+ @headers = headers
14
+ @body = body
15
+ @response = response
16
+ @validation_result = validation_result
17
+ end
18
+ end
19
+
20
+ class Response
21
+ attr_accessor :status, :headers, :body, :error, :validation_result
22
+
23
+ def initialize(status = nil, headers = nil, body = nil, error = nil, validation_result = nil)
24
+ @headers = headers
25
+ @body = body
26
+ @status = status
27
+ @error = error
28
+ @validation_result = validation_result
29
+ end
30
+ end
31
+
32
+ class ValidationResult
33
+ attr_accessor :status, :error, :schema_res , :body_pass, :body_diff, :header_pass, :header_diff
34
+
35
+ def status
36
+ @status ||= get_status
37
+ end
38
+
39
+ def get_status
40
+ # p '@error and @headerPass and ((@schema and @schemaPass) or (not @schema and @bodyPass))'
41
+ #
42
+ # p @error
43
+ # p @header_pass
44
+ # p @schemaRes
45
+ # p schema
46
+ # p schema_pass
47
+ # p @body_pass
48
+ # p '#'
49
+ # p (not @error and @header_pass and ((schema and schema_pass) or (not schema and @body_pass)))
50
+ # p (@header_pass and ((schema and schema_pass) or (not schema and @body_pass)))
51
+ # p (((schema and schema_pass) or (not schema and @body_pass)))
52
+ # p (((schema and schema_pass)))
53
+ # p (((not schema and @bodyPass)))
54
+ # p (not @error)
55
+ # p '----'
56
+ # p @body_diff
57
+ # p @header_diff
58
+ return true if not @error and @header_pass and ((schema and schema_pass) or (not schema and @body_pass))
59
+ return false
60
+ end
61
+
62
+ def schema
63
+ !(@schema_res == false)
64
+ end
65
+
66
+ def schema_pass
67
+ not schema or schema and @schema_res and not @schema_res['errors']
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require 'json'
3
+
4
+ module Apiary
5
+ module Okapi
6
+ class Parser
7
+
8
+ attr_reader :data, :resources
9
+
10
+ def initialize(spec_path)
11
+ @data = read_file(spec_path)
12
+ end
13
+
14
+ def resources
15
+ @resources ||= begin
16
+ parse_data { |res|
17
+ raise Exception, 'resource not defined' unless res["resource"]
18
+ raise Exception, 'method not defined' unless res["method"]
19
+
20
+ (@resources ||= []) << Apiary::Okapi::Resource.new(res["resource"], res["method"], res["params"])
21
+ }
22
+ @resources
23
+ end
24
+ end
25
+
26
+ def read_file(path)
27
+ @data = []
28
+ File.open(path).each do |line|
29
+ @data << line
30
+ end
31
+ @data
32
+ end
33
+
34
+ def parse_data
35
+ @data.each { |res|
36
+ splited = res.split(' ',3)
37
+ begin
38
+ splited[2] = JSON.parse splited[2] if splited[2]
39
+ rescue Exception => e
40
+ raise Exception, 'can not parse parameters for resource:' + res + "(#{e})"
41
+ end
42
+ out = {
43
+ 'resource' => splited[1],
44
+ 'method' => splited[0],
45
+ 'params' => splited[2] || {}
46
+ }
47
+ yield out
48
+ }
49
+ end
50
+
51
+ end
52
+ end
53
+ end
data/lib/okapi/test.rb ADDED
@@ -0,0 +1,139 @@
1
+ # encoding: utf-8
2
+ require 'rest_client'
3
+
4
+ module Apiary
5
+ module Okapi
6
+ class Test
7
+ def initialize(blueprint_path, test_spec_path, test_url, output, apiary_url)
8
+ @blueprint_path = blueprint_path || BLUEPRINT_PATH
9
+ @test_spec_path = test_spec_path || TEST_SPEC_PATH
10
+ @test_url = test_url || TEST_URL
11
+ @output_format = output || OUTPUT
12
+ @apiary_url = apiary_url || APIARY_URL
13
+ @req_path = GET_REQUESTS_PATH
14
+ @res_path = GET_RESULTS_PATH
15
+ @connector = Apiary::Okapi::ApiaryConnector.new(@apiary_url, @req_path, @res_path)
16
+ @output = []
17
+ @resources = []
18
+ @error = nil
19
+
20
+ end
21
+
22
+ def run
23
+ get_output(method(:test))
24
+ end
25
+
26
+ def get_output(test)
27
+ begin
28
+ test.call()
29
+ #change to Exception !!!!
30
+ #rescue LoadError => e
31
+ rescue Exception => e
32
+ @error = e
33
+ #p @error
34
+ end
35
+
36
+ Apiary::Okapi::Output.get(@output_format, @resources, @error)
37
+ end
38
+
39
+ def test
40
+ prepare()
41
+ if not @resources.empty?
42
+ get_responses
43
+ evaluate
44
+ else
45
+ raise Exception, 'No resources provided'
46
+ end
47
+ end
48
+
49
+ def prepare
50
+ resources = parse_test_spec(@test_spec_path)
51
+
52
+ data = get_requests_spec(resources)
53
+
54
+ raise Exception, 'Can not get request data from apiary ' + data[:error] || '' if data[:error] or data[:resp].code.to_i != 200
55
+
56
+ data[:data].each do |res|
57
+ raise Exception, 'Resource error "' + res['error'] + '" for resource "' + res["method"] + ' ' + res["uri"] + '"' if res['error']
58
+
59
+ resources.each do |resource|
60
+ if resource.uri == res["uri"] and resource.method == res["method"]
61
+ resource.expanded_uri = res["expandedUri"]
62
+ resource.body = res["body"]
63
+ resource.headers = res["headers"]
64
+ break
65
+ end
66
+ end
67
+ end
68
+ @resources = resources
69
+ end
70
+
71
+ def blueprint
72
+ @blueprint ||= parse_blueprint(@blueprint_path)
73
+ end
74
+
75
+ def get_responses
76
+ @resources.each { |resource|
77
+ params = {:method => resource.method, :url => @test_url + resource.expanded_uri['url'], :headers => resource.headers || {}}
78
+ begin
79
+ response = RestClient::Request.execute(params)
80
+
81
+ raw_headers = response.raw_headers.inject({}) do |out, (key, value)|
82
+ out[key] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
83
+ out
84
+ end
85
+
86
+ resource.response = Apiary::Okapi::Response.new(response.code, raw_headers, response.body)
87
+ rescue Exception => e
88
+ raise Exception 'Can not get response for:' + params
89
+ end
90
+ }
91
+
92
+ end
93
+
94
+ def evaluate
95
+
96
+ data = @connector.get_results(@resources, blueprint)
97
+
98
+ raise Exception, 'Can not get evaluation data from apiary' + data[:error] || '' if data[:resp].code.to_i != 200 or data[:error]
99
+
100
+ data[:data].each { |validation|
101
+ @resources.each { |resource|
102
+ if validation['resource']['uri'] == resource.uri and validation['resource']['method'] == resource.method
103
+ resource.validation_result = Apiary::Okapi::ValidationResult.new()
104
+ resource.validation_result.error = validation['errors']
105
+ resource.validation_result.schema_res = validation["validations"]['reqSchemaValidations']
106
+ resource.validation_result.body_pass = !validation["validations"]['reqData']['body']['isDifferent']
107
+ resource.validation_result.body_diff = validation["validations"]['reqData']['body']['diff']
108
+ resource.validation_result.header_pass = !validation["validations"]['reqData']['headers']['isDifferent']
109
+ resource.validation_result.header_diff = validation["validations"]['reqData']['headers']['diff']
110
+
111
+ resource.response.validation_result = Apiary::Okapi::ValidationResult.new()
112
+ resource.response.validation_result.error = validation['errors']
113
+ resource.response.validation_result.schema_res = validation["validations"]['resSchemaValidations']
114
+ resource.response.validation_result.body_pass = !validation["validations"]['resData']['body']['isDifferent']
115
+ resource.response.validation_result.body_diff = validation["validations"]['resData']['body']['diff']
116
+ resource.response.validation_result.header_pass = !validation["validations"]['resData']['headers']['isDifferent']
117
+ resource.response.validation_result.header_diff = validation["validations"]['resData']['headers']['diff']
118
+ end
119
+
120
+ }
121
+ }
122
+ end
123
+
124
+ def parse_test_spec(test_spec)
125
+ Apiary::Okapi::Parser.new(test_spec).resources
126
+ end
127
+
128
+ def parse_blueprint(blueprint_path)
129
+ File.read(blueprint_path)
130
+ end
131
+
132
+ def get_requests_spec(resources)
133
+ @connector.get_requests(resources, blueprint)
134
+ end
135
+
136
+ end
137
+ end
138
+ end
139
+
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ module Apiary
3
+ module Okapi
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
data/lib/okapi.rb ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require "okapi/version"
4
+ require "okapi/config"
5
+ require "okapi/output"
6
+ require "okapi/apiary_connector"
7
+ require "okapi/resources"
8
+ require "okapi/spec_parser"
9
+ require "okapi/test"
10
+ require "okapi/cli"
11
+ require "okapi/help"
12
+
13
+
14
+
15
+
16
+ module Okapi
17
+
18
+ end
data/okapi.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require File.expand_path('../lib/okapi/version', __FILE__)
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "okapi"
9
+ spec.version = Apiary::Okapi::VERSION
10
+ spec.authors = ["Tu1ly"]
11
+ spec.email = ["tully@apiary.io"]
12
+ spec.description = %q{Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API}
13
+ spec.summary = %q{Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API}
14
+ spec.homepage = "http://apiary.io"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "json"
23
+ spec.add_dependency "rest-client"
24
+ end
@@ -0,0 +1,57 @@
1
+ HOST: http://www.google.com/
2
+
3
+ --- aaaaaaa ---
4
+
5
+ ---
6
+ Welcome to the our sample API documentation. All comments can be written in (support [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax)
7
+ ---
8
+
9
+ --
10
+ Shopping Cart Resources
11
+ The following is a section of resources related to the shopping cart
12
+ --
13
+
14
+ List products added into your shopping-cart. (comment block again in Markdown)
15
+ GET /shopping-cart/{id}
16
+ < 200
17
+ < Content-Type: application/json
18
+ { "items": [
19
+ { "url": "/shopping-cart/1", "product":"2ZY48XPZ", "quantity": 1, "name": "New socks", "price": 1.25 }
20
+ ] }
21
+
22
+ Save new products in your shopping cart
23
+ POST /shopping-cart/{id2}
24
+ > Content-Type: application/json
25
+ { "product":"1AB23ORM", "quantity": 2 }
26
+ < 201
27
+ < Content-Type: application/json
28
+ { "status": "created", "url": "/shopping-cart/2" }
29
+
30
+ -- Payment Resources --
31
+
32
+ This resource allows you to submit payment information to process your *shopping cart* items
33
+ POST /payment
34
+ { "cc": "12345678900", "cvc": "123", "expiry": "0112" }
35
+ < 200
36
+ { "receipt": "/payment/receipt/1aaa" }
37
+
38
+ -- JSON Schema Validations --
39
+
40
+ POST /shopping-cart/{id2}
41
+ {"request":
42
+ { "type": "object",
43
+ "properties": {
44
+ "product": { "type": "string","format": "alphanumeric" },
45
+ "quantity": { "type": "integer" }
46
+ }
47
+ }
48
+ ,
49
+ "response":
50
+ { "type": "object",
51
+ "properties": {
52
+ "product": { "type": "string","format": "alphanumeric" },
53
+ "status": { "type": "integer" }
54
+ }
55
+ }
56
+ }
57
+
@@ -0,0 +1,2 @@
1
+ POST /shopping-cart/{id2} {"id2": "eee2"}
2
+ POST /payment
@@ -0,0 +1,18 @@
1
+ [{
2
+ "resource": "/shopping-cart/{id}",
3
+ "method": "GET",
4
+ "params": {"id": "eee"}
5
+ }
6
+ ,
7
+ {
8
+ "resource": "/shopping-cart/{id2}",
9
+ "method": "POST",
10
+ "params": {"id2": "eee2"}
11
+ }
12
+ ,
13
+ {
14
+ "resource": "/payment",
15
+ "method": "POST",
16
+ "params": {}
17
+ }
18
+ ]
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: okapi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Tu1ly
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-05-05 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API
50
+ email:
51
+ - tully@apiary.io
52
+ executables:
53
+ - okapi
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - LICENSE.txt
62
+ - README.md
63
+ - Rakefile
64
+ - bin/okapi
65
+ - lib/okapi.rb
66
+ - lib/okapi/apiary_connector.rb
67
+ - lib/okapi/cli.rb
68
+ - lib/okapi/config.rb
69
+ - lib/okapi/exceptions.rb
70
+ - lib/okapi/help.rb
71
+ - lib/okapi/okapi
72
+ - lib/okapi/output.rb
73
+ - lib/okapi/outputs/base.rb
74
+ - lib/okapi/outputs/tap.rb
75
+ - lib/okapi/resources.rb
76
+ - lib/okapi/spec_parser.rb
77
+ - lib/okapi/test.rb
78
+ - lib/okapi/version.rb
79
+ - okapi.gemspec
80
+ - test_files/apiary.apib
81
+ - test_files/tests.spec
82
+ - test_files/tests_1.spec
83
+ has_rdoc: true
84
+ homepage: http://apiary.io
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Apiary.io API tester - OKApi allows you to test if your documentation in Apiary Blueprint match your API
117
+ test_files: []
118
+