soaspec 0.1.3 → 0.1.4

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: 1c1e38e1213ce6461e1bca9a181d6be4130295a4
4
- data.tar.gz: 9e2170b74242c21f8c9ac3fe51fccf5676a4db49
3
+ metadata.gz: 33b4fef9deff557c6531eb1d12aac9071bbcc95e
4
+ data.tar.gz: c317a3e008dd94f7094eae9be7d6e133a1376c0b
5
5
  SHA512:
6
- metadata.gz: 9c41202a31e2e2740688628efada58bb0631cd91b5f1b60f624219d0f254c1cb5e823f00d2ea2451f16890b8059594fe8add22c9db4cb4d4db3acca8f06dcd90
7
- data.tar.gz: 76bbf2ad8ba5a5e1333cb33653ba45220c9dcca5d8257b7e5c235dc849dfd85ea0b5783d3e1100ee7b606c3072a9cf95c5e4e362e91ba2b4f3c1a8586ccb0d05
6
+ metadata.gz: 12f211b2ff81229e85b6bb6d4b70899067cf59c8f8d37a74d3d24feeaf4a9285b368af4e909bc3d250a5206de4a056d9872844357f97a7fc5470c9bcb3dd1457
7
+ data.tar.gz: aa6269a25076f3f0132b879c88136e7d6becadf4871e3c66bbea9a5a5083f263b1d5e89e5f11bfcbba5cda0434e69465c8a5f907193090b90ad870b278bb2bb0
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.1.4
2
+ * Enhancements
3
+ * create_file method create folders automatically if necessary
4
+ * Package spec to help one learn testing for items in a list
5
+ * Added docs for soaspec-virtual-server
6
+
1
7
  Version 0.1.3
2
8
  * Enhancements
3
9
  * Ability to set template folder
@@ -34,18 +34,13 @@ module Soaspec
34
34
  create_file(filename: '.rspec')
35
35
  create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
36
  create_file(filename: 'README.md')
37
- create_folder 'lib'
38
37
  if type == 'soap'
39
38
  create_file filename: 'lib/blz_service.rb'
40
39
  create_file filename: 'lib/shared_example.rb'
41
40
  end
42
- create_folder 'config'
43
- create_folder 'config/data'
44
41
  create_file(filename: 'config/data/default.yml')
45
- create_folder 'spec'
46
42
  create_file(filename: 'spec/spec_helper.rb')
47
43
  create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
48
- create_folder 'template'
49
44
  create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
50
45
  create_folder 'logs'
51
46
 
@@ -80,13 +75,8 @@ module Soaspec
80
75
  create_file(filename: '.rspec')
81
76
  create_file(filename: '.travis.yml') if options[:ci] == 'travis'
82
77
  create_file filename: 'README.md', ignore_if_present: true
83
- create_folder 'spec'
84
78
  create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
85
-
86
79
  create_folder 'logs'
87
- create_folder 'config'
88
- create_folder 'config/data'
89
- create_folder 'lib'
90
80
  create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
91
81
 
92
82
  # Files according to WSDL
@@ -1,47 +1,91 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  require 'soaspec'
5
5
  require 'sinatra'
6
6
  require 'sinatra/basic_auth'
7
+ require 'docdsl'
7
8
  require 'nokogiri'
8
9
  require 'erb'
9
10
  require 'json'
10
11
  require 'faker'
11
12
 
13
+ # Used to run virtual web service on localhost. This makes tests more reliable and faster
12
14
  class SoaspecVirtualServer < Sinatra::Application
15
+ set :port, 4999
13
16
 
14
- # Used to run virtual web service on localhost. This makes tests more reliable and faster
17
+ register Sinatra::DocDsl
15
18
 
16
- set :port, 4999
19
+ page do
20
+ title 'Soaspec Virtual Services'
21
+ header 'Perform efficient API testing with Ruby'
22
+ introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
23
+ end
24
+
25
+ documentation 'Nothing under /. Go look at /docs' do
26
+ response 'redirects to the documentation page'
27
+ status 303
28
+ end
29
+ get '/' do
30
+ redirect '/docs'
31
+ end
17
32
 
18
- # Used to test attributes
33
+ doc_endpoint '/docs'
34
+
35
+ documentation 'Used to test attributes' do
36
+ response 'A simple Note XML with a date attribute'
37
+ end
19
38
  get '/test_attribute' do
20
39
  Soaspec::TestServer::TestAttribute.note
21
40
  end
22
41
 
23
- # Used to test attributes
42
+ documentation 'Used to test namespaces' do
43
+ response 'XML with 2 namespaces and same elements inside it'
44
+ end
24
45
  get '/namespace' do
25
- # Soaspec::TestServer::TestAttribute.note
26
46
  Soaspec::TestServer::TestNamespace.food
27
47
  end
28
48
 
49
+ documentation 'Used for showing a simple difference in value depending on the id used' do
50
+ param :num, 'Number of tester'
51
+ param :id, 'Test parameter'
52
+ response 'JSON with success or true or false and the id sent
53
+ Idea is for tester to find the id that causes a failure (the fake "defect")
54
+ '
55
+ end
56
+ get '/packages/:num/:id' do |num, id|
57
+ result = case num
58
+ when '1', '4', '10' then 'false' if id == '40'
59
+ when '3', '11', '9' then 'false' if id == '74'
60
+ when '8', '6', '8' then 'false' if id == '80'
61
+ when '7', '5', '12' then 'false' if id == '64'
62
+ else
63
+ true
64
+ end
65
+ result ||= true
66
+ JSON.generate(success: result, id: id)
67
+ end
68
+
29
69
  # Used for simple testing of posing
70
+ documentation 'Simply sends the response body back'
30
71
  post '/echoer' do
31
72
  request.body
32
73
  end
33
74
 
34
- # Simulate retrieving an ouath token. Passed to '/invoices'
75
+ documentation "Simulate retrieving an ouath token Passed to '/invoices'"
35
76
  post '/as/token.oauth2' do
36
77
  Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
37
78
  [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
38
79
  end
39
80
 
81
+ documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
40
82
  get '/invoice/:id' do |id|
41
83
  JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
42
84
  end
43
85
 
44
- # This is returned when a query for the WSDL is made
86
+ documentation 'This is returned when a query for the WSDL is made' do
87
+ response 'WSDL containing SCHEMA information'
88
+ end
45
89
  get '/BLZService' do
46
90
  [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
47
91
  end
@@ -51,17 +95,23 @@ class SoaspecVirtualServer < Sinatra::Application
51
95
  end
52
96
 
53
97
  protect do
98
+ documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
99
+ response 'Secret text'
100
+ end
54
101
  get '/basic_secrets' do
55
102
  'Secret data'
56
103
  end
57
104
 
58
- # This is the one being hit by SOAP actions
105
+ documentation 'This is the basic service being hit by SOAP actions'
59
106
  post '/BLZService' do
60
107
  Soaspec::TestServer::GetBank.response_for request
61
108
  end
62
109
  end
63
110
 
64
- # Used for testing storage of data
111
+ documentation 'Used for testing storage of data' do
112
+ payload 'Puppy JSON',
113
+ Name: 'Test', Failure_Type__c: 'Fail'
114
+ end
65
115
  post '/test/puppy' do
66
116
  request_hash = JSON.parse(request.body.string)
67
117
  id = Soaspec::TestServer::PuppyService.new_id
@@ -71,12 +121,23 @@ class SoaspecVirtualServer < Sinatra::Application
71
121
  JSON.generate response_hash
72
122
  end
73
123
 
74
- # Used for testing retrieving storage of data
124
+ documentation 'Used for testing retrieving storage of data'
75
125
  get '/test/puppy/:id' do |id|
76
126
  result = Soaspec::TestServer::PuppyService.data[id.to_i]
77
127
  JSON.generate result
78
128
  end
79
129
 
130
+ documentation 'Used for testing updating data'
131
+ patch '/test/puppy/:id' do |id|
132
+ request_hash = JSON.parse(request.body.string)
133
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
134
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
135
+ JSON.generate response_hash
136
+ end
137
+
138
+ documentation 'Used for testing the handling of JSON path' do
139
+ response 'JSON with multiple elements of the same name at different nested levels'
140
+ end
80
141
  get '/test/multiple_json' do
81
142
  <<-BOOKS
82
143
  {"store":
@@ -93,12 +154,6 @@ class SoaspecVirtualServer < Sinatra::Application
93
154
  BOOKS
94
155
  end
95
156
 
96
- patch '/test/puppy/:id' do |id|
97
- request_hash = JSON.parse(request.body.string)
98
- Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
99
- response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
100
- JSON.generate response_hash
101
- end
102
157
  end
103
158
 
104
159
  SoaspecVirtualServer.run!
@@ -302,8 +302,8 @@ module Soaspec
302
302
  # Make REST Exchange within this Handler context
303
303
  # @param [Hash] params Exchange parameters
304
304
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
305
- define_method(rest_method) do |params|
306
- params ||= {}
305
+ define_method(rest_method) do |params = {}|
306
+ # params ||= {}
307
307
  params[:name] ||= rest_method
308
308
  new(params[:name])
309
309
  Exchange.new(params[:name], method: rest_method.to_sym, **params)
@@ -22,6 +22,7 @@ module Soaspec
22
22
  def create_file(filename: nil, content: nil, ignore_if_present: false, erb: true)
23
23
  raise 'Need to pass filename' unless filename
24
24
  content ||= retrieve_contents(filename, erb)
25
+ create_folder File.split(filename).first
25
26
  if File.exist? filename
26
27
  old_content = File.read(filename)
27
28
  if old_content != content && !ignore_if_present
@@ -33,11 +34,14 @@ module Soaspec
33
34
  end
34
35
  end
35
36
 
37
+ # Create folder if there's not a file already there.
38
+ # Will create parent folder if necessary.
39
+ # @param [String] folder Folder to create
36
40
  def create_folder(folder)
37
41
  if File.exist? folder
38
42
  warn "!! #{folder} already exists and is not a directory" unless File.directory? folder
39
43
  else
40
- FileUtils.mkdir folder
44
+ FileUtils.mkdir_p folder
41
45
  puts "Created folder: #{folder}/"
42
46
  end
43
47
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module Soaspec
3
2
  module TestServer
4
3
  # Helps tests attribute methods
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -40,6 +40,7 @@ the same configuration "
40
40
  spec.add_dependency 'savon', '>= 2' # SOAP
41
41
  spec.add_dependency 'sinatra'
42
42
  spec.add_dependency 'sinatra-basic-auth'
43
+ spec.add_dependency 'sinatra-docdsl'
43
44
  spec.add_dependency 'thor'
44
45
  spec.add_dependency 'xml-simple', '>= 1.1.5'
45
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-18 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -262,6 +262,20 @@ dependencies:
262
262
  - - ">="
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: sinatra-docdsl
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
265
279
  - !ruby/object:Gem::Dependency
266
280
  name: thor
267
281
  requirement: !ruby/object:Gem::Requirement