soaspec 0.0.81 → 0.0.82

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +15 -15
  3. data/.gitlab-ci.yml +31 -31
  4. data/.rspec +3 -3
  5. data/.rubocop.yml +2 -2
  6. data/.travis.yml +5 -5
  7. data/CODE_OF_CONDUCT.md +74 -74
  8. data/ChangeLog +345 -341
  9. data/Gemfile +6 -6
  10. data/LICENSE.txt +21 -21
  11. data/README.md +85 -85
  12. data/Rakefile +24 -24
  13. data/Todo.md +6 -6
  14. data/exe/soaspec +123 -123
  15. data/exe/soaspec-virtual-server +98 -92
  16. data/exe/xml_to_yaml_file +60 -60
  17. data/lib/soaspec.rb +86 -85
  18. data/lib/soaspec/core_ext/hash.rb +83 -83
  19. data/lib/soaspec/exchange.rb +230 -230
  20. data/lib/soaspec/exchange_handlers/exchange_handler.rb +98 -98
  21. data/lib/soaspec/exchange_handlers/handler_accessors.rb +95 -95
  22. data/lib/soaspec/exchange_handlers/rest_handler.rb +367 -367
  23. data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
  24. data/lib/soaspec/exchange_handlers/soap_handler.rb +231 -231
  25. data/lib/soaspec/exe_helpers.rb +56 -56
  26. data/lib/soaspec/generator/.rspec.erb +5 -5
  27. data/lib/soaspec/generator/.travis.yml.erb +5 -5
  28. data/lib/soaspec/generator/Gemfile.erb +8 -8
  29. data/lib/soaspec/generator/README.md.erb +29 -29
  30. data/lib/soaspec/generator/Rakefile.erb +19 -19
  31. data/lib/soaspec/generator/config/data/default.yml.erb +1 -1
  32. data/lib/soaspec/generator/lib/blz_service.rb.erb +24 -24
  33. data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
  34. data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
  35. data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +14 -14
  36. data/lib/soaspec/generator/spec/soap_spec.rb.erb +53 -53
  37. data/lib/soaspec/generator/spec/spec_helper.rb.erb +20 -20
  38. data/lib/soaspec/generator/template/soap_template.xml +6 -6
  39. data/lib/soaspec/interpreter.rb +25 -25
  40. data/lib/soaspec/matchers.rb +65 -65
  41. data/lib/soaspec/not_found_errors.rb +13 -13
  42. data/lib/soaspec/soaspec_shared_examples.rb +24 -24
  43. data/lib/soaspec/spec_logger.rb +27 -27
  44. data/lib/soaspec/test_server/bank.wsdl +90 -90
  45. data/lib/soaspec/test_server/get_bank.rb +160 -160
  46. data/lib/soaspec/test_server/invoices.rb +27 -27
  47. data/lib/soaspec/test_server/namespace.xml +15 -0
  48. data/lib/soaspec/test_server/note.xml +5 -5
  49. data/lib/soaspec/test_server/puppy_service.rb +20 -20
  50. data/lib/soaspec/test_server/test_attribute.rb +13 -13
  51. data/lib/soaspec/test_server/test_namespace.rb +13 -0
  52. data/lib/soaspec/version.rb +2 -2
  53. data/lib/soaspec/wsdl_generator.rb +93 -93
  54. data/soaspec.gemspec +45 -45
  55. data/test.wsdl +116 -116
  56. data/test.xml +10 -10
  57. data/test_rest.rb +97 -97
  58. data/test_wsdl.rb +43 -43
  59. metadata +5 -3
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:gitlab) { |repo_name| "https://gitlab.com/samuel-garratt/soaspec" }
4
-
5
- # Specify your gem's dependencies in soaspec.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:gitlab) { |repo_name| "https://gitlab.com/samuel-garratt/soaspec" }
4
+
5
+ # Specify your gem's dependencies in soaspec.gemspec
6
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 Samuel Garratt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Samuel Garratt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,85 +1,85 @@
1
- # Soaspec
2
-
3
- This gem helps to represent multiple API tests against a backend briefly, concisely and clearly. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
4
-
5
- [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
6
- [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](https://samuel-garratt.gitlab.io/soaspec)
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'soaspec'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install soaspec
22
-
23
- [Things to be done](Todo.md)
24
-
25
- ## Getting Started
26
-
27
- To create a new test suite using this you can use the 'soaspec-init' binary.
28
-
29
- Example:
30
-
31
- ```
32
- mkdir 'api_test'
33
- cd 'api_test'
34
- soaspec-init
35
- bundle install
36
- ```
37
-
38
- Then you can run the tests with:
39
-
40
- ```
41
- rake spec
42
- ```
43
-
44
- You can also use `soaspec-generate` to generate a set of tests from a WSDL. This is still in trial period
45
-
46
- ## Usage
47
-
48
- * SOAP - this uses Savon behind the scenes. Some defaults are overridden. Please see 'soap_handler.rb'-'default_options' method
49
- for such defaults. When describing an API override this in 'savon_options' method
50
- * REST - this uses the resource class from the Rest-Client gem behind the scenes.
51
-
52
- See specs for example of usage. This will be added to later.
53
-
54
- ### Recommended
55
-
56
- It is recommended that a class be created representing a Web Service Operation or REST call. Then tests refer back to
57
- that class. See 'weather_web_service.rb' class in spec/soaspec/soap folder for example.
58
-
59
- If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
60
- backtrace.
61
-
62
- RSpec.configure do |config|
63
-
64
- config.backtrace_exclusion_patterns = [
65
- /rspec/
66
- ]
67
- end
68
-
69
- ## Development
70
-
71
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
-
73
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
-
75
- ## Contributing
76
-
77
- Bug reports and pull requests are welcome on GitLab at https://gitlab.com/samuel-garratt/soaspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
78
-
79
- ## License
80
-
81
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
-
83
- ## Code of Conduct
84
-
85
- Everyone interacting in the Soaspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/samuel-garratt/soaspec/blob/master/CODE_OF_CONDUCT.md).
1
+ # Soaspec
2
+
3
+ This gem helps to represent multiple API tests against a backend briefly, concisely and clearly. It is essentially a wrapper around the Savon and RestClient gems. Note it is still in early stages of development.
4
+
5
+ [![Build Status](https://gitlab.com/samuel-garratt/soaspec/badges/master/build.svg)](https://gitlab.com/samuel-garratt/soaspec/pipelines)
6
+ [![Coverage](https://gitlab.com/samuel-garratt/soaspec/badges/master/coverage.svg)](https://samuel-garratt.gitlab.io/soaspec)
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'soaspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install soaspec
22
+
23
+ [Things to be done](Todo.md)
24
+
25
+ ## Getting Started
26
+
27
+ To create a new test suite using this you can use the 'soaspec-init' binary.
28
+
29
+ Example:
30
+
31
+ ```
32
+ mkdir 'api_test'
33
+ cd 'api_test'
34
+ soaspec-init
35
+ bundle install
36
+ ```
37
+
38
+ Then you can run the tests with:
39
+
40
+ ```
41
+ rake spec
42
+ ```
43
+
44
+ You can also use `soaspec-generate` to generate a set of tests from a WSDL. This is still in trial period
45
+
46
+ ## Usage
47
+
48
+ * SOAP - this uses Savon behind the scenes. Some defaults are overridden. Please see 'soap_handler.rb'-'default_options' method
49
+ for such defaults. When describing an API override this in 'savon_options' method
50
+ * REST - this uses the resource class from the Rest-Client gem behind the scenes.
51
+
52
+ See specs for example of usage. This will be added to later.
53
+
54
+ ### Recommended
55
+
56
+ It is recommended that a class be created representing a Web Service Operation or REST call. Then tests refer back to
57
+ that class. See 'weather_web_service.rb' class in spec/soaspec/soap folder for example.
58
+
59
+ If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
60
+ backtrace.
61
+
62
+ RSpec.configure do |config|
63
+
64
+ config.backtrace_exclusion_patterns = [
65
+ /rspec/
66
+ ]
67
+ end
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/samuel-garratt/soaspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the Soaspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/samuel-garratt/soaspec/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,24 +1,24 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rake/clean'
4
-
5
- ENV['folder'] ||= ''
6
- ENV['test'] ||= ''
7
-
8
- desc 'Run tests'
9
- RSpec::Core::RakeTask.new(spec: %i[clean clobber start_test_server]) do |t|
10
- t.pattern = "spec/**/#{ENV['folder']}*/#{ENV['test']}*_spec.rb"
11
- end
12
-
13
- task default: :spec
14
-
15
- CLEAN.include 'tmp/*'
16
- CLOBBER.include 'logs/*'
17
-
18
- desc 'Start virtual web service'
19
- task :start_test_server do
20
- mkdir_p 'logs'
21
- ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
22
- sleep 2 # Wait a little for virtual server to start up
23
- puts 'Running test server at pid ' + ENV['test_server_pid']
24
- end
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/clean'
4
+
5
+ ENV['folder'] ||= ''
6
+ ENV['test'] ||= ''
7
+
8
+ desc 'Run tests'
9
+ RSpec::Core::RakeTask.new(spec: %i[clean clobber start_test_server]) do |t|
10
+ t.pattern = "spec/**/#{ENV['folder']}*/#{ENV['test']}*_spec.rb"
11
+ end
12
+
13
+ task default: :spec
14
+
15
+ CLEAN.include 'tmp/*'
16
+ CLOBBER.include 'logs/*'
17
+
18
+ desc 'Start virtual web service'
19
+ task :start_test_server do
20
+ mkdir_p 'logs'
21
+ ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
22
+ sleep 2 # Wait a little for virtual server to start up
23
+ puts 'Running test server at pid ' + ENV['test_server_pid']
24
+ end
data/Todo.md CHANGED
@@ -1,7 +1,7 @@
1
- * Give examples and convenience methods for building classes for each SOAP or REST operation
2
- * For SOAP give example of basic_auth
3
- * Handle REST template (similar way to SOAP)
4
- * Get wsdl generator working for non complex gems
5
- * Potentially have in built use of 'vcr' and 'http_stub' gems
6
- * Handle proxies to record traffic for MiddleWare testing
1
+ * Give examples and convenience methods for building classes for each SOAP or REST operation
2
+ * For SOAP give example of basic_auth
3
+ * Handle REST template (similar way to SOAP)
4
+ * Get wsdl generator working for non complex gems
5
+ * Potentially have in built use of 'vcr' and 'http_stub' gems
6
+ * Handle proxies to record traffic for MiddleWare testing
7
7
  * Much more - please raise an issue for suggestion
data/exe/soaspec CHANGED
@@ -1,124 +1,124 @@
1
- #!/usr/bin/env ruby
2
-
3
-
4
- require 'thor'
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
- require 'savon'
7
- require 'soaspec'
8
-
9
- module Soaspec
10
-
11
- # Common executable for Soaspec
12
- class Exe < Thor
13
-
14
- include Soaspec::ExeHelpers
15
- include Soaspec::WsdlGenerator
16
-
17
- long_desc <<-LONGDESC
18
- `soaspec new` will generate the initial files and folders for starting a testing project using soaspec
19
- \x5
20
-
21
- `soaspec new soap` will create example files testing against a virtual SOAP service
22
- \x5
23
-
24
- `soaspec new rest` will create example files testing against a virtual REST service
25
- LONGDESC
26
- desc 'new [type]', 'Initialize soaspec repository'
27
- option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
28
- option :virtual, type: :boolean, default: true, banner: 'Whether to set things up for a virtual server'
29
- def new(type = 'initial')
30
- @virtual = options[:virtual]
31
- puts "Creating files for soaspec. options are #{options}"
32
- create_file(filename: 'Gemfile')
33
- create_file(filename: 'Rakefile')
34
- create_file(filename: '.rspec')
35
- create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
- create_file(filename: 'README.md')
37
- create_folder 'lib'
38
- if type == 'soap'
39
- create_file filename: 'lib/blz_service.rb'
40
- create_file filename: 'lib/shared_example.rb'
41
- end
42
- create_folder 'config'
43
- create_folder 'config/data'
44
- create_file(filename: 'config/data/default.yml')
45
- create_folder 'spec'
46
- create_file(filename: 'spec/spec_helper.rb')
47
- create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
48
- create_folder 'template'
49
- create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
50
- create_folder 'logs'
51
-
52
- puts "Run 'bundle install' to install necessary gems"
53
- puts "Run 'rake spec' to run the tests"
54
- end
55
-
56
- desc 'generate', 'Generate initial test code from wsdl'
57
- long_desc <<-LONGDESC
58
- `soaspec generate wsdl=wsdl name=ServiceName ` will generate the initial files and folders to test each operation in a wsdl
59
- \x5
60
- Additionally the auth parameter can be used to use basic authentication to retrieve the WSDL.
61
- To do use the following `soaspec generate --auth=basic`
62
-
63
- LONGDESC
64
- option :wsdl, required: true, aliases: :w
65
- option :name, default: 'Service', aliases: :n
66
- option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
67
- option :auth
68
- option :string_default, default: 'test string'
69
- def generate
70
- enter_auth_details if options[:auth] == 'basic'
71
- @virtual = false
72
- savon_options = { wsdl: options[:wsdl] }
73
- savon_options[:basic_auth] = [@auth_name, @auth_password] if options[:auth] == 'basic'
74
-
75
- @wsdl_doc = Savon.client(**savon_options).wsdl
76
- @wsdl_schemas = @wsdl_doc.parser.schemas
77
-
78
- create_file filename: 'Rakefile', ignore_if_present: true
79
- create_file filename: 'Gemfile', ignore_if_present: true
80
- create_file(filename: '.rspec')
81
- create_file(filename: '.travis.yml') if options[:ci] == 'travis'
82
- create_file filename: 'README.md', ignore_if_present: true
83
- create_folder 'spec'
84
- create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
85
-
86
- create_folder 'logs'
87
- create_folder 'config'
88
- create_folder 'config/data'
89
- create_folder 'lib'
90
- create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
91
-
92
- # Files according to WSDL
93
- @wsdl_doc.operations.each do |operation, details|
94
- puts "Creating files for operation: #{operation}"
95
- @content = "default:\n"
96
- @use_camel_case = false
97
- puts 'Message params: ' + details.to_s
98
- # From namespace identifier, find namespace, and for that find schemaLocation xsd and use that to build request
99
- if details[:parameters]
100
- details[:parameters].each do |element, details|
101
- @use_camel_case = true if /[[:upper:]]/.match(element.to_s[0]) != nil
102
- @content += " #{element.to_s.snakecase}: #{fill_in_field_from_type(details[:type])} # #{details[:type]} \n"
103
- # TODO: If details is a Hash need to loop again
104
- end
105
- end
106
-
107
- root_type = @wsdl_schemas.at_xpath("//*[@name='#{details[:input]}']")['type'].split(':').last
108
- root_elements = @wsdl_schemas.xpath("//*[@name='#{root_type}']//xsd:element")
109
- wsdl_to_yaml_for root_elements
110
-
111
- params = []
112
- params << 'convert_request_keys_to: :camelcase' if @use_camel_case
113
- params_string = params == [] ? '' : ', ' + params.join(', ')
114
- @class_params = "'#{camel_case(operation)}'#{params_string}"
115
-
116
- create_file(filename: "config/data/#{operation}.yml", content: @content)
117
- create_file(filename: "spec/#{operation}_spec.rb", content: generated_soap_spec_for(operation))
118
- end
119
- end
120
-
121
- end
122
- end
123
-
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'thor'
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+ require 'savon'
7
+ require 'soaspec'
8
+
9
+ module Soaspec
10
+
11
+ # Common executable for Soaspec
12
+ class Exe < Thor
13
+
14
+ include Soaspec::ExeHelpers
15
+ include Soaspec::WsdlGenerator
16
+
17
+ long_desc <<-LONGDESC
18
+ `soaspec new` will generate the initial files and folders for starting a testing project using soaspec
19
+ \x5
20
+
21
+ `soaspec new soap` will create example files testing against a virtual SOAP service
22
+ \x5
23
+
24
+ `soaspec new rest` will create example files testing against a virtual REST service
25
+ LONGDESC
26
+ desc 'new [type]', 'Initialize soaspec repository'
27
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
28
+ option :virtual, type: :boolean, default: true, banner: 'Whether to set things up for a virtual server'
29
+ def new(type = 'initial')
30
+ @virtual = options[:virtual]
31
+ puts "Creating files for soaspec. options are #{options}"
32
+ create_file(filename: 'Gemfile')
33
+ create_file(filename: 'Rakefile')
34
+ create_file(filename: '.rspec')
35
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
+ create_file(filename: 'README.md')
37
+ create_folder 'lib'
38
+ if type == 'soap'
39
+ create_file filename: 'lib/blz_service.rb'
40
+ create_file filename: 'lib/shared_example.rb'
41
+ end
42
+ create_folder 'config'
43
+ create_folder 'config/data'
44
+ create_file(filename: 'config/data/default.yml')
45
+ create_folder 'spec'
46
+ create_file(filename: 'spec/spec_helper.rb')
47
+ create_file(filename: 'spec/soap_spec.rb') if type == 'soap'
48
+ create_folder 'template'
49
+ create_file(filename: 'template/soap_template.xml', erb: false) if type == 'soap'
50
+ create_folder 'logs'
51
+
52
+ puts "Run 'bundle install' to install necessary gems"
53
+ puts "Run 'rake spec' to run the tests"
54
+ end
55
+
56
+ desc 'generate', 'Generate initial test code from wsdl'
57
+ long_desc <<-LONGDESC
58
+ `soaspec generate wsdl=wsdl name=ServiceName ` will generate the initial files and folders to test each operation in a wsdl
59
+ \x5
60
+ Additionally the auth parameter can be used to use basic authentication to retrieve the WSDL.
61
+ To do use the following `soaspec generate --auth=basic`
62
+
63
+ LONGDESC
64
+ option :wsdl, required: true, aliases: :w
65
+ option :name, default: 'Service', aliases: :n
66
+ option :ci, default: 'jenkins', banner: 'What Continuous Integration is used'
67
+ option :auth
68
+ option :string_default, default: 'test string'
69
+ def generate
70
+ enter_auth_details if options[:auth] == 'basic'
71
+ @virtual = false
72
+ savon_options = { wsdl: options[:wsdl] }
73
+ savon_options[:basic_auth] = [@auth_name, @auth_password] if options[:auth] == 'basic'
74
+
75
+ @wsdl_doc = Savon.client(**savon_options).wsdl
76
+ @wsdl_schemas = @wsdl_doc.parser.schemas
77
+
78
+ create_file filename: 'Rakefile', ignore_if_present: true
79
+ create_file filename: 'Gemfile', ignore_if_present: true
80
+ create_file(filename: '.rspec')
81
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
82
+ create_file filename: 'README.md', ignore_if_present: true
83
+ create_folder 'spec'
84
+ create_file filename: 'spec/spec_helper.rb', ignore_if_present: true
85
+
86
+ create_folder 'logs'
87
+ create_folder 'config'
88
+ create_folder 'config/data'
89
+ create_folder 'lib'
90
+ create_file filename: "lib/#{options[:name].snakecase}.rb", content: class_content
91
+
92
+ # Files according to WSDL
93
+ @wsdl_doc.operations.each do |operation, details|
94
+ puts "Creating files for operation: #{operation}"
95
+ @content = "default:\n"
96
+ @use_camel_case = false
97
+ puts 'Message params: ' + details.to_s
98
+ # From namespace identifier, find namespace, and for that find schemaLocation xsd and use that to build request
99
+ if details[:parameters]
100
+ details[:parameters].each do |element, details|
101
+ @use_camel_case = true if /[[:upper:]]/.match(element.to_s[0]) != nil
102
+ @content += " #{element.to_s.snakecase}: #{fill_in_field_from_type(details[:type])} # #{details[:type]} \n"
103
+ # TODO: If details is a Hash need to loop again
104
+ end
105
+ end
106
+
107
+ root_type = @wsdl_schemas.at_xpath("//*[@name='#{details[:input]}']")['type'].split(':').last
108
+ root_elements = @wsdl_schemas.xpath("//*[@name='#{root_type}']//xsd:element")
109
+ wsdl_to_yaml_for root_elements
110
+
111
+ params = []
112
+ params << 'convert_request_keys_to: :camelcase' if @use_camel_case
113
+ params_string = params == [] ? '' : ', ' + params.join(', ')
114
+ @class_params = "'#{camel_case(operation)}'#{params_string}"
115
+
116
+ create_file(filename: "config/data/#{operation}.yml", content: @content)
117
+ create_file(filename: "spec/#{operation}_spec.rb", content: generated_soap_spec_for(operation))
118
+ end
119
+ end
120
+
121
+ end
122
+ end
123
+
124
124
  Soaspec::Exe.start(ARGV)