webspicy 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d404dff3afb455b57fea64ddf9b9b7ab90efe6a3
4
- data.tar.gz: 7b101990a2060a96f3281e2effd2cf38839c562b
3
+ metadata.gz: d4aae5afefcdda4fe5593cfc4626bfdb52143c07
4
+ data.tar.gz: 6c0653d7ac94dacb5ea97325cdc696f458b7f73d
5
5
  SHA512:
6
- metadata.gz: 5d6032e474a7d2379a93efbb0193530df7ade3bb1ac55752195bcddbbcc56b52823e7619fa5a371028d61bf8e758b3f40186efea79e71edc13310a01c5e7dc93
7
- data.tar.gz: 44e5f5191c37f58d8c3623a91bab72b1b77a2f379497b77f964242e4ac37bc987220f9d01e4a305bd4e2694ac0e18885159a2a71cec9412ee32c073f060a49a3
6
+ metadata.gz: d013ffd5cc0eb2c1edeb8609709ffe467696d817d6beff6abc2c615697ef3d9686e30422399afb0fbb71180a76e9c6aa94a2f68961cc167e2e23403dfeb15a7f
7
+ data.tar.gz: 19bae47fc5674ab351403e0c338ae4a4b584f68b355aea80f57ed816fadba0e26ad0f53a9dc4f9e998eec05db8b74a9bd2cb1cb30ee98eb3b15261ca8aa8f887
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- webspicy (0.1.0.pre.rc3)
4
+ webspicy (0.2.0)
5
5
  finitio (~> 0.5.2)
6
6
  http (~> 0.5)
7
7
  path (~> 1.3)
@@ -2,16 +2,17 @@ $LOAD_PATH.unshift File.expand_path("..", __FILE__)
2
2
  require 'app'
3
3
  require 'webspicy'
4
4
 
5
- namespace :webspicy do
6
-
7
- task :check do
8
- config = Webspicy::Configuration.new do |c|
9
- c.add_folder Path.dir/"webspicy"
10
- end
11
- Webspicy::Checker.new(config).call
5
+ desc "Checks all .yml definition files"
6
+ task :check do
7
+ config = Webspicy::Configuration.new do |c|
8
+ c.add_folder Path.dir/"webspicy"
12
9
  end
10
+ Webspicy::Checker.new(config).call
11
+ end
13
12
 
14
- task :testrack do
13
+ namespace :test do
14
+ desc "Run all tests directly on Sinatra application using rack/test"
15
+ task :rack do
15
16
  config = Webspicy::Configuration.new do |c|
16
17
  c.add_folder Path.dir/"webspicy"
17
18
  c.client = Webspicy::RackTestClient.for(::Sinatra::Application)
@@ -22,7 +23,8 @@ namespace :webspicy do
22
23
  Webspicy::Tester.new(config).call
23
24
  end
24
25
 
25
- task :testreal do
26
+ desc "Runs all tests on the real web server (must be launched previously)"
27
+ task :real do
26
28
  config = Webspicy::Configuration.new do |c|
27
29
  c.host = "http://127.0.0.1:4567"
28
30
  c.add_folder Path.dir/"webspicy"
@@ -33,8 +35,10 @@ namespace :webspicy do
33
35
  end
34
36
  Webspicy::Tester.new(config).call
35
37
  end
36
-
37
38
  end
38
39
 
39
- task :test => [:"webspicy:check", :"webspicy:testrack"]
40
+ desc "Runs all checks and tests"
41
+ task :test => :check
42
+ task :test => :"test:rack"
43
+
40
44
  task :default => :test
@@ -55,3 +55,16 @@ get '/todo/:id' do |id|
55
55
  todo.to_json
56
56
  end
57
57
  end
58
+
59
+ delete '/todo/:id' do |id|
60
+ content_type :json
61
+ todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
62
+ if todo.nil?
63
+ status 404
64
+ {error: "No such todo"}.to_json
65
+ else
66
+ settings.todolist = settings.todolist.reject{|todo| todo[:id] == Integer(id) }
67
+ status 204
68
+ content_type "text/plain"
69
+ end
70
+ end
@@ -0,0 +1,50 @@
1
+ ---
2
+ name: |-
3
+ Todo
4
+
5
+ url: |-
6
+ /todo/{id}
7
+
8
+ services:
9
+ - method: |-
10
+ DELETE
11
+
12
+ description: |-
13
+ Deletes a single todo item
14
+
15
+ preconditions: |-
16
+
17
+ input_schema: |-
18
+ {
19
+ id: Integer
20
+ }
21
+
22
+ output_schema: |-
23
+ .
24
+
25
+ error_schema: |-
26
+ {
27
+ error: String
28
+ }
29
+
30
+ examples:
31
+
32
+ - description: |-
33
+ when requested on an existing TODO
34
+ params:
35
+ id: 1
36
+ expected:
37
+ content_type: ~
38
+ status: 204
39
+
40
+ counterexamples:
41
+
42
+ - description: |-
43
+ when requested on an unexisting TODO
44
+ params:
45
+ id: 999254654
46
+ expected:
47
+ content_type: application/json
48
+ status: 404
49
+ assert:
50
+ - "pathFD('', error: 'No such todo')"
@@ -56,6 +56,15 @@ module Webspicy
56
56
  Webspicy.debug("Response: #{@last_response.body}")
57
57
  end
58
58
 
59
+ def delete(url, params = {}, headers = nil)
60
+ Webspicy.info("DELETE #{url} -- #{params.inspect}")
61
+
62
+ @last_response = HTTP[headers || {}].delete(url, body: params.to_json)
63
+
64
+ Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
65
+ Webspicy.debug("Response: #{@last_response.body}")
66
+ end
67
+
59
68
  end
60
69
 
61
70
  end
@@ -91,6 +91,17 @@ module Webspicy
91
91
  Webspicy.debug("Response: #{@last_response.body}")
92
92
  end
93
93
 
94
+ def delete(url, params = {}, headers = nil)
95
+ Webspicy.info("DELETE #{url} -- #{params.inspect}")
96
+
97
+ install_headers(headers) if headers
98
+ handler.delete(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
99
+ @last_response = handler.last_response
100
+
101
+ Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
102
+ Webspicy.debug("Response: #{@last_response.body}")
103
+ end
104
+
94
105
  private
95
106
 
96
107
  def install_headers(hs)
@@ -37,7 +37,7 @@ TestCase =
37
37
  requester :? String
38
38
  expected: {
39
39
  status : Integer
40
- content_type :? String
40
+ content_type :? String|Nil
41
41
  error :? String
42
42
  headers :? .Hash
43
43
  }
@@ -58,8 +58,12 @@ module Webspicy
58
58
  def expected_content_type_unmet
59
59
  ect = test_case.expected_content_type
60
60
  got = response.content_type
61
- got = got.mime_type.to_s if got.respond_to?(:mime_type)
62
- ect == got ? nil : "#{ect} != #{got}"
61
+ got = got.mime_type if got.respond_to?(:mime_type)
62
+ if ect.nil?
63
+ got.nil? ? nil : "#{ect} != #{got}"
64
+ else
65
+ ect.to_s == got.to_s ? nil : "#{ect} != #{got}"
66
+ end
63
67
  end
64
68
 
65
69
  def meets_expected_content_type?
@@ -33,7 +33,7 @@ module Webspicy
33
33
  end
34
34
 
35
35
  def expected_content_type
36
- @raw[:expected][:content_type] || 'application/json'
36
+ @raw[:expected].fetch(:content_type){ 'application/json' }
37
37
  end
38
38
 
39
39
  def expected_status
@@ -1,7 +1,7 @@
1
1
  module Webspicy
2
2
  module Version
3
3
  TINY = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  MAJOR = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -123,6 +123,7 @@ files:
123
123
  - examples/restful/Rakefile
124
124
  - examples/restful/app.rb
125
125
  - examples/restful/webspicy/schema.fio
126
+ - examples/restful/webspicy/todo/deleteTodo.yml
126
127
  - examples/restful/webspicy/todo/getTodo.yml
127
128
  - examples/restful/webspicy/todo/getTodos.yml
128
129
  - examples/restful/webspicy/todo/postTodos.yml