apirunner 0.4.6 → 0.4.7
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.
- data/VERSION +1 -1
- data/apirunner.gemspec +1 -1
- data/lib/checker.rb +10 -0
- data/lib/http_client.rb +1 -1
- data/lib/plugins/plug03_response_header_checker.rb +5 -0
- data/spec/api_runner_spec.rb +1 -1
- data/spec/checker_spec.rb +84 -0
- data/spec/http_client_spec.rb +2 -2
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.7
|
data/apirunner.gemspec
CHANGED
data/lib/checker.rb
CHANGED
|
@@ -31,6 +31,16 @@ class Checker
|
|
|
31
31
|
@excludes.include?(item)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def is_number_comparison?(string)
|
|
35
|
+
return false unless string
|
|
36
|
+
string.match(/^[><]\s*\d+\s*$/) || string.match(/^[<>=]=\s*\d+\s*$/)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def compare_number(expectation, value)
|
|
40
|
+
return false unless value && value.match(/[\d\.]+/)
|
|
41
|
+
eval "#{value}#{expectation}"
|
|
42
|
+
end
|
|
43
|
+
|
|
34
44
|
# returns true if given string seems to be a regular expression
|
|
35
45
|
def is_regex?(string)
|
|
36
46
|
string.to_s.match(/^\/.+\/$/)
|
data/lib/http_client.rb
CHANGED
|
@@ -26,7 +26,7 @@ class HttpClient
|
|
|
26
26
|
response.code = raw_response.code
|
|
27
27
|
response.message = raw_response.message
|
|
28
28
|
response.body = raw_response.body
|
|
29
|
-
response.headers =
|
|
29
|
+
response.headers = raw_response.to_hash.keys.inject({}){|hash, key| hash[key] = raw_response.to_hash[key][0]; hash}
|
|
30
30
|
response.runtime = runtime
|
|
31
31
|
response.fully_qualified_path = (method == "GET" ? build_uri(resource, params).request_uri : resource_path(resource))
|
|
32
32
|
response
|
|
@@ -10,6 +10,11 @@ class ResponseHeaderChecker < Checker
|
|
|
10
10
|
result.succeeded = false
|
|
11
11
|
result.error_message = " expected header identifier --#{header_name}-- to match regex --#{header_value}--\n got --#{@response.headers[header_name]}--"
|
|
12
12
|
end
|
|
13
|
+
elsif is_number_comparison?(header_value)
|
|
14
|
+
if not (excluded?(header_name) or compare_number(header_value, @response.headers[header_name]))
|
|
15
|
+
result.succeeded = false
|
|
16
|
+
result.error_message = " expected header identifier --#{header_name}-- to match number comparison --#{header_value}--\n got --#{@response.headers[header_name]}--"
|
|
17
|
+
end
|
|
13
18
|
else
|
|
14
19
|
if not (excluded?(header_name) or string_matches?(header_value, @response.headers[header_name]))
|
|
15
20
|
result.succeeded = false
|
data/spec/api_runner_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ describe 'apirunner' do
|
|
|
10
10
|
describe 'initialize' do
|
|
11
11
|
it 'should fill all instance variables properly' do
|
|
12
12
|
@a.instance_variable_get(:@spec).should be_a(Array)
|
|
13
|
-
@a.instance_variable_get(:@spec).size.should ==
|
|
13
|
+
@a.instance_variable_get(:@spec).size.should == 165
|
|
14
14
|
@a.instance_variable_get(:@results).should be_a(Array)
|
|
15
15
|
@a.instance_variable_get(:@results).size.should == 0
|
|
16
16
|
@a.instance_variable_get(:@configuration).should be_a(ApiConfiguration)
|
data/spec/checker_spec.rb
CHANGED
|
@@ -34,6 +34,90 @@ describe "Checker" do
|
|
|
34
34
|
Checker.new({},{}).send(:is_regex?, string).should be_false
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
describe "is_number_comparison?" do
|
|
39
|
+
it "should return true when expectation starts with <=, >=, >,<, ==" do
|
|
40
|
+
[">", ">=", "<", "<=", "=="].each do |comp|
|
|
41
|
+
string = "#{comp}4"
|
|
42
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_true
|
|
43
|
+
string = "#{comp} 4"
|
|
44
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_true
|
|
45
|
+
string = "#{comp} 4 "
|
|
46
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should return false when expectation does not start with >,<, =" do
|
|
51
|
+
[">", ">=", "<", "<=", "=="].each do |comp|
|
|
52
|
+
string = "#{comp}hallo"
|
|
53
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
54
|
+
string = "#{comp} hallo"
|
|
55
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
56
|
+
string = "#{comp}"
|
|
57
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
58
|
+
string = "#{comp} 4 hihihihihihi"
|
|
59
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
string = "/hallo/"
|
|
63
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
64
|
+
string = "hallo"
|
|
65
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
66
|
+
string = ""
|
|
67
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
68
|
+
string = nil
|
|
69
|
+
Checker.new({}, {}).send(:is_number_comparison?, string).should be_false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "compare_number" do
|
|
75
|
+
it "should compare lt and lte correctly" do
|
|
76
|
+
Checker.new({}, {}).send(:compare_number, "<4", "5").should be_false
|
|
77
|
+
Checker.new({}, {}).send(:compare_number, "< 4", "5").should be_false
|
|
78
|
+
|
|
79
|
+
Checker.new({}, {}).send(:compare_number, "< 4", "3").should be_true
|
|
80
|
+
Checker.new({}, {}).send(:compare_number, "<4", "3").should be_true
|
|
81
|
+
|
|
82
|
+
Checker.new({}, {}).send(:compare_number, "<=4", "4").should be_true
|
|
83
|
+
Checker.new({}, {}).send(:compare_number, "<= 4", "4").should be_true
|
|
84
|
+
Checker.new({}, {}).send(:compare_number, "<=4", "5").should be_false
|
|
85
|
+
Checker.new({}, {}).send(:compare_number, "<= 4", "5").should be_false
|
|
86
|
+
Checker.new({}, {}).send(:compare_number, "<=4", "3").should be_true
|
|
87
|
+
Checker.new({}, {}).send(:compare_number, "<= 4", "3").should be_true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should compare gt and gte correctly" do
|
|
91
|
+
Checker.new({}, {}).send(:compare_number, ">4", "5").should be_true
|
|
92
|
+
Checker.new({}, {}).send(:compare_number, "> 4", "5").should be_true
|
|
93
|
+
|
|
94
|
+
Checker.new({}, {}).send(:compare_number, "> 4", "3").should be_false
|
|
95
|
+
Checker.new({}, {}).send(:compare_number, ">4", "3").should be_false
|
|
96
|
+
|
|
97
|
+
Checker.new({}, {}).send(:compare_number, ">=4", "4").should be_true
|
|
98
|
+
Checker.new({}, {}).send(:compare_number, ">= 4", "4").should be_true
|
|
99
|
+
Checker.new({}, {}).send(:compare_number, ">=4", "5").should be_true
|
|
100
|
+
Checker.new({}, {}).send(:compare_number, ">= 4", "5").should be_true
|
|
101
|
+
Checker.new({}, {}).send(:compare_number, ">=4", "3").should be_false
|
|
102
|
+
Checker.new({}, {}).send(:compare_number, ">= 4", "3").should be_false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should compare ==" do
|
|
106
|
+
Checker.new({}, {}).send(:compare_number, "==4", "5").should be_false
|
|
107
|
+
Checker.new({}, {}).send(:compare_number, "== 4", "5").should be_false
|
|
108
|
+
|
|
109
|
+
Checker.new({}, {}).send(:compare_number, "==4", "4").should be_true
|
|
110
|
+
Checker.new({}, {}).send(:compare_number, "==4", "4").should be_true
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should return false when it gets unexpected header values" do
|
|
114
|
+
Checker.new({}, {}).send(:compare_number, "==4", nil).should be_false
|
|
115
|
+
Checker.new({}, {}).send(:compare_number, "== 4", "Exception").should be_false
|
|
116
|
+
Checker.new({}, {}).send(:compare_number, "== 4", "q").should be_false
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
37
121
|
describe "regex_matches?" do
|
|
38
122
|
it 'should return true if the given regular expression matches the given value' do
|
|
39
123
|
regex = "^\\d{2}$"
|
data/spec/http_client_spec.rb
CHANGED
|
@@ -34,14 +34,14 @@ describe 'http_client' do
|
|
|
34
34
|
response = raw_response_struct.new
|
|
35
35
|
response.code = 404
|
|
36
36
|
response.message = "Hi Duffy Duck"
|
|
37
|
-
response.
|
|
37
|
+
response.stub!(:to_hash).and_return({ :daisy => ["duck"] })
|
|
38
38
|
response.body = { :duffy => "duck" }
|
|
39
39
|
response.runtime = 0.123456789
|
|
40
40
|
response.fully_qualified_path = "/path/to/resource"
|
|
41
41
|
@http_client.send(:build_response, response, 0.0, "GET", "resource", {}).code.should_not be_nil
|
|
42
42
|
@http_client.send(:build_response, response, 0.0, "GET", "resource", {}).message.should_not be_nil
|
|
43
43
|
@http_client.send(:build_response, response, 0.0, "GET", "resource", {}).body.should == {:duffy => "duck"}
|
|
44
|
-
@http_client.send(:build_response, response, 0.0, "GET", "resource", {}).headers.should == {
|
|
44
|
+
@http_client.send(:build_response, response, 0.0, "GET", "resource", {}).headers.should == {:daisy => "duck"}
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
describe "resource_path" do
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 4
|
|
8
|
-
-
|
|
9
|
-
version: 0.4.
|
|
8
|
+
- 7
|
|
9
|
+
version: 0.4.7
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- jan@moviepilot.com
|
|
@@ -291,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
291
291
|
requirements:
|
|
292
292
|
- - ">="
|
|
293
293
|
- !ruby/object:Gem::Version
|
|
294
|
-
hash:
|
|
294
|
+
hash: -3482657105735188905
|
|
295
295
|
segments:
|
|
296
296
|
- 0
|
|
297
297
|
version: "0"
|