apirunner 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/VERSION +1 -1
- data/apirunner.gemspec +9 -2
- data/lib/api_runner.rb +23 -4
- data/lib/expectation_matcher.rb +1 -2
- data/lib/http_client.rb +3 -1
- data/spec/api_runner_spec.rb +68 -0
- data/spec/expectation_matcher_spec.rb +221 -0
- data/spec/http_client_spec.rb +47 -0
- metadata +33 -14
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -20,6 +20,8 @@ GEM
|
|
20
20
|
git (>= 1.2.5)
|
21
21
|
rake
|
22
22
|
json_pure (1.4.6)
|
23
|
+
mocha (0.9.8)
|
24
|
+
rake
|
23
25
|
nokogiri (1.4.3.1)
|
24
26
|
rake (0.8.7)
|
25
27
|
rcov (0.9.9)
|
@@ -44,6 +46,7 @@ DEPENDENCIES
|
|
44
46
|
cucumber
|
45
47
|
httparty (~> 0.6.1)
|
46
48
|
jeweler (~> 1.5.0.pre3)
|
49
|
+
mocha (>= 0.9.8)
|
47
50
|
nokogiri (~> 1.4.3.1)
|
48
51
|
rcov
|
49
52
|
rspec (>= 2.0.0.beta.19)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
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.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["moviepilot"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-21}
|
13
13
|
s.description = %q{longer description of your gem}
|
14
14
|
s.email = %q{developers@moviepilot.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,7 +40,9 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/http_client.rb",
|
41
41
|
"lib/tasks/api.rake",
|
42
42
|
"spec/.rspec",
|
43
|
+
"spec/api_runner_spec.rb",
|
43
44
|
"spec/expectation_matcher_spec.rb",
|
45
|
+
"spec/http_client_spec.rb",
|
44
46
|
"spec/spec_helper.rb"
|
45
47
|
]
|
46
48
|
s.homepage = %q{http://github.com/moviepilot/apirunner}
|
@@ -48,7 +50,9 @@ Gem::Specification.new do |s|
|
|
48
50
|
s.rubygems_version = %q{1.3.7}
|
49
51
|
s.summary = %q{one-line summary of your gem}
|
50
52
|
s.test_files = [
|
53
|
+
"spec/api_runner_spec.rb",
|
51
54
|
"spec/expectation_matcher_spec.rb",
|
55
|
+
"spec/http_client_spec.rb",
|
52
56
|
"spec/spec_helper.rb"
|
53
57
|
]
|
54
58
|
|
@@ -64,6 +68,7 @@ Gem::Specification.new do |s|
|
|
64
68
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
69
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
66
70
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
67
72
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
68
73
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
69
74
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -77,6 +82,7 @@ Gem::Specification.new do |s|
|
|
77
82
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
83
|
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
79
84
|
s.add_dependency(%q<rcov>, [">= 0"])
|
85
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
80
86
|
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
81
87
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
82
88
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -91,6 +97,7 @@ Gem::Specification.new do |s|
|
|
91
97
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
92
98
|
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
93
99
|
s.add_dependency(%q<rcov>, [">= 0"])
|
100
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
94
101
|
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
95
102
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
96
103
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
data/lib/api_runner.rb
CHANGED
@@ -3,9 +3,13 @@ class ApiRunner
|
|
3
3
|
require 'expectation_matcher'
|
4
4
|
require 'http_client'
|
5
5
|
|
6
|
+
CONFIG_FILE = "config/api_runner.yml"
|
7
|
+
SPEC_PATH = "test/api_runner/"
|
8
|
+
EXCLUDES_FILE = "test/api_runner/excludes.yml"
|
9
|
+
|
6
10
|
# initializes the object, loads environment, build base_uri
|
7
11
|
def initialize(env)
|
8
|
-
@
|
12
|
+
@http_client = HttpClient.new
|
9
13
|
@spec = []
|
10
14
|
@errors = []
|
11
15
|
@excludes = []
|
@@ -63,13 +67,13 @@ class ApiRunner
|
|
63
67
|
|
64
68
|
# loads environment config data from yaml file
|
65
69
|
def load_config(env)
|
66
|
-
config = YAML.load_file(
|
70
|
+
config = YAML.load_file(self.class.config_file)
|
67
71
|
config[env.to_s].each { |key, value| instance_variable_set("@#{key}", value) }
|
68
72
|
end
|
69
73
|
|
70
74
|
# loads spec cases from yaml files
|
71
75
|
def load_url_spec
|
72
|
-
path =
|
76
|
+
path = self.class.spec_path
|
73
77
|
Dir.new(path).entries.each do |dir_entry|
|
74
78
|
@spec.push *YAML.load_file(path+dir_entry) if not (File.directory? dir_entry or dir_entry.match(/^\./) or dir_entry.match(/excludes/))
|
75
79
|
end
|
@@ -77,8 +81,23 @@ class ApiRunner
|
|
77
81
|
|
78
82
|
# loads and parses items that need to be excluded from the checks in certain environments
|
79
83
|
def load_excludes(env)
|
80
|
-
excludes_file =
|
84
|
+
excludes_file = self.class.excludes_file
|
81
85
|
@excludes = YAML.load_file(excludes_file).detect{ |a| a.first == env.to_s }[1]["excludes"]
|
82
86
|
end
|
87
|
+
|
88
|
+
# returns config files path and can be stubbed this way
|
89
|
+
def self.config_file
|
90
|
+
CONFIG_FILE
|
91
|
+
end
|
92
|
+
|
93
|
+
# returns path to spec files that can be stubbed for tests
|
94
|
+
def self.spec_path
|
95
|
+
SPEC_PATH
|
96
|
+
end
|
97
|
+
|
98
|
+
# returns excludes file path that can be stubbed
|
99
|
+
def self.excludes_file
|
100
|
+
EXCLUDES_FILE
|
101
|
+
end
|
83
102
|
end
|
84
103
|
|
data/lib/expectation_matcher.rb
CHANGED
@@ -3,7 +3,7 @@ class ExpectationMatcher
|
|
3
3
|
|
4
4
|
def initialize(excludes=nil)
|
5
5
|
@test_types = [:response_code, :response_body_format, :response_headers, :response_body]
|
6
|
-
@excludes = excludes
|
6
|
+
@excludes = excludes || []
|
7
7
|
end
|
8
8
|
|
9
9
|
# returns the available test types if this matcher class
|
@@ -145,7 +145,6 @@ class ExpectationMatcher
|
|
145
145
|
|
146
146
|
# returns true if the given regular expression matches the given value
|
147
147
|
def regex_matches?(regex, value)
|
148
|
-
debugger
|
149
148
|
regex = Regexp.compile( regex.gsub(/^\//, '').gsub(/\/$/,'') )
|
150
149
|
!!value.to_s.match(regex)
|
151
150
|
end
|
data/lib/http_client.rb
CHANGED
@@ -4,9 +4,11 @@ class HttpClient
|
|
4
4
|
|
5
5
|
# sends http request with given method, uri and data and returns servers response
|
6
6
|
def send_request(method, uri, data=nil)
|
7
|
-
build_response(self.class.send(method, uri, data))
|
7
|
+
build_response(self.class.send(method, uri, data ||= {}))
|
8
8
|
end
|
9
9
|
|
10
|
+
protected
|
11
|
+
|
10
12
|
# returns struct containing response.code, headers, body and message
|
11
13
|
# this is only for easily interfaceing another http client
|
12
14
|
def build_response(raw_response)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'apirunner' do
|
4
|
+
before(:each) do
|
5
|
+
ApiRunner.stub(:config_file).and_return("examples/config/api_runner.yml")
|
6
|
+
ApiRunner.stub(:excludes_file).and_return("examples/test/api_runner/excludes.yml")
|
7
|
+
ApiRunner.stub(:spec_path).and_return("examples/test/api_runner/")
|
8
|
+
@a = ApiRunner.new(:local)
|
9
|
+
end
|
10
|
+
describe 'initialize' do
|
11
|
+
it 'should fill all instance variables' do
|
12
|
+
@a.instance_variable_get(:@protocol).should eql "http"
|
13
|
+
@a.instance_variable_get(:@host).should eql "localhost"
|
14
|
+
@a.instance_variable_get(:@port).should eql 3000
|
15
|
+
@a.instance_variable_get(:@namespace).should eql "api1v0"
|
16
|
+
end
|
17
|
+
it 'should fill @excludes' do
|
18
|
+
@a.instance_variable_get(:@excludes).should_not be_nil
|
19
|
+
@a.instance_variable_get(:@excludes).should be_a(Array)
|
20
|
+
@a.instance_variable_get(:@excludes).include?("content-length").should be_true
|
21
|
+
@a.instance_variable_get(:@excludes).include?("notthere").should be_false
|
22
|
+
end
|
23
|
+
it 'should fill @spec'
|
24
|
+
it 'should instantiate an http client into @http_client' do
|
25
|
+
@a.instance_variable_get(:@http_client).should be_a(HttpClient)
|
26
|
+
end
|
27
|
+
it 'should instantiate an expectation_matcher into @expectation' do
|
28
|
+
@a.instance_variable_get(:@expectation).should be_a(ExpectationMatcher)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'run_tests' do
|
33
|
+
it 'should send a request for every given testcase'
|
34
|
+
it 'should run a test for every test_type'
|
35
|
+
it 'should output an "F" if an error occured'
|
36
|
+
it 'should save an error message in @errors if an error occured'
|
37
|
+
it 'should output a "." if all test_types of a certain test_case passed'
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'send_request' do
|
41
|
+
it 'should invoke send_request at the @http_client with the appropiate method, uri and data'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'target_uri' do
|
45
|
+
it 'should create a correct target uri from existing instance variables'
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'server_is_available?' do
|
49
|
+
it 'should return true if the requested server is available'
|
50
|
+
it 'should return false if the given server is not available'
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'load_config' do
|
54
|
+
it 'should load the configuration from a YAML file'
|
55
|
+
it 'should put the config into certain instance variables'
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'load_url_spec' do
|
59
|
+
it 'should load the URL spec from a YAML file'
|
60
|
+
it 'should create an array of test_cases in @spec instance variable'
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'load_excludes' do
|
64
|
+
it 'should load the excludes from a yaml file'
|
65
|
+
it 'should populate @excludes instance variable with the excludes from the YAML file'
|
66
|
+
it 'should make sure that @excludes is an array'
|
67
|
+
end
|
68
|
+
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'json'
|
3
|
+
require 'nokogiri'
|
2
4
|
|
3
5
|
describe 'ExpectationMatcher' do
|
6
|
+
before(:each) do
|
7
|
+
@em = ExpectationMatcher.new
|
8
|
+
end
|
4
9
|
describe 'regex_matches?' do
|
5
10
|
it 'should return true if given regex matches the given string' do
|
6
11
|
ExpectationMatcher.new.send(:regex_matches?, "/^\\d{2}$/", "12").should be_true
|
@@ -9,5 +14,221 @@ describe 'ExpectationMatcher' do
|
|
9
14
|
ExpectationMatcher.new.send(:regex_matches?, "/^\\d{2}$/", "133").should be_false
|
10
15
|
end
|
11
16
|
end
|
17
|
+
|
18
|
+
describe 'testtypes' do
|
19
|
+
it 'should return the available testtypes of the class' do
|
20
|
+
@em.test_types.should eql ([:response_code, :response_body_format, :response_headers, :response_body])
|
21
|
+
end
|
22
|
+
it 'should at least return one testtype' do
|
23
|
+
@em.test_types.size.should >= 1
|
24
|
+
end
|
25
|
+
it 'should return an array of symbols' do
|
26
|
+
@em.test_types.should be_a(Array)
|
27
|
+
@em.test_types.each do |type|
|
28
|
+
type.should be_a(Symbol)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
it 'should not return nil' do
|
32
|
+
@em.test_types.should_not be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'check' do
|
37
|
+
it 'should invoke http client with the given method, response and testcase' do
|
38
|
+
@em = ExpectationMatcher.new
|
39
|
+
@em.should_receive(:put)
|
40
|
+
@em.check(:put, {}, [])
|
41
|
+
@em.should_receive(:post)
|
42
|
+
@em.check(:post, {}, [])
|
43
|
+
@em.should_receive(:get)
|
44
|
+
@em.check(:get, {}, [])
|
45
|
+
@em.should_receive(:delete)
|
46
|
+
@em.check(:delete, {}, [])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'response_code' do
|
51
|
+
it 'should return a struct representing success if the given response code matches the expected one' do
|
52
|
+
response_struct = Struct.new(:code, :message, :headers, :body)
|
53
|
+
response = response_struct.new
|
54
|
+
response.code = 404
|
55
|
+
testcase = { 'response_expectation' => { 'status_code' => 404 } }
|
56
|
+
@em.send(:response_code, response, testcase).should be_a(Struct)
|
57
|
+
@em.send(:response_code, response, testcase).succeeded.should be_true
|
58
|
+
@em.send(:response_code, response, testcase).error.should be_nil
|
59
|
+
end
|
60
|
+
it 'should return a struct representing failure if the given repsonse code does not match the expected one' do
|
61
|
+
response_struct = Struct.new(:code, :message, :headers, :body)
|
62
|
+
response = response_struct.new
|
63
|
+
response.code = 400
|
64
|
+
testcase = { 'response_expectation' => { 'status_code' => 404 } }
|
65
|
+
@em.send(:response_code, response, testcase).should be_a(Struct)
|
66
|
+
@em.send(:response_code, response, testcase).succeeded.should be_false
|
67
|
+
@em.send(:response_code, response, testcase).error.should_not be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'response_body_format' do
|
72
|
+
before(:each) do
|
73
|
+
response_struct = Struct.new(:code, :message, :headers, :body)
|
74
|
+
@response = response_struct.new
|
75
|
+
end
|
76
|
+
it 'should return a struct representing success if the given response body is nil, cause this is allowed' do
|
77
|
+
@response.body = nil
|
78
|
+
@em.send(:response_body_format, @response, {}).should be_a(Struct)
|
79
|
+
@em.send(:response_body_format, @response, {}).succeeded.should be_true
|
80
|
+
@em.send(:response_body_format, @response, {}).error.should be_nil
|
81
|
+
end
|
82
|
+
it 'should return the given response body in JSON format, if a valid JSON string is given to check' do
|
83
|
+
@response.body = {:fooz => "baaz"}.to_json
|
84
|
+
@em.send(:response_body_format, @response, {}).should be_a(Struct)
|
85
|
+
@em.send(:response_body_format, @response, {}).succeeded.should be_true
|
86
|
+
@em.send(:response_body_format, @response, {}).error.should be_nil
|
87
|
+
end
|
88
|
+
it 'should not fatal but return false, if the given response body is no valid JSON' do
|
89
|
+
@response.body = "foozbaz"
|
90
|
+
@em.send(:response_body_format, @response, {}).should be_a(Struct)
|
91
|
+
@em.send(:response_body_format, @response, {}).succeeded.should be_false
|
92
|
+
@em.send(:response_body_format, @response, {}).error.should_not be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'response_headers' do
|
97
|
+
before(:each) do
|
98
|
+
response_struct = Struct.new(:code, :message, :headers, :body)
|
99
|
+
@response = response_struct.new
|
100
|
+
end
|
101
|
+
it 'should return a struct representing success, if one certain expected header value matches the response header' do
|
102
|
+
pending "TODO:pair this one"
|
103
|
+
@response.headers = {"content-type"=>["text/html; charset=utf-8"], "cache-control"=>["no-cache"], "x-runtime"=>["0.340116"], "server"=>["WEBrick/1.3.1 (Ruby/1.9.2/2010-08-18)"], "date"=>["Tue, 21 Sep 2010 11:33:05 GMT"], "content-length"=>["149"], "connection"=>["close"], "Last-Modified" => "2010-10-01 23:23:23"}
|
104
|
+
testcase = { 'response_expectation' => { 'headers' => {"Last-Modified"=>"/.*/"} } }
|
105
|
+
@em.send(:response_headers, @response, testcase).should be_a(Struct)
|
106
|
+
@em.send(:response_headers, @response, testcase).succeeded.should be_true
|
107
|
+
@em.send(:response_headers, @response, testcase).error.should be_nil
|
108
|
+
end
|
109
|
+
it 'should return a struct representing success, if more than one expected header values match the ones in the repsonse header' do
|
110
|
+
pending "TODO: pair this one"
|
111
|
+
end
|
112
|
+
it 'should even return a struct representing success if the response header contains more values than the excpected' do
|
113
|
+
pending "TODO: pair this one"
|
114
|
+
end
|
115
|
+
it 'should return a struct representing an error, if one single expected header value does not match the one in response' do
|
116
|
+
pending "TODO: pair this one"
|
117
|
+
end
|
118
|
+
it 'should return a struct representing an error, if one of more expected header values does not match the corresponding one in the response' do
|
119
|
+
pending "TODO: pair this one"
|
120
|
+
end
|
121
|
+
it 'should return a struct representing success, if the expected header is nil - no expectation exists' do
|
122
|
+
pending "TODO: pair this one"
|
123
|
+
testcase = { 'response_expectation' => { 'headers' => nil } }
|
124
|
+
@em.send(:response_headers, @response, testcase).should be_a(Struct)
|
125
|
+
@em.send(:response_headers, @response, testcase).succeeded.should be_true
|
126
|
+
@em.send(:response_headers, @response, testcase).error.should be_nil
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'response_body' do
|
131
|
+
it 'should check something'
|
132
|
+
it 'should return a result struct'
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'matcher_pathes_from' do
|
136
|
+
it 'should return pathes to all leaves of a given tree including relative pathes in case of arrays in the JSON' do
|
137
|
+
xml_tree = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hash><bla>laber</bla><foo><values type=\"array\"><value><a>1</a></value><value><b type=\"integer\">2</b></value><value><c>/.*/</c></value></values></foo><bar>baz</bar></hash>"
|
138
|
+
tree = Nokogiri::XML(xml_tree)
|
139
|
+
@em.send(:matcher_pathes_from, tree).should be_a(Array)
|
140
|
+
@em.send(:matcher_pathes_from, tree).include?("/hash/bla").should be_true
|
141
|
+
@em.send(:matcher_pathes_from, tree).include?("/hash/foo/values/*/a").should be_true
|
142
|
+
@em.send(:matcher_pathes_from, tree).include?("/hash/foo/values/*/b").should be_true
|
143
|
+
@em.send(:matcher_pathes_from, tree).include?("/hash/foo/values/*/c").should be_true
|
144
|
+
@em.send(:matcher_pathes_from, tree).include?("/hash/bar").should be_true
|
145
|
+
@em.send(:matcher_pathes_from, tree).each do |path|
|
146
|
+
path.should be_a(String)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'relative_path' do
|
152
|
+
it 'should substitute an absolute addressing in a given path' do
|
153
|
+
path = "/bla/foo/values[6]/duffy/duck"
|
154
|
+
@em.send(:relative_path, path).should eql "/bla/foo/*/duffy/duck"
|
155
|
+
end
|
156
|
+
it 'should substitute more than one absolute adressing in a given path' do
|
157
|
+
path = "/bla/foo/values[6]/duffy/friends[1]/duck"
|
158
|
+
@em.send(:relative_path, path).should eql "/bla/foo/*/duffy/*/duck"
|
159
|
+
end
|
160
|
+
it 'should return a string' do
|
161
|
+
path = "/bla/foo/values[6]/duffy/friends[1]/duck"
|
162
|
+
@em.send(:relative_path, path).should be_a(String)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'excluded?' do
|
167
|
+
before(:each) do
|
168
|
+
@em = ExpectationMatcher.new(['foo', 'bar'])
|
169
|
+
end
|
170
|
+
it 'should return true if the given string is present in the @excludes instance variable of the class' do
|
171
|
+
@em.send(:excluded?, 'foo').should be_true
|
172
|
+
end
|
173
|
+
it 'should return false if the given string is not present in the @excludes instance variable of the class' do
|
174
|
+
@em.send(:excluded?, 'fooz').should be_false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe 'is_regex?' do
|
179
|
+
it 'should return true if the given string seems to be a regular expression' do
|
180
|
+
string = "/^\d{3}$/"
|
181
|
+
@em.send(:is_regex?, string).should be_true
|
182
|
+
end
|
183
|
+
it 'should return false if the given string does not seem to be a regular expression' do
|
184
|
+
string = "fooz"
|
185
|
+
@em.send(:is_regex?, string).should be_false
|
186
|
+
string = "/fooz"
|
187
|
+
@em.send(:is_regex?, string).should be_false
|
188
|
+
string = "fooz/"
|
189
|
+
@em.send(:is_regex?, string).should be_false
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe 'regex_matches?' do
|
194
|
+
it 'should return true if the given regular expression matches the given value' do
|
195
|
+
regex = "^\\d{2}$"
|
196
|
+
value = "12"
|
197
|
+
@em.send(:regex_matches?, regex, value).should be_true
|
198
|
+
end
|
199
|
+
it 'should return false if the giveb reular expression does not match the given value' do
|
200
|
+
regex = "^\\d{2}$"
|
201
|
+
value = "123"
|
202
|
+
@em.send(:regex_matches?, regex, value).should be_false
|
203
|
+
value = "foo"
|
204
|
+
@em.send(:regex_matches?, regex, value).should be_false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe 'string_matches?' do
|
209
|
+
it 'should return true if the given string matches the given value' do
|
210
|
+
string = "bar"
|
211
|
+
value = "bar"
|
212
|
+
@em.send(:string_matches?, string, value).should be_true
|
213
|
+
end
|
214
|
+
it 'should return false if the given string does not match the given value' do
|
215
|
+
string = "bar"
|
216
|
+
value = "foo"
|
217
|
+
@em.send(:string_matches?, string, value).should be_false
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe 'valid_json?' do
|
222
|
+
it 'should return true if the given response body consists of valid JSON' do
|
223
|
+
validateable = { :foo => "bar" }.to_json
|
224
|
+
@em.send(:valid_json?, validateable).should be_true
|
225
|
+
end
|
226
|
+
it 'should return true if the given response body is nil' do
|
227
|
+
@em.send(:valid_json?, nil).should be_true
|
228
|
+
end
|
229
|
+
it 'should return false if the given response body consists of anything else but valid JSON' do
|
230
|
+
@em.send(:valid_json?, "foobar").should be_false
|
231
|
+
end
|
232
|
+
end
|
12
233
|
end
|
13
234
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'http_client' do
|
4
|
+
before(:each) do
|
5
|
+
@http_client = HttpClient.new
|
6
|
+
any_response = Struct.new(:code, :message, :headers, :body)
|
7
|
+
@response = any_response.new(:code => 200, :message => "Ok", :headers => {:foo => ["baz" => "bar"], :body => {:a => "b"}})
|
8
|
+
end
|
9
|
+
describe 'send_request' do
|
10
|
+
it 'should invoke a send request in the underlying http class with the given method, uri and data' do
|
11
|
+
@http_client.class.should_receive(:put)
|
12
|
+
@http_client.should_receive(:build_response).and_return(@response)
|
13
|
+
@http_client.send_request(:put, "http://foo.bar", nil)
|
14
|
+
|
15
|
+
@http_client.class.should_receive(:get)
|
16
|
+
@http_client.should_receive(:build_response).and_return(@response)
|
17
|
+
@http_client.send_request(:get, "http://foo.bar", nil)
|
18
|
+
end
|
19
|
+
it 'should invoke build response and return its output to the caller' do
|
20
|
+
@http_client.should_receive(:build_response).and_return("response")
|
21
|
+
@http_client.send_request(:put, "http://foo.bar", nil).should eql "response"
|
22
|
+
end
|
23
|
+
it 'should not fatal if expected data attribute is nil' do
|
24
|
+
pending "TODO: pair this one"
|
25
|
+
@http_client.should_receive(:build_response).and_return(@response)
|
26
|
+
@http_client.send_request(:put, "http://foo.bar", nil).should_not raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'build_response' do
|
31
|
+
it 'should return a struct consisting of 4 symbols: :code, :message, :headers and :body with right types' do
|
32
|
+
raw_response_struct = Struct.new(:code, :message, :headers, :body)
|
33
|
+
response = raw_response_struct.new
|
34
|
+
|
35
|
+
response.code = 404
|
36
|
+
response.message = "Hi Duffy Duck"
|
37
|
+
response.headers = { :foo => ["bar" => "baz"] }
|
38
|
+
response.body = { :duffy => "duck" }
|
39
|
+
|
40
|
+
@http_client.send(:build_response, response).to_s.should eql response.to_s
|
41
|
+
@http_client.send(:build_response, response).code.should_not be_nil
|
42
|
+
@http_client.send(:build_response, response).message.should_not be_nil
|
43
|
+
@http_client.send(:build_response, response).body.should_not be_nil
|
44
|
+
@http_client.send(:build_response, response).headers.should_not be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- moviepilot
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-21 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -123,8 +123,23 @@ dependencies:
|
|
123
123
|
prerelease: false
|
124
124
|
version_requirements: *id007
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: mocha
|
127
127
|
requirement: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
- 9
|
135
|
+
- 8
|
136
|
+
version: 0.9.8
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rspec
|
142
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
128
143
|
none: false
|
129
144
|
requirements:
|
130
145
|
- - ">="
|
@@ -138,10 +153,10 @@ dependencies:
|
|
138
153
|
version: 2.0.0.beta.19
|
139
154
|
type: :development
|
140
155
|
prerelease: false
|
141
|
-
version_requirements: *
|
156
|
+
version_requirements: *id009
|
142
157
|
- !ruby/object:Gem::Dependency
|
143
158
|
name: cucumber
|
144
|
-
requirement: &
|
159
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
145
160
|
none: false
|
146
161
|
requirements:
|
147
162
|
- - ">="
|
@@ -151,10 +166,10 @@ dependencies:
|
|
151
166
|
version: "0"
|
152
167
|
type: :development
|
153
168
|
prerelease: false
|
154
|
-
version_requirements: *
|
169
|
+
version_requirements: *id010
|
155
170
|
- !ruby/object:Gem::Dependency
|
156
171
|
name: bundler
|
157
|
-
requirement: &
|
172
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
158
173
|
none: false
|
159
174
|
requirements:
|
160
175
|
- - ~>
|
@@ -166,10 +181,10 @@ dependencies:
|
|
166
181
|
version: 1.0.0
|
167
182
|
type: :development
|
168
183
|
prerelease: false
|
169
|
-
version_requirements: *
|
184
|
+
version_requirements: *id011
|
170
185
|
- !ruby/object:Gem::Dependency
|
171
186
|
name: jeweler
|
172
|
-
requirement: &
|
187
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
173
188
|
none: false
|
174
189
|
requirements:
|
175
190
|
- - ~>
|
@@ -182,10 +197,10 @@ dependencies:
|
|
182
197
|
version: 1.5.0.pre3
|
183
198
|
type: :development
|
184
199
|
prerelease: false
|
185
|
-
version_requirements: *
|
200
|
+
version_requirements: *id012
|
186
201
|
- !ruby/object:Gem::Dependency
|
187
202
|
name: rcov
|
188
|
-
requirement: &
|
203
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
189
204
|
none: false
|
190
205
|
requirements:
|
191
206
|
- - ">="
|
@@ -195,7 +210,7 @@ dependencies:
|
|
195
210
|
version: "0"
|
196
211
|
type: :development
|
197
212
|
prerelease: false
|
198
|
-
version_requirements: *
|
213
|
+
version_requirements: *id013
|
199
214
|
description: longer description of your gem
|
200
215
|
email: developers@moviepilot.com
|
201
216
|
executables: []
|
@@ -229,7 +244,9 @@ files:
|
|
229
244
|
- lib/http_client.rb
|
230
245
|
- lib/tasks/api.rake
|
231
246
|
- spec/.rspec
|
247
|
+
- spec/api_runner_spec.rb
|
232
248
|
- spec/expectation_matcher_spec.rb
|
249
|
+
- spec/http_client_spec.rb
|
233
250
|
- spec/spec_helper.rb
|
234
251
|
has_rdoc: true
|
235
252
|
homepage: http://github.com/moviepilot/apirunner
|
@@ -245,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
262
|
requirements:
|
246
263
|
- - ">="
|
247
264
|
- !ruby/object:Gem::Version
|
248
|
-
hash: -
|
265
|
+
hash: -1063302093406786431
|
249
266
|
segments:
|
250
267
|
- 0
|
251
268
|
version: "0"
|
@@ -265,5 +282,7 @@ signing_key:
|
|
265
282
|
specification_version: 3
|
266
283
|
summary: one-line summary of your gem
|
267
284
|
test_files:
|
285
|
+
- spec/api_runner_spec.rb
|
268
286
|
- spec/expectation_matcher_spec.rb
|
287
|
+
- spec/http_client_spec.rb
|
269
288
|
- spec/spec_helper.rb
|