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
@@ -1,57 +1,57 @@
1
-
2
- require 'fileutils'
3
- module Soaspec
4
- # Help with tasks common to soaspec executables
5
- module ExeHelpers
6
-
7
- # Spec task string depending upon whether virtual is used
8
- def spec_task
9
- task_name = options[:virtual] ? 'spec: :start_test_server' : ':spec'
10
- "RSpec::Core::RakeTask.new(#{task_name}) do |t|"
11
- end
12
-
13
- # Retrieve default file contents based on filename
14
- def retrieve_contents(filename, erb)
15
- default_file = File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : ''))
16
- contents = File.read(default_file)
17
- erb ? ERB.new(contents).result(binding) : contents
18
- end
19
-
20
- # @param [String] filename Name of the file to create
21
- # @param [String] content Content to place inside file
22
- def create_file(filename: nil, content: nil, ignore_if_present: false, erb: true)
23
- raise 'Need to pass filename' unless filename
24
- content ||= retrieve_contents(filename, erb)
25
- if File.exist? filename
26
- old_content = File.read(filename)
27
- if old_content != content && !ignore_if_present
28
- warn "!! #{filename} already exists and differs from template"
29
- end
30
- else
31
- File.open(filename, 'w') { |f| f.puts content }
32
- puts 'Created: ' + filename
33
- end
34
- end
35
-
36
- def create_folder(folder)
37
- if File.exist? folder
38
- warn "!! #{folder} already exists and is not a directory" unless File.directory? folder
39
- else
40
- FileUtils.mkdir folder
41
- puts "Created folder: #{folder}/"
42
- end
43
- end
44
-
45
- # Create class representing wsdl in general
46
- def class_content
47
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'lib/dynamic_class_content.rb.erb'))).result(binding)
48
- end
49
-
50
- # Create a spec for an WSDL operation
51
- # @param [String] operation Used in ERB to create a test for a WSDL operation
52
- def generated_soap_spec_for(operation)
53
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'spec/dynamic_soap_spec.rb.erb'))).result(binding)
54
- end
55
-
56
- end
1
+
2
+ require 'fileutils'
3
+ module Soaspec
4
+ # Help with tasks common to soaspec executables
5
+ module ExeHelpers
6
+
7
+ # Spec task string depending upon whether virtual is used
8
+ def spec_task
9
+ task_name = options[:virtual] ? 'spec: :start_test_server' : ':spec'
10
+ "RSpec::Core::RakeTask.new(#{task_name}) do |t|"
11
+ end
12
+
13
+ # Retrieve default file contents based on filename
14
+ def retrieve_contents(filename, erb)
15
+ default_file = File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : ''))
16
+ contents = File.read(default_file)
17
+ erb ? ERB.new(contents).result(binding) : contents
18
+ end
19
+
20
+ # @param [String] filename Name of the file to create
21
+ # @param [String] content Content to place inside file
22
+ def create_file(filename: nil, content: nil, ignore_if_present: false, erb: true)
23
+ raise 'Need to pass filename' unless filename
24
+ content ||= retrieve_contents(filename, erb)
25
+ if File.exist? filename
26
+ old_content = File.read(filename)
27
+ if old_content != content && !ignore_if_present
28
+ warn "!! #{filename} already exists and differs from template"
29
+ end
30
+ else
31
+ File.open(filename, 'w') { |f| f.puts content }
32
+ puts 'Created: ' + filename
33
+ end
34
+ end
35
+
36
+ def create_folder(folder)
37
+ if File.exist? folder
38
+ warn "!! #{folder} already exists and is not a directory" unless File.directory? folder
39
+ else
40
+ FileUtils.mkdir folder
41
+ puts "Created folder: #{folder}/"
42
+ end
43
+ end
44
+
45
+ # Create class representing wsdl in general
46
+ def class_content
47
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'lib/dynamic_class_content.rb.erb'))).result(binding)
48
+ end
49
+
50
+ # Create a spec for an WSDL operation
51
+ # @param [String] operation Used in ERB to create a test for a WSDL operation
52
+ def generated_soap_spec_for(operation)
53
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'spec/dynamic_soap_spec.rb.erb'))).result(binding)
54
+ end
55
+
56
+ end
57
57
  end
@@ -1,5 +1,5 @@
1
- --require spec_helper
2
- --format documentation
3
- <%= '--format RspecJunitFormatter --out logs/spec.xml' if options[:ci] == 'jenkins' %>
4
- --format html --out logs/spec.html
5
- --color
1
+ --require spec_helper
2
+ --format documentation
3
+ <%= '--format RspecJunitFormatter --out logs/spec.xml' if options[:ci] == 'jenkins' %>
4
+ --format html --out logs/spec.html
5
+ --color
@@ -1,5 +1,5 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.4
5
- before_install: gem install bundler -v 1.16.0
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.0
@@ -1,8 +1,8 @@
1
-
2
- source 'https://rubygems.org'
3
-
4
- gem 'data_magic'
5
- gem 'require_all'
6
- gem 'rake'
7
- <%= "gem 'rspec_junit_formatter'" if options[:ci] == 'jenkins' %>
8
- gem 'soaspec'
1
+
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'data_magic'
5
+ gem 'require_all'
6
+ gem 'rake'
7
+ <%= "gem 'rspec_junit_formatter'" if options[:ci] == 'jenkins' %>
8
+ gem 'soaspec'
@@ -1,29 +1,29 @@
1
-
2
- # Installation
3
-
4
- Run `bundle install` to install the gems mentioned in the Gemfile.
5
-
6
- To avoid conflict with gems on the machine globally it may be better to specify gem location with:
7
-
8
- `bundle install --path ~/.gem`
9
-
10
- # Running tests
11
- On the command line type:
12
- `bundle exec rake spec` or simply `bundle exec rake`
13
-
14
- # Structure
15
-
16
- ## Tests
17
- RSpec tests are within the `spec` folder and end in `_spec`. Setup and teardown for tests is in `spec/spec_helper`
18
-
19
- ## Templates
20
- These are the base requests with ERB inside them to create smartly changing requests accoring to the test.yml
21
-
22
- ## Data
23
- Data used in the test is stored in `config/data` folder. The `data_magic` gem is used by default to read files here.
24
-
25
- ## Libraries
26
- Libaries to be installed are in 'Gemfile'. Specific gem versions can be specified here and enforeced with `bundle exec rake`
27
-
28
- ## Reports
29
- Reports are shown in the 'logs' folder. By default Rake produces a junit, an html report, and a `traffic.log` file with the API request and responses in it
1
+
2
+ # Installation
3
+
4
+ Run `bundle install` to install the gems mentioned in the Gemfile.
5
+
6
+ To avoid conflict with gems on the machine globally it may be better to specify gem location with:
7
+
8
+ `bundle install --path ~/.gem`
9
+
10
+ # Running tests
11
+ On the command line type:
12
+ `bundle exec rake spec` or simply `bundle exec rake`
13
+
14
+ # Structure
15
+
16
+ ## Tests
17
+ RSpec tests are within the `spec` folder and end in `_spec`. Setup and teardown for tests is in `spec/spec_helper`
18
+
19
+ ## Templates
20
+ These are the base requests with ERB inside them to create smartly changing requests accoring to the test.yml
21
+
22
+ ## Data
23
+ Data used in the test is stored in `config/data` folder. The `data_magic` gem is used by default to read files here.
24
+
25
+ ## Libraries
26
+ Libaries to be installed are in 'Gemfile'. Specific gem versions can be specified here and enforeced with `bundle exec rake`
27
+
28
+ ## Reports
29
+ Reports are shown in the 'logs' folder. By default Rake produces a junit, an html report, and a `traffic.log` file with the API request and responses in it
@@ -1,20 +1,20 @@
1
-
2
- # The list of task for a Rake file can be seen with `rake -T`
3
- require 'rspec/core/rake_task' # See https://relishapp.com/rspec/rspec-core/docs/command-line/rake-task for details
4
-
5
- # This runs `rspec` command with the following options. Type `rake spec` to run this task
6
- <%= spec_task %>
7
- t.pattern = "spec/*_spec.rb" # Run all specs in 'spec' folder ending in '_spec'
8
- <%= 't.fail_on_error = false' if options[:ci] == 'jenkins' %>
9
- end
10
-
11
- task default: :spec # This runs the 'spec' task by default when no task is mentioned. E.g., if only `rake` is typed
12
-
13
- <% if @virtual %>
14
- desc 'Start virtual web service'
15
- task :start_test_server do
16
- ENV['test_server_pid'] = Process.spawn('soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
17
- puts 'Running test server at pid ' + ENV['test_server_pid']
18
- sleep 0.5 # Wait a little for virtual server to start up
19
- end
1
+
2
+ # The list of task for a Rake file can be seen with `rake -T`
3
+ require 'rspec/core/rake_task' # See https://relishapp.com/rspec/rspec-core/docs/command-line/rake-task for details
4
+
5
+ # This runs `rspec` command with the following options. Type `rake spec` to run this task
6
+ <%= spec_task %>
7
+ t.pattern = "spec/*_spec.rb" # Run all specs in 'spec' folder ending in '_spec'
8
+ <%= 't.fail_on_error = false' if options[:ci] == 'jenkins' %>
9
+ end
10
+
11
+ task default: :spec # This runs the 'spec' task by default when no task is mentioned. E.g., if only `rake` is typed
12
+
13
+ <% if @virtual %>
14
+ desc 'Start virtual web service'
15
+ task :start_test_server do
16
+ ENV['test_server_pid'] = Process.spawn('soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
17
+ puts 'Running test server at pid ' + ENV['test_server_pid']
18
+ sleep 0.5 # Wait a little for virtual server to start up
19
+ end
20
20
  <% end %>
@@ -1,2 +1,2 @@
1
- small_id:
1
+ small_id:
2
2
  blz: 100
@@ -1,24 +1,24 @@
1
-
2
- require 'soaspec'
3
-
4
- # This class is not part of the gem. It's an example of a class you can make
5
- # to describe your APIs. Usually this would exist in the 'lib' directory
6
- # Common configuration for the Savon client should go here
7
- class BLZService < Soaspec::SoapHandler
8
- # Add to or override default Savon client options
9
- def savon_options
10
- {
11
- wsdl: 'http://localhost:4999/BLZService?wsdl'
12
- }
13
- end
14
-
15
- # # Specifying that get_weather_result must be present in the SOAP response
16
- mandatory_elements [:plz]
17
-
18
- # Example of xpath value that must be true for all success scenarios
19
- mandatory_xpath_values 'ns1:bezeichnung' => 'Deutsche Bank'
20
-
21
- # Example of setting an attribute on the root XML element
22
- root_attributes 'Version' => '1'
23
-
24
- end
1
+
2
+ require 'soaspec'
3
+
4
+ # This class is not part of the gem. It's an example of a class you can make
5
+ # to describe your APIs. Usually this would exist in the 'lib' directory
6
+ # Common configuration for the Savon client should go here
7
+ class BLZService < Soaspec::SoapHandler
8
+ # Add to or override default Savon client options
9
+ def savon_options
10
+ {
11
+ wsdl: 'http://localhost:4999/BLZService?wsdl'
12
+ }
13
+ end
14
+
15
+ # # Specifying that get_weather_result must be present in the SOAP response
16
+ mandatory_elements [:plz]
17
+
18
+ # Example of xpath value that must be true for all success scenarios
19
+ mandatory_xpath_values 'ns1:bezeichnung' => 'Deutsche Bank'
20
+
21
+ # Example of setting an attribute on the root XML element
22
+ root_attributes 'Version' => '1'
23
+
24
+ end
@@ -1,12 +1,12 @@
1
-
2
- require 'soaspec'
3
-
4
- class <%= options[:name] %> < Soaspec::SoapHandler
5
- # Add to or override default Savon client options
6
- def savon_options
7
- {
8
- wsdl: '<%= options[:wsdl] %>'
9
- }
10
- end
11
-
12
- end
1
+
2
+ require 'soaspec'
3
+
4
+ class <%= options[:name] %> < Soaspec::SoapHandler
5
+ # Add to or override default Savon client options
6
+ def savon_options
7
+ {
8
+ wsdl: '<%= options[:wsdl] %>'
9
+ }
10
+ end
11
+
12
+ end
@@ -1,8 +1,8 @@
1
-
2
- require 'rspec'
3
-
4
- shared_examples_for 'error scenario' do
5
- it 'does not have status code of 200' do
6
- expect(described_class.status_code).not_to eq 200
7
- end
8
- end
1
+
2
+ require 'rspec'
3
+
4
+ shared_examples_for 'error scenario' do
5
+ it 'does not have status code of 200' do
6
+ expect(described_class.status_code).not_to eq 200
7
+ end
8
+ end
@@ -1,14 +1,14 @@
1
-
2
- require 'spec_helper'
3
-
4
- Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
5
-
6
- <%= operation %> = <%= options[:name] %>.new(<%= @class_params %>)
7
- <%= operation %>.operation = :<%= operation %>
8
- <%= operation %>.default_hash = data_for '<%= operation %>/default'
9
-
10
- context <%= operation %> do
11
- describe Exchange.new(:default) do
12
- it_behaves_like 'success scenario'
13
- end
14
- end
1
+
2
+ require 'spec_helper'
3
+
4
+ Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
5
+
6
+ <%= operation %> = <%= options[:name] %>.new(<%= @class_params %>)
7
+ <%= operation %>.operation = :<%= operation %>
8
+ <%= operation %>.default_hash = data_for '<%= operation %>/default'
9
+
10
+ context <%= operation %> do
11
+ describe Exchange.new(:default) do
12
+ it_behaves_like 'success scenario'
13
+ end
14
+ end
@@ -1,53 +1,53 @@
1
-
2
- require 'spec_helper'
3
-
4
- Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
5
-
6
- id = '70070010'
7
- # BLZService.new(template_name: 'soap_template') Use this instead of default_hash to use template approach
8
-
9
- context 'Test Examples' do
10
- context BLZService.new('Get Bank', operation: :get_bank, default_hash: { blz: id }) do
11
-
12
- describe Exchange.new(:default) do
13
- it { is_expected.to contain_value id }
14
- it { is_expected.to include_in_body id }
15
- it_behaves_like 'success scenario'
16
- after(:all) { described_class.store(:title, 'bezeichnung') }
17
- end
18
-
19
- describe Exchange.new(:xpath_eg, blz: 100000) do
20
- its(['plz']) { is_expected.to eq '100000' }
21
- it { is_expected.to have_xpath_value '//ns1:bezeichnung' => 'Deutsche Bank' }
22
- context 'Handle retrieving stored value' do
23
- it { is_expected.to have_xpath_value 'bezeichnung' => described_class.retrieve(:title) }
24
- end
25
- end
26
-
27
- describe Exchange.new(:yaml_eg, data_for(:small_id)) do
28
- it_behaves_like 'success scenario'
29
- end
30
-
31
- # Retry for success more for web services that intermittently fail
32
- describe Exchange.new(:short_hand_xpath).retry_for_success do
33
- # Be careful. If you call a method that does not use namespaces, calling one that does may not find the element
34
- its(['ns1:bezeichnung']) { is_expected.to eq 'Deutsche Bank' } # '//' is not required at the beginning
35
- end
36
- describe Exchange.new('Check existence of elements') do
37
- it { is_expected.to have_element_at_xpath '//ns1:bezeichnung' }
38
- it { is_expected.not_to have_element_at_xpath '//ns1:bezeichnung_pretend' }
39
- end
40
- end
41
- end
42
-
43
- error_example = BLZService.new('Error example')
44
- error_example.operation = :get_bank
45
- error_example.default_hash = {}
46
-
47
- context 'Error Examples' do
48
- context error_example do
49
- describe Exchange.new(:no_blz_error) do
50
- it_behaves_like 'error scenario'
51
- end
52
- end
53
- end
1
+
2
+ require 'spec_helper'
3
+
4
+ Soaspec.strip_namespaces = true # This allows namespace not to be used. Be careful with this
5
+
6
+ id = '70070010'
7
+ # BLZService.new(template_name: 'soap_template') Use this instead of default_hash to use template approach
8
+
9
+ context 'Test Examples' do
10
+ context BLZService.new('Get Bank', operation: :get_bank, default_hash: { blz: id }) do
11
+
12
+ describe Exchange.new(:default) do
13
+ it { is_expected.to contain_value id }
14
+ it { is_expected.to include_in_body id }
15
+ it_behaves_like 'success scenario'
16
+ after(:all) { described_class.store(:title, 'bezeichnung') }
17
+ end
18
+
19
+ describe Exchange.new(:xpath_eg, blz: 100000) do
20
+ its(['plz']) { is_expected.to eq '100000' }
21
+ it { is_expected.to have_xpath_value '//ns1:bezeichnung' => 'Deutsche Bank' }
22
+ context 'Handle retrieving stored value' do
23
+ it { is_expected.to have_xpath_value 'bezeichnung' => described_class.retrieve(:title) }
24
+ end
25
+ end
26
+
27
+ describe Exchange.new(:yaml_eg, data_for(:small_id)) do
28
+ it_behaves_like 'success scenario'
29
+ end
30
+
31
+ # Retry for success more for web services that intermittently fail
32
+ describe Exchange.new(:short_hand_xpath).retry_for_success do
33
+ # Be careful. If you call a method that does not use namespaces, calling one that does may not find the element
34
+ its(['ns1:bezeichnung']) { is_expected.to eq 'Deutsche Bank' } # '//' is not required at the beginning
35
+ end
36
+ describe Exchange.new('Check existence of elements') do
37
+ it { is_expected.to have_element_at_xpath '//ns1:bezeichnung' }
38
+ it { is_expected.not_to have_element_at_xpath '//ns1:bezeichnung_pretend' }
39
+ end
40
+ end
41
+ end
42
+
43
+ error_example = BLZService.new('Error example')
44
+ error_example.operation = :get_bank
45
+ error_example.default_hash = {}
46
+
47
+ context 'Error Examples' do
48
+ context error_example do
49
+ describe Exchange.new(:no_blz_error) do
50
+ it_behaves_like 'error scenario'
51
+ end
52
+ end
53
+ end