apirunner 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apirunner.gemspec +3 -2
- data/lib/api_configuration.rb +8 -0
- data/lib/api_runner.rb +15 -14
- data/lib/expectation_matcher.rb +8 -8
- data/lib/testcase.rb +11 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/apirunner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apirunner}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["jan@moviepilot.com"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-30}
|
13
13
|
s.description = %q{apirunner is a testsuite to query your RESTful JSON API and match response with your defined expectations}
|
14
14
|
s.email = %q{developers@moviepilot.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/http_client.rb",
|
49
49
|
"lib/result.rb",
|
50
50
|
"lib/tasks/api.rake",
|
51
|
+
"lib/testcase.rb",
|
51
52
|
"spec/.rspec",
|
52
53
|
"spec/api_runner_spec.rb",
|
53
54
|
"spec/expectation_matcher_spec.rb",
|
data/lib/api_configuration.rb
CHANGED
@@ -2,5 +2,13 @@ class ApiConfiguration
|
|
2
2
|
|
3
3
|
attr_accessor :protocol, :host, :namespace, :port, :verbosity, :priority
|
4
4
|
|
5
|
+
# initializes a configuration object from given YAML file for given environment
|
6
|
+
def initialize(raw_config, env)
|
7
|
+
raw_config[env.to_s].each { |key, value| self.instance_variable_set("@#{key}", value) }
|
8
|
+
self.verbosity = raw_config['general']['verbosity'].first
|
9
|
+
self.priority = raw_config['general']['priority'] || 0
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
5
13
|
end
|
6
14
|
|
data/lib/api_runner.rb
CHANGED
@@ -3,6 +3,7 @@ class ApiRunner
|
|
3
3
|
require 'expectation_matcher'
|
4
4
|
require 'http_client'
|
5
5
|
require 'api_configuration'
|
6
|
+
require 'testcase'
|
6
7
|
|
7
8
|
CONFIG_FILE = "config/api_runner.yml"
|
8
9
|
SPEC_PATH = "test/api_runner/"
|
@@ -13,8 +14,7 @@ class ApiRunner
|
|
13
14
|
@spec = []
|
14
15
|
@results = []
|
15
16
|
@excludes = []
|
16
|
-
@configuration = ApiConfiguration.new
|
17
|
-
load_config(env)
|
17
|
+
@configuration = ApiConfiguration.new(YAML.load_file(self.class.config_file), env)
|
18
18
|
load_excludes(env)
|
19
19
|
load_url_spec
|
20
20
|
@http_client = HttpClient.new(@configuration.protocol, @configuration.host, @configuration.port, @configuration.namespace)
|
@@ -39,7 +39,7 @@ class ApiRunner
|
|
39
39
|
def run_tests
|
40
40
|
puts "Running exactly #{@spec.size} tests."
|
41
41
|
@spec.each do |test_case|
|
42
|
-
response =
|
42
|
+
response = send_request_for(test_case)
|
43
43
|
@expectation.test_types.each do |test_type|
|
44
44
|
result = @expectation.check(test_type, response, test_case)
|
45
45
|
if not result.succeeded
|
@@ -57,8 +57,8 @@ class ApiRunner
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# sends http request and fetches response using the given http client
|
60
|
-
def
|
61
|
-
@http_client.send_request(method,
|
60
|
+
def send_request_for(testcase)
|
61
|
+
@http_client.send_request(testcase.request['method'], testcase.request['path'], testcase.request['headers'], testcase.request['body'], testcase.request['parameters'])
|
62
62
|
end
|
63
63
|
|
64
64
|
# builds target uri from base uri generated of host port and namespace as well as the ressource path
|
@@ -72,14 +72,6 @@ class ApiRunner
|
|
72
72
|
!@http_client.send_request(:get, "#{@configuration.protocol}://#{@configuration.host}:#{@configuration.port}", nil, {:timeout => 5}).nil?
|
73
73
|
end
|
74
74
|
|
75
|
-
# loads environment config data from yaml file
|
76
|
-
def load_config(env)
|
77
|
-
config = YAML.load_file(self.class.config_file)
|
78
|
-
config[env.to_s].each { |key, value| @configuration.instance_variable_set("@#{key}", value) }
|
79
|
-
@configuration.verbosity = config['general']['verbosity'].first
|
80
|
-
@configuration.priority = config['general']['priority'] || 0
|
81
|
-
end
|
82
|
-
|
83
75
|
# loads spec cases from yaml files
|
84
76
|
def load_url_spec
|
85
77
|
path = self.class.spec_path
|
@@ -87,7 +79,16 @@ class ApiRunner
|
|
87
79
|
Dir.new(path).entries.each do |dir_entry|
|
88
80
|
specs.push *YAML.load_file(path+dir_entry) if not (File.directory? dir_entry or dir_entry.match(/^\./) or dir_entry.match(/excludes/))
|
89
81
|
end
|
90
|
-
@spec = priorize(partition(specs))
|
82
|
+
@spec = objectize(priorize(partition(specs)))
|
83
|
+
end
|
84
|
+
|
85
|
+
# converts the given array of raw testcases to an array of testcase objects
|
86
|
+
def objectize(raw_specs)
|
87
|
+
specs = []
|
88
|
+
raw_specs.each do |spec|
|
89
|
+
specs << Testcase.new(spec)
|
90
|
+
end
|
91
|
+
specs
|
91
92
|
end
|
92
93
|
|
93
94
|
# returns only spec whose priority level is less or equals configures priority level
|
data/lib/expectation_matcher.rb
CHANGED
@@ -23,9 +23,9 @@ class ExpectationMatcher
|
|
23
23
|
# matches the given response code
|
24
24
|
def response_code(response, testcase)
|
25
25
|
result = Result.new(testcase, response)
|
26
|
-
if not testcase
|
26
|
+
if not testcase.response_expectation['status_code'].to_s == response.code.to_s
|
27
27
|
result.succeeded = false
|
28
|
-
result.error_message = " expected response code --#{testcase
|
28
|
+
result.error_message = " expected response code --#{testcase.response_expectation['status_code']}--\n got response code --#{response.code}--"
|
29
29
|
end
|
30
30
|
result
|
31
31
|
end
|
@@ -46,7 +46,7 @@ class ExpectationMatcher
|
|
46
46
|
def response_headers(response, testcase)
|
47
47
|
result = Result.new(testcase, response)
|
48
48
|
|
49
|
-
testcase
|
49
|
+
testcase.response_expectation['headers'].each_pair do |header_name, header_value|
|
50
50
|
if is_regex?(header_value)
|
51
51
|
if not (excluded?(header_name) or regex_matches?(header_value, response.headers[header_name]))
|
52
52
|
result.succeeded = false
|
@@ -58,7 +58,7 @@ class ExpectationMatcher
|
|
58
58
|
result.error_message = " expected header identifier --#{header_name}-- to match --#{header_value}--\n got --#{response.headers[header_name]}--"
|
59
59
|
end
|
60
60
|
end
|
61
|
-
end unless (testcase
|
61
|
+
end unless (testcase.response_expectation['headers'].nil? or testcase.response_expectation['headers'].empty?)
|
62
62
|
return result
|
63
63
|
end
|
64
64
|
|
@@ -67,15 +67,15 @@ class ExpectationMatcher
|
|
67
67
|
result = Result.new(testcase, response)
|
68
68
|
|
69
69
|
# special case: the whole body has to be matched via a regular expression
|
70
|
-
if is_regex?(testcase
|
71
|
-
if not regex_matches?(testcase
|
70
|
+
if is_regex?(testcase.response_expectation['body'])
|
71
|
+
if not regex_matches?(testcase.response_expectation['body'], response.body)
|
72
72
|
result.succeeded = false
|
73
|
-
result.error_message = " expected the whole body to match regex --#{testcase
|
73
|
+
result.error_message = " expected the whole body to match regex --#{testcase.response_expectation['body']}--\n got --#{response.body}--"
|
74
74
|
end
|
75
75
|
return result
|
76
76
|
end
|
77
77
|
|
78
|
-
expected_body_hash = testcase
|
78
|
+
expected_body_hash = testcase.response_expectation['body']
|
79
79
|
|
80
80
|
# in case we have no body expectation we simply return success
|
81
81
|
return result if expected_body_hash.nil?
|
data/lib/testcase.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jan@moviepilot.com
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -252,6 +252,7 @@ files:
|
|
252
252
|
- lib/http_client.rb
|
253
253
|
- lib/result.rb
|
254
254
|
- lib/tasks/api.rake
|
255
|
+
- lib/testcase.rb
|
255
256
|
- spec/.rspec
|
256
257
|
- spec/api_runner_spec.rb
|
257
258
|
- spec/expectation_matcher_spec.rb
|
@@ -271,7 +272,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
272
|
requirements:
|
272
273
|
- - ">="
|
273
274
|
- !ruby/object:Gem::Version
|
274
|
-
hash:
|
275
|
+
hash: -4241672918987621375
|
275
276
|
segments:
|
276
277
|
- 0
|
277
278
|
version: "0"
|