cucumber-rest-api 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2919988920dfbf95c04f1eff5ac0da636e6511c
4
- data.tar.gz: c8f94e16217deda646354635b025ed1dcb734f5d
3
+ metadata.gz: 4a3fa8e3d3f088998463154ab371d40b9b6719be
4
+ data.tar.gz: d8ad2eed12586feb88d878cab626c12a42e1eccf
5
5
  SHA512:
6
- metadata.gz: 9c9843b9ee3cad6c3f0aebac78e9c4c9264b7b5118b1c5f23df16317aa4263aeb8d962c88026dab78066b1e2875deefbc578859004080978914c183bd2ba7753
7
- data.tar.gz: 6a51d0c477d986489bec6aa0c749e1ee05cd620edeb407eccf6804262c17ad5ae3f6a18b421b7a67111deebfaf4db33f8b4f3f0e0494f5f0b65743650dd73b21
6
+ metadata.gz: ebb5e478362dbfc9f6c55f6fe2e74280bc1c8821ab627e74835088c68a1dbd05a4cf12635cb6593e5f4afd5d8ce91cddc2b5e150bf71a22fd1618ba7dc03c6cd
7
+ data.tar.gz: 4b85cc347b607e1e8d8f9127b9aab59587785324ea3a6ebd8cdedd9862d38c642046b10032ff0ba41a79e6cb714ab3f96893c63316ec65033f7d1f8b13d90c90
@@ -146,12 +146,6 @@ Then /^the JSON response should be:$/ do |json|
146
146
  end
147
147
  end
148
148
 
149
- Then(/^the JSON should have "(.*)" elements$/) do |element|
150
- json = JSON.parse(last_response.body)
151
- total_elements = json.count
152
- total_elements.should == element.to_i
153
- end
154
-
155
149
  Then /^the JSON response should have "([^"]*)" with a length of (\d+)$/ do |json_path, length|
156
150
  json = JSON.parse(last_response.body)
157
151
  results = JsonPath.new(json_path).on(json)
@@ -22,23 +22,23 @@ class Object
22
22
  @headers[key] = value
23
23
  end
24
24
 
25
+ def last_response
26
+ return @response
27
+ end
28
+
25
29
  def request path,request_opts
26
30
  req = "#{$SERVER_PATH}" + path
27
-
28
31
  uri = URI.parse(req)
29
- http = Net::HTTP.new(uri.host, uri.port)
30
-
32
+ http = Net::HTTP.new(uri.host, uri.port)
33
+
31
34
  if request_opts[:method] == :post
32
- request = Net::HTTP::Post.new(uri.request_uri)
33
-
34
- body = nil
35
- if request_opts[:params]
36
- body = request_opts[:params].to_json
37
- else
38
- body = request_opts[:input]
39
- end
40
- else
41
- request = Net::HTTP::Get.new(uri.request_uri)
35
+ request, body = send_post_request(uri, request_opts)
36
+ elsif request_opts[:method] == :put
37
+ request, body = perform_put_request(uri, request_opts)
38
+ elsif request_opts[:method] == :get
39
+ request = send_get_request(uri, request_opts)
40
+ elsif request_opts[:method] == :delete
41
+ request = perform_delete_request(uri, request_opts)
42
42
  end
43
43
 
44
44
  #do we have any headers to add?
@@ -46,12 +46,41 @@ class Object
46
46
  @headers.each { |k,v| request.add_field(k, v) }
47
47
  @headers = nil
48
48
  end
49
-
50
49
  @response = http.request(request,body)
51
50
  end
52
51
 
53
- def last_response
54
- return @response
52
+
53
+ def send_post_request uri,request_opts
54
+ request = Net::HTTP::Post.new(uri.request_uri)
55
+ body = nil
56
+ if request_opts[:params]
57
+ body = request_opts[:params].to_json
58
+ else
59
+ body = request_opts[:input]
60
+ end
61
+ return request, body
62
+ end
63
+
64
+ def perform_put_request uri,request_opts
65
+ request = Net::HTTP::Put.new(uri.request_uri)
66
+ body = nil
67
+ if request_opts[:params]
68
+ body = request_opts[:params].to_json
69
+ else
70
+ body = request_opts[:input]
71
+ end
72
+ return request, body
73
+ end
74
+
75
+ def send_get_request uri,request_opts
76
+ request = Net::HTTP::Get.new(uri.request_uri)
77
+ return request
78
+ end
79
+
80
+
81
+ def perform_delete_request uri,request_opts
82
+ request = Net::HTTP::Delete.new(uri.request_uri)
83
+ return request
55
84
  end
56
85
 
57
- end
86
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-rest-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anupama Vijaykumar,Nic Jackson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonpath