webspicy 0.1.0.pre.rc3 → 0.1.0.pre.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/restful/Gemfile.lock +4 -1
- data/examples/restful/Rakefile +26 -7
- data/examples/restful/app.rb +12 -4
- data/lib/webspicy/client/http_client.rb +12 -20
- data/lib/webspicy/client/rack_test_client.rb +105 -0
- data/lib/webspicy/client.rb +1 -0
- data/lib/webspicy/configuration.rb +21 -2
- data/lib/webspicy/resource/service/invocation.rb +15 -4
- data/lib/webspicy/version.rb +1 -1
- data/lib/webspicy.rb +2 -0
- data/spec/unit/test_configuration.rb +34 -0
- data/tasks/test.rake +3 -1
- metadata +30 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db22eea722029a231a0b460ab4984c5c0b4fb04a
|
4
|
+
data.tar.gz: d4138fb451e46da2c76bb49009ec64a31f32f15a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b464b7b066f6d8d07033261e16e579d3609e339b189328561eb58fe2d741ee110d878bfda870def3c7210723cca6d2b5fd1b53c57cd2140422cb2604ec7059f7
|
7
|
+
data.tar.gz: b529dea8cfe6b724b02b16fb414b675403e9def355795b6a5b904508626a66b924955e77b817db72c0d25928394f38f437c6f4d8d32486485c2545c454a09c62
|
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
webspicy (0.1.0.pre.
|
4
|
+
webspicy (0.1.0.pre.rc3)
|
5
5
|
finitio (~> 0.5.2)
|
6
6
|
http (~> 0.5)
|
7
7
|
path (~> 1.3)
|
8
|
+
rack-test (~> 0.7)
|
8
9
|
rspec (~> 3.6)
|
9
10
|
|
10
11
|
GEM
|
@@ -33,6 +34,8 @@ GEM
|
|
33
34
|
rack (2.0.3)
|
34
35
|
rack-protection (2.0.0)
|
35
36
|
rack
|
37
|
+
rack-test (0.7.0)
|
38
|
+
rack (>= 1.0, < 3)
|
36
39
|
rake (10.5.0)
|
37
40
|
rspec (3.6.0)
|
38
41
|
rspec-core (~> 3.6.0)
|
data/examples/restful/Rakefile
CHANGED
@@ -1,21 +1,40 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
|
2
|
+
require 'app'
|
1
3
|
require 'webspicy'
|
2
4
|
|
3
5
|
namespace :webspicy do
|
4
6
|
|
5
|
-
config = Webspicy::Configuration.new do |c|
|
6
|
-
c.host = "http://127.0.0.1:4567"
|
7
|
-
c.add_folder Path.dir/"webspicy"
|
8
|
-
end
|
9
|
-
|
10
7
|
task :check do
|
8
|
+
config = Webspicy::Configuration.new do |c|
|
9
|
+
c.add_folder Path.dir/"webspicy"
|
10
|
+
end
|
11
11
|
Webspicy::Checker.new(config).call
|
12
12
|
end
|
13
13
|
|
14
|
-
task :
|
14
|
+
task :testrack do
|
15
|
+
config = Webspicy::Configuration.new do |c|
|
16
|
+
c.add_folder Path.dir/"webspicy"
|
17
|
+
c.client = Webspicy::RackTestClient.for(::Sinatra::Application)
|
18
|
+
c.before_each do |_,_,_,client|
|
19
|
+
client.api.post "/reset"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
Webspicy::Tester.new(config).call
|
23
|
+
end
|
24
|
+
|
25
|
+
task :testreal do
|
26
|
+
config = Webspicy::Configuration.new do |c|
|
27
|
+
c.host = "http://127.0.0.1:4567"
|
28
|
+
c.add_folder Path.dir/"webspicy"
|
29
|
+
c.client = Webspicy::HttpClient
|
30
|
+
c.before_each do |_,_,_,client|
|
31
|
+
client.api.post "http://127.0.0.1:4567/reset"
|
32
|
+
end
|
33
|
+
end
|
15
34
|
Webspicy::Tester.new(config).call
|
16
35
|
end
|
17
36
|
|
18
37
|
end
|
19
38
|
|
20
|
-
task :test => :"webspicy:
|
39
|
+
task :test => [:"webspicy:check", :"webspicy:testrack"]
|
21
40
|
task :default => :test
|
data/examples/restful/app.rb
CHANGED
@@ -19,19 +19,27 @@ TODOLIST = [
|
|
19
19
|
disable :show_exceptions
|
20
20
|
enable :raise_errors
|
21
21
|
|
22
|
+
set :todolist, TODOLIST.dup
|
23
|
+
|
24
|
+
post '/reset' do
|
25
|
+
settings.todolist = TODOLIST.dup
|
26
|
+
status 200
|
27
|
+
""
|
28
|
+
end
|
29
|
+
|
22
30
|
get '/todo/' do
|
23
31
|
content_type :json
|
24
|
-
|
32
|
+
settings.todolist.to_json
|
25
33
|
end
|
26
34
|
|
27
35
|
post '/todo/' do
|
28
36
|
content_type :json
|
29
37
|
todo = SCHEMA["Todo"].dress(JSON.load(request.body.read))
|
30
|
-
if
|
38
|
+
if settings.todolist.find{|t| t[:id] == todo[:id] }
|
31
39
|
status 409
|
32
40
|
{error: "Identifier already in use"}.to_json
|
33
41
|
else
|
34
|
-
|
42
|
+
settings.todolist << todo
|
35
43
|
status 201
|
36
44
|
todo.to_json
|
37
45
|
end
|
@@ -39,7 +47,7 @@ end
|
|
39
47
|
|
40
48
|
get '/todo/:id' do |id|
|
41
49
|
content_type :json
|
42
|
-
todo =
|
50
|
+
todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
|
43
51
|
if todo.nil?
|
44
52
|
status 404
|
45
53
|
{error: "No such todo"}.to_json
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class HttpClient < Client
|
3
3
|
|
4
|
+
def initialize(scope)
|
5
|
+
super(scope)
|
6
|
+
@api = Api.new
|
7
|
+
end
|
8
|
+
attr_reader :api
|
9
|
+
|
4
10
|
def call(test_case, service, resource)
|
5
11
|
# Instantiate the parameters
|
6
12
|
headers = test_case.headers
|
@@ -13,7 +19,6 @@ module Webspicy
|
|
13
19
|
url = scope.to_real_url(url)
|
14
20
|
|
15
21
|
# Invoke the service now
|
16
|
-
api = Api.new
|
17
22
|
api.public_send(service.method.to_s.downcase.to_sym, url, params, headers)
|
18
23
|
|
19
24
|
# Return the result
|
@@ -24,46 +29,33 @@ module Webspicy
|
|
24
29
|
|
25
30
|
attr_reader :last_response
|
26
31
|
|
27
|
-
def get(url, params, headers = nil)
|
28
|
-
headers, url = headers_and_url_for(url, params, headers)
|
29
|
-
|
32
|
+
def get(url, params = {}, headers = nil)
|
30
33
|
Webspicy.info("GET #{url} -- #{params.inspect}")
|
31
34
|
|
32
|
-
@last_response = HTTP[headers].get(url, params: params)
|
35
|
+
@last_response = HTTP[headers || {}].get(url, params: params)
|
33
36
|
|
34
37
|
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
35
38
|
Webspicy.debug("Response: #{@last_response.body}")
|
36
39
|
end
|
37
40
|
|
38
|
-
def post(url, params, headers = nil)
|
39
|
-
headers, url = headers_and_url_for(url, params, headers)
|
40
|
-
|
41
|
+
def post(url, params = {}, headers = nil)
|
41
42
|
Webspicy.info("POST #{url} -- #{params.inspect}")
|
42
43
|
|
43
|
-
@last_response = HTTP[headers].post(url, body: params.to_json)
|
44
|
+
@last_response = HTTP[headers || {}].post(url, body: params.to_json)
|
44
45
|
|
45
46
|
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
46
47
|
Webspicy.debug("Response: #{@last_response.body}")
|
47
48
|
end
|
48
49
|
|
49
|
-
def post_form(url, params, headers = nil)
|
50
|
-
headers, url = headers_and_url_for(url, params, headers)
|
51
|
-
|
50
|
+
def post_form(url, params = {}, headers = nil)
|
52
51
|
Webspicy.info("POST #{url} -- #{params.inspect}")
|
53
52
|
|
54
|
-
@last_response = HTTP[headers].post(url, form: params)
|
53
|
+
@last_response = HTTP[headers || {}].post(url, form: params)
|
55
54
|
|
56
55
|
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
57
56
|
Webspicy.debug("Response: #{@last_response.body}")
|
58
57
|
end
|
59
58
|
|
60
|
-
private
|
61
|
-
|
62
|
-
def headers_and_url_for(url, params, headers)
|
63
|
-
headers = headers || {}
|
64
|
-
[ headers, url ]
|
65
|
-
end
|
66
|
-
|
67
59
|
end
|
68
60
|
|
69
61
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class RackTestClient < Client
|
3
|
+
|
4
|
+
def self.for(app)
|
5
|
+
Factory.new(app)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(scope, app)
|
9
|
+
super(scope)
|
10
|
+
@api = Api.new(app)
|
11
|
+
end
|
12
|
+
attr_reader :api
|
13
|
+
|
14
|
+
def call(test_case, service, resource)
|
15
|
+
# Instantiate the parameters
|
16
|
+
headers = test_case.headers
|
17
|
+
params = test_case.dress_params? ? service.dress_params(test_case.params) : test_case.params
|
18
|
+
|
19
|
+
# Instantiate the url and strip parameters
|
20
|
+
url, params = resource.instantiate_url(params)
|
21
|
+
|
22
|
+
# Invoke the service now
|
23
|
+
api.public_send(service.method.to_s.downcase.to_sym, url, params, headers)
|
24
|
+
|
25
|
+
# Return the result
|
26
|
+
Resource::Service::Invocation.new(service, test_case, api.last_response)
|
27
|
+
end
|
28
|
+
|
29
|
+
class Factory
|
30
|
+
|
31
|
+
def initialize(app)
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
attr_reader :app
|
35
|
+
|
36
|
+
def new(scope)
|
37
|
+
RackTestClient.new(scope, app)
|
38
|
+
end
|
39
|
+
|
40
|
+
end # class Factory
|
41
|
+
|
42
|
+
class RackHandler
|
43
|
+
include Rack::Test::Methods
|
44
|
+
|
45
|
+
def initialize(app)
|
46
|
+
@app = app
|
47
|
+
end
|
48
|
+
attr_reader :app
|
49
|
+
|
50
|
+
end # class RackHandler
|
51
|
+
|
52
|
+
class Api
|
53
|
+
|
54
|
+
attr_reader :last_response
|
55
|
+
|
56
|
+
def initialize(app)
|
57
|
+
@handler = RackHandler.new(app)
|
58
|
+
end
|
59
|
+
attr_reader :handler
|
60
|
+
|
61
|
+
def get(url, params = {}, headers = nil)
|
62
|
+
Webspicy.info("GET #{url} -- #{params.inspect}")
|
63
|
+
|
64
|
+
install_headers(headers) if headers
|
65
|
+
handler.get(url, params)
|
66
|
+
@last_response = handler.last_response
|
67
|
+
|
68
|
+
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
69
|
+
Webspicy.debug("Response: #{@last_response.body}")
|
70
|
+
end
|
71
|
+
|
72
|
+
def post(url, params = {}, headers = nil)
|
73
|
+
Webspicy.info("POST #{url} -- #{params.inspect}")
|
74
|
+
|
75
|
+
install_headers(headers) if headers
|
76
|
+
handler.post(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
|
77
|
+
@last_response = handler.last_response
|
78
|
+
|
79
|
+
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
80
|
+
Webspicy.debug("Response: #{@last_response.body}")
|
81
|
+
end
|
82
|
+
|
83
|
+
def post_form(url, params = {}, headers = nil)
|
84
|
+
Webspicy.info("POST #{url} -- #{params.inspect}")
|
85
|
+
|
86
|
+
install_headers(headers) if headers
|
87
|
+
handler.post(url, params)
|
88
|
+
@last_response = handler.last_response
|
89
|
+
|
90
|
+
Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
|
91
|
+
Webspicy.debug("Response: #{@last_response.body}")
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def install_headers(hs)
|
97
|
+
hs.each_pair do |k,v|
|
98
|
+
handler.header(k,v)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end # class Api
|
103
|
+
|
104
|
+
end # class RackTestClient
|
105
|
+
end # module Webspicy
|
data/lib/webspicy/client.rb
CHANGED
@@ -19,7 +19,8 @@ module Webspicy
|
|
19
19
|
raise "Folder `#{folder}` does not exists" unless folder.exists? && folder.directory?
|
20
20
|
@folders << folder
|
21
21
|
end
|
22
|
-
|
22
|
+
attr_accessor :folders
|
23
|
+
protected :folders=
|
23
24
|
|
24
25
|
# Sets whether counter examples have to be ran or not.
|
25
26
|
def run_counterexamples=(run_counterexamples)
|
@@ -137,6 +138,8 @@ module Webspicy
|
|
137
138
|
def before_listeners
|
138
139
|
@before_listeners
|
139
140
|
end
|
141
|
+
attr_writer :before_listeners
|
142
|
+
protected :before_listeners=
|
140
143
|
|
141
144
|
# Allows setting the options passed at RSpec, which is used by both the runner
|
142
145
|
# and checker classes.
|
@@ -146,7 +149,8 @@ module Webspicy
|
|
146
149
|
def rspec_options=(options)
|
147
150
|
@rspec_options = options
|
148
151
|
end
|
149
|
-
|
152
|
+
attr_accessor :rspec_options
|
153
|
+
protected :rspec_options=
|
150
154
|
|
151
155
|
# Returns the default rspec options.
|
152
156
|
#
|
@@ -164,5 +168,20 @@ module Webspicy
|
|
164
168
|
end
|
165
169
|
private :default_rspec_options
|
166
170
|
|
171
|
+
# Duplicates this configuration and yields the block with the new one,
|
172
|
+
# if a block is given.
|
173
|
+
#
|
174
|
+
# The cloned configuration has all same values as the original but shares
|
175
|
+
# nothing with it. Therefore, affecting the new one has no effect on the
|
176
|
+
# original.
|
177
|
+
def dup(&bl)
|
178
|
+
super.tap do |d|
|
179
|
+
d.folders = self.folders.dup
|
180
|
+
d.rspec_options = self.rspec_options.dup
|
181
|
+
d.before_listeners = self.before_listeners.dup
|
182
|
+
yield d if block_given?
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
167
186
|
end
|
168
187
|
end
|
@@ -11,6 +11,16 @@ module Webspicy
|
|
11
11
|
|
12
12
|
attr_reader :service, :test_case, :response
|
13
13
|
|
14
|
+
### Getters on response
|
15
|
+
|
16
|
+
def response_code
|
17
|
+
code = response.status
|
18
|
+
code = code.code unless code.is_a?(Integer)
|
19
|
+
code
|
20
|
+
end
|
21
|
+
|
22
|
+
### Query methods
|
23
|
+
|
14
24
|
def done?
|
15
25
|
!response.nil?
|
16
26
|
end
|
@@ -20,15 +30,15 @@ module Webspicy
|
|
20
30
|
end
|
21
31
|
|
22
32
|
def is_success?
|
23
|
-
|
33
|
+
response_code >= 200 && response_code < 300
|
24
34
|
end
|
25
35
|
|
26
36
|
def is_empty_response?
|
27
|
-
|
37
|
+
response_code == 204
|
28
38
|
end
|
29
39
|
|
30
40
|
def is_redirect?
|
31
|
-
|
41
|
+
response_code >= 300 && response_code < 400
|
32
42
|
end
|
33
43
|
|
34
44
|
### Check of HTTP status
|
@@ -47,7 +57,8 @@ module Webspicy
|
|
47
57
|
|
48
58
|
def expected_content_type_unmet
|
49
59
|
ect = test_case.expected_content_type
|
50
|
-
got = response.content_type
|
60
|
+
got = response.content_type
|
61
|
+
got = got.mime_type.to_s if got.respond_to?(:mime_type)
|
51
62
|
ect == got ? nil : "#{ect} != #{got}"
|
52
63
|
end
|
53
64
|
|
data/lib/webspicy/version.rb
CHANGED
data/lib/webspicy.rb
CHANGED
@@ -6,6 +6,7 @@ require 'logger'
|
|
6
6
|
require 'ostruct'
|
7
7
|
require 'yaml'
|
8
8
|
require 'rspec'
|
9
|
+
require 'rack/test'
|
9
10
|
module Webspicy
|
10
11
|
|
11
12
|
###
|
@@ -16,6 +17,7 @@ module Webspicy
|
|
16
17
|
require 'webspicy/scope'
|
17
18
|
require 'webspicy/client'
|
18
19
|
require 'webspicy/client/http_client'
|
20
|
+
require 'webspicy/client/rack_test_client'
|
19
21
|
require 'webspicy/resource'
|
20
22
|
require 'webspicy/checker'
|
21
23
|
require 'webspicy/tester'
|
@@ -80,5 +80,39 @@ module Webspicy
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
describe 'dup' do
|
84
|
+
|
85
|
+
let(:original) do
|
86
|
+
Configuration.new do |c|
|
87
|
+
c.add_folder Path.dir/'resource'
|
88
|
+
c.host = "http://127.0.0.1"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'lets duplicate a configuration' do
|
93
|
+
duped = original.dup do |d|
|
94
|
+
d.host = "http://127.0.0.1:4567"
|
95
|
+
end
|
96
|
+
expect(duped.host).to eql("http://127.0.0.1:4567")
|
97
|
+
expect(original.host).to eql("http://127.0.0.1")
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'duplicates the internal arrays to' do
|
101
|
+
duped = original.dup do |d|
|
102
|
+
d.add_folder Path.dir/'scope'
|
103
|
+
d.rspec_options << "--hello"
|
104
|
+
d.before_each do end
|
105
|
+
end
|
106
|
+
expect(duped.folders.size).to eql(2)
|
107
|
+
expect(original.folders.size).to eql(1)
|
108
|
+
|
109
|
+
expect(duped.rspec_options.last).to eq("--hello")
|
110
|
+
expect(original.rspec_options.last).not_to eq("--hello")
|
111
|
+
|
112
|
+
expect(duped.before_listeners.size).to eq(1)
|
113
|
+
expect(original.before_listeners.size).to eq(0)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
83
117
|
end
|
84
118
|
end
|
data/tasks/test.rake
CHANGED
@@ -15,7 +15,9 @@ namespace :test do
|
|
15
15
|
test_name = file.basename.to_s.to_sym
|
16
16
|
desc "Runs the integration tests on the #{file.basename} example"
|
17
17
|
task(test_name) do
|
18
|
-
|
18
|
+
Bundler.with_original_env do
|
19
|
+
system("cd #{file} && rake")
|
20
|
+
end
|
19
21
|
end
|
20
22
|
tests << test_name
|
21
23
|
end
|
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.pre.
|
4
|
+
version: 0.1.0.pre.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sinatra
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: finitio
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,6 +130,7 @@ files:
|
|
102
130
|
- lib/webspicy/checker.rb
|
103
131
|
- lib/webspicy/client.rb
|
104
132
|
- lib/webspicy/client/http_client.rb
|
133
|
+
- lib/webspicy/client/rack_test_client.rb
|
105
134
|
- lib/webspicy/configuration.rb
|
106
135
|
- lib/webspicy/formaldoc.fio
|
107
136
|
- lib/webspicy/resource.rb
|