pacto 0.4.0.rc1 → 0.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/Gemfile +2 -7
  4. data/Rakefile +0 -5
  5. data/appveyor.yml +12 -0
  6. data/features/configuration/strict_matchers.feature +4 -4
  7. data/features/generate/generation.feature +8 -10
  8. data/features/support/env.rb +3 -7
  9. data/features/validate/validation.feature +3 -3
  10. data/lib/pacto.rb +5 -4
  11. data/lib/pacto/actors/json_generator.rb +1 -1
  12. data/lib/pacto/body_parsing.rb +42 -0
  13. data/lib/pacto/consumer/faraday_driver.rb +5 -2
  14. data/lib/pacto/contract.rb +23 -24
  15. data/lib/pacto/contract_factory.rb +4 -4
  16. data/lib/pacto/core/configuration.rb +18 -10
  17. data/lib/pacto/core/http_middleware.rb +1 -1
  18. data/lib/pacto/core/pacto_request.rb +3 -15
  19. data/lib/pacto/core/pacto_response.rb +3 -13
  20. data/lib/pacto/errors.rb +68 -0
  21. data/lib/pacto/formats/legacy/contract.rb +49 -0
  22. data/lib/pacto/formats/legacy/contract_builder.rb +129 -0
  23. data/lib/pacto/formats/legacy/contract_factory.rb +63 -0
  24. data/lib/pacto/formats/legacy/contract_generator.rb +77 -0
  25. data/lib/pacto/formats/legacy/generator/filters.rb +46 -0
  26. data/lib/pacto/formats/legacy/generator_hint.rb +36 -0
  27. data/lib/pacto/formats/legacy/request_clause.rb +39 -0
  28. data/lib/pacto/formats/legacy/response_clause.rb +31 -0
  29. data/lib/pacto/formats/swagger/contract.rb +86 -0
  30. data/lib/pacto/formats/swagger/contract_factory.rb +45 -0
  31. data/lib/pacto/formats/swagger/request_clause.rb +53 -0
  32. data/lib/pacto/formats/swagger/response_clause.rb +31 -0
  33. data/lib/pacto/generator.rb +4 -4
  34. data/lib/pacto/handlers/json_handler.rb +19 -0
  35. data/lib/pacto/handlers/text_handler.rb +17 -0
  36. data/lib/pacto/request_clause.rb +9 -19
  37. data/lib/pacto/response_clause.rb +4 -4
  38. data/lib/pacto/server.rb +41 -2
  39. data/lib/pacto/stubs/uri_pattern.rb +5 -5
  40. data/lib/pacto/stubs/webmock_adapter.rb +4 -1
  41. data/lib/pacto/test_helper.rb +16 -13
  42. data/lib/pacto/version.rb +1 -1
  43. data/pacto-server.gemspec +1 -3
  44. data/pacto.gemspec +1 -1
  45. data/sample_apis/user_api.rb +16 -0
  46. data/samples/contracts/user.json +51 -0
  47. data/samples/cops.rb +3 -0
  48. data/samples/server_cli.sh +3 -3
  49. data/spec/fabricators/contract_fabricator.rb +17 -8
  50. data/spec/fixtures/{deprecated_contracts → contracts/deprecated}/deprecated_contract.json +2 -2
  51. data/spec/fixtures/contracts/{contract.json → legacy/contract.json} +0 -0
  52. data/spec/fixtures/contracts/{contract_with_examples.json → legacy/contract_with_examples.json} +0 -0
  53. data/spec/fixtures/contracts/{simple_contract.json → legacy/simple_contract.json} +1 -1
  54. data/spec/fixtures/contracts/{strict_contract.json → legacy/strict_contract.json} +0 -0
  55. data/spec/fixtures/contracts/{templating_contract.json → legacy/templating_contract.json} +0 -0
  56. data/spec/fixtures/{swagger → contracts/swagger}/petstore.yaml +0 -0
  57. data/spec/integration/e2e_spec.rb +6 -12
  58. data/spec/integration/forensics/integration_matcher_spec.rb +5 -11
  59. data/spec/integration/rspec_spec.rb +12 -12
  60. data/spec/integration/templating_spec.rb +1 -1
  61. data/spec/spec_helper.rb +14 -2
  62. data/spec/unit/pacto/contract_factory_spec.rb +1 -2
  63. data/spec/unit/pacto/contract_spec.rb +44 -70
  64. data/spec/unit/pacto/core/investigation_spec.rb +4 -3
  65. data/spec/unit/pacto/formats/legacy/contract_builder_spec.rb +93 -0
  66. data/spec/unit/pacto/formats/legacy/contract_factory_spec.rb +29 -0
  67. data/spec/unit/pacto/formats/legacy/contract_generator_spec.rb +173 -0
  68. data/spec/unit/pacto/formats/legacy/contract_spec.rb +41 -0
  69. data/spec/unit/pacto/formats/legacy/generator/filters_spec.rb +104 -0
  70. data/spec/unit/pacto/formats/legacy/request_clause_spec.rb +79 -0
  71. data/spec/unit/pacto/formats/legacy/response_clause_spec.rb +45 -0
  72. data/spec/unit/pacto/formats/swagger/contract_factory_spec.rb +58 -0
  73. data/spec/unit/pacto/formats/swagger/contract_spec.rb +47 -0
  74. data/spec/unit/pacto/investigation_registry_spec.rb +1 -2
  75. data/spec/unit/pacto/pacto_spec.rb +6 -4
  76. data/spec/unit/pacto/stubs/uri_pattern_spec.rb +7 -8
  77. data/spec/unit/pacto/stubs/webmock_adapter_spec.rb +2 -4
  78. data/tasks/release.rake +1 -1
  79. metadata +53 -53
  80. data/lib/pacto/contract_builder.rb +0 -125
  81. data/lib/pacto/exceptions/invalid_contract.rb +0 -12
  82. data/lib/pacto/generator/filters.rb +0 -42
  83. data/lib/pacto/generator/hint.rb +0 -26
  84. data/lib/pacto/generator/native_contract_generator.rb +0 -74
  85. data/lib/pacto/native_contract_factory.rb +0 -60
  86. data/lib/pacto/swagger_contract_factory.rb +0 -90
  87. data/spec/pacto/dummy_server.rb +0 -4
  88. data/spec/pacto/dummy_server/dummy.rb +0 -51
  89. data/spec/pacto/dummy_server/jruby_workaround_helper.rb +0 -23
  90. data/spec/pacto/dummy_server/playback_servlet.rb +0 -22
  91. data/spec/unit/pacto/contract_builder_spec.rb +0 -89
  92. data/spec/unit/pacto/generator/filters_spec.rb +0 -100
  93. data/spec/unit/pacto/generator/native_contract_generator_spec.rb +0 -171
  94. data/spec/unit/pacto/native_contract_factory_spec.rb +0 -26
  95. data/spec/unit/pacto/request_clause_spec.rb +0 -75
  96. data/spec/unit/pacto/response_clause_spec.rb +0 -41
  97. data/spec/unit/pacto/server/playback_servlet_spec.rb +0 -27
  98. data/spec/unit/pacto/swagger_contract_factory_spec.rb +0 -56
@@ -142,10 +142,8 @@ module Pacto
142
142
  )
143
143
  end
144
144
 
145
- it 'uses WebMock to stub the request' do
146
- expect(request_pattern).to receive(:with).
147
- with({}).
148
- and_return(stubbed_request)
145
+ it 'does not send parameter details to WebMock' do
146
+ expect(request_pattern).to_not receive(:with)
149
147
  adapter.stub_request! contract
150
148
  end
151
149
  end
@@ -35,7 +35,7 @@ task :release_gem do
35
35
  end
36
36
 
37
37
  desc 'Releases to RubyGems and GitHub'
38
- task :release => [:build, :release_gem, :documentation, :package, :create_release, :upload_docs]
38
+ task :release => [:build, :release_gem, :samples, :package, :create_release, :upload_docs]
39
39
 
40
40
  desc 'Preview the changelog'
41
41
  task :changelog do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pacto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc1
4
+ version: 0.4.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ThoughtWorks & Abril
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.18'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 1.20.3
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.18'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 1.20.3
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: swagger-core
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -433,6 +427,7 @@ files:
433
427
  - README.md
434
428
  - Rakefile
435
429
  - TODO.md
430
+ - appveyor.yml
436
431
  - bin/pacto
437
432
  - changelog.md
438
433
  - docs/configuration.md
@@ -462,12 +457,12 @@ files:
462
457
  - lib/pacto/actor.rb
463
458
  - lib/pacto/actors/from_examples.rb
464
459
  - lib/pacto/actors/json_generator.rb
460
+ - lib/pacto/body_parsing.rb
465
461
  - lib/pacto/cli.rb
466
462
  - lib/pacto/cli/helpers.rb
467
463
  - lib/pacto/consumer.rb
468
464
  - lib/pacto/consumer/faraday_driver.rb
469
465
  - lib/pacto/contract.rb
470
- - lib/pacto/contract_builder.rb
471
466
  - lib/pacto/contract_factory.rb
472
467
  - lib/pacto/contract_files.rb
473
468
  - lib/pacto/contract_set.rb
@@ -487,19 +482,29 @@ files:
487
482
  - lib/pacto/core/pacto_response.rb
488
483
  - lib/pacto/dash.rb
489
484
  - lib/pacto/erb_processor.rb
490
- - lib/pacto/exceptions/invalid_contract.rb
485
+ - lib/pacto/errors.rb
491
486
  - lib/pacto/extensions.rb
492
487
  - lib/pacto/forensics/investigation_filter.rb
493
488
  - lib/pacto/forensics/investigation_matcher.rb
489
+ - lib/pacto/formats/legacy/contract.rb
490
+ - lib/pacto/formats/legacy/contract_builder.rb
491
+ - lib/pacto/formats/legacy/contract_factory.rb
492
+ - lib/pacto/formats/legacy/contract_generator.rb
493
+ - lib/pacto/formats/legacy/generator/filters.rb
494
+ - lib/pacto/formats/legacy/generator_hint.rb
495
+ - lib/pacto/formats/legacy/request_clause.rb
496
+ - lib/pacto/formats/legacy/response_clause.rb
497
+ - lib/pacto/formats/swagger/contract.rb
498
+ - lib/pacto/formats/swagger/contract_factory.rb
499
+ - lib/pacto/formats/swagger/request_clause.rb
500
+ - lib/pacto/formats/swagger/response_clause.rb
494
501
  - lib/pacto/generator.rb
495
- - lib/pacto/generator/filters.rb
496
- - lib/pacto/generator/hint.rb
497
- - lib/pacto/generator/native_contract_generator.rb
502
+ - lib/pacto/handlers/json_handler.rb
503
+ - lib/pacto/handlers/text_handler.rb
498
504
  - lib/pacto/hooks/erb_hook.rb
499
505
  - lib/pacto/investigation.rb
500
506
  - lib/pacto/logger.rb
501
507
  - lib/pacto/meta_schema.rb
502
- - lib/pacto/native_contract_factory.rb
503
508
  - lib/pacto/observers/stenographer.rb
504
509
  - lib/pacto/provider.rb
505
510
  - lib/pacto/rake_task.rb
@@ -511,7 +516,6 @@ files:
511
516
  - lib/pacto/server.rb
512
517
  - lib/pacto/stubs/uri_pattern.rb
513
518
  - lib/pacto/stubs/webmock_adapter.rb
514
- - lib/pacto/swagger_contract_factory.rb
515
519
  - lib/pacto/test_helper.rb
516
520
  - lib/pacto/ui.rb
517
521
  - lib/pacto/uri.rb
@@ -528,6 +532,7 @@ files:
528
532
  - sample_apis/hello_api.rb
529
533
  - sample_apis/ping_api.rb
530
534
  - sample_apis/reverse_api.rb
535
+ - sample_apis/user_api.rb
531
536
  - samples/README.md
532
537
  - samples/Rakefile
533
538
  - samples/configuration.rb
@@ -537,6 +542,7 @@ files:
537
542
  - samples/contracts/get_album_cover.json
538
543
  - samples/contracts/localhost/api/echo.json
539
544
  - samples/contracts/localhost/api/ping.json
545
+ - samples/contracts/user.json
540
546
  - samples/cops.rb
541
547
  - samples/forensics.rb
542
548
  - samples/generation.rb
@@ -552,28 +558,23 @@ files:
552
558
  - spec/fabricators/contract_fabricator.rb
553
559
  - spec/fabricators/http_fabricator.rb
554
560
  - spec/fabricators/webmock_fabricator.rb
555
- - spec/fixtures/contracts/contract.json
556
- - spec/fixtures/contracts/contract_with_examples.json
557
- - spec/fixtures/contracts/simple_contract.json
558
- - spec/fixtures/contracts/strict_contract.json
559
- - spec/fixtures/contracts/templating_contract.json
560
- - spec/fixtures/deprecated_contracts/deprecated_contract.json
561
- - spec/fixtures/swagger/petstore.yaml
561
+ - spec/fixtures/contracts/deprecated/deprecated_contract.json
562
+ - spec/fixtures/contracts/legacy/contract.json
563
+ - spec/fixtures/contracts/legacy/contract_with_examples.json
564
+ - spec/fixtures/contracts/legacy/simple_contract.json
565
+ - spec/fixtures/contracts/legacy/strict_contract.json
566
+ - spec/fixtures/contracts/legacy/templating_contract.json
567
+ - spec/fixtures/contracts/swagger/petstore.yaml
562
568
  - spec/integration/e2e_spec.rb
563
569
  - spec/integration/forensics/integration_matcher_spec.rb
564
570
  - spec/integration/rspec_spec.rb
565
571
  - spec/integration/templating_spec.rb
566
- - spec/pacto/dummy_server.rb
567
- - spec/pacto/dummy_server/dummy.rb
568
- - spec/pacto/dummy_server/jruby_workaround_helper.rb
569
- - spec/pacto/dummy_server/playback_servlet.rb
570
572
  - spec/spec_helper.rb
571
573
  - spec/unit/actors/from_examples_spec.rb
572
574
  - spec/unit/actors/json_generator_spec.rb
573
575
  - spec/unit/pacto/actor_spec.rb
574
576
  - spec/unit/pacto/configuration_spec.rb
575
577
  - spec/unit/pacto/consumer/faraday_driver_spec.rb
576
- - spec/unit/pacto/contract_builder_spec.rb
577
578
  - spec/unit/pacto/contract_factory_spec.rb
578
579
  - spec/unit/pacto/contract_files_spec.rb
579
580
  - spec/unit/pacto/contract_set_spec.rb
@@ -589,22 +590,24 @@ files:
589
590
  - spec/unit/pacto/core/modes_spec.rb
590
591
  - spec/unit/pacto/erb_processor_spec.rb
591
592
  - spec/unit/pacto/extensions_spec.rb
592
- - spec/unit/pacto/generator/filters_spec.rb
593
- - spec/unit/pacto/generator/native_contract_generator_spec.rb
593
+ - spec/unit/pacto/formats/legacy/contract_builder_spec.rb
594
+ - spec/unit/pacto/formats/legacy/contract_factory_spec.rb
595
+ - spec/unit/pacto/formats/legacy/contract_generator_spec.rb
596
+ - spec/unit/pacto/formats/legacy/contract_spec.rb
597
+ - spec/unit/pacto/formats/legacy/generator/filters_spec.rb
598
+ - spec/unit/pacto/formats/legacy/request_clause_spec.rb
599
+ - spec/unit/pacto/formats/legacy/response_clause_spec.rb
600
+ - spec/unit/pacto/formats/swagger/contract_factory_spec.rb
601
+ - spec/unit/pacto/formats/swagger/contract_spec.rb
594
602
  - spec/unit/pacto/hooks/erb_hook_spec.rb
595
603
  - spec/unit/pacto/investigation_registry_spec.rb
596
604
  - spec/unit/pacto/logger_spec.rb
597
605
  - spec/unit/pacto/meta_schema_spec.rb
598
- - spec/unit/pacto/native_contract_factory_spec.rb
599
606
  - spec/unit/pacto/pacto_spec.rb
600
- - spec/unit/pacto/request_clause_spec.rb
601
607
  - spec/unit/pacto/request_pattern_spec.rb
602
- - spec/unit/pacto/response_clause_spec.rb
603
- - spec/unit/pacto/server/playback_servlet_spec.rb
604
608
  - spec/unit/pacto/stubs/observers/stenographer_spec.rb
605
609
  - spec/unit/pacto/stubs/uri_pattern_spec.rb
606
610
  - spec/unit/pacto/stubs/webmock_adapter_spec.rb
607
- - spec/unit/pacto/swagger_contract_factory_spec.rb
608
611
  - spec/unit/pacto/uri_spec.rb
609
612
  - tasks/release.rake
610
613
  homepage: http://thoughtworks.github.io/pacto/
@@ -648,28 +651,23 @@ test_files:
648
651
  - spec/fabricators/contract_fabricator.rb
649
652
  - spec/fabricators/http_fabricator.rb
650
653
  - spec/fabricators/webmock_fabricator.rb
651
- - spec/fixtures/contracts/contract.json
652
- - spec/fixtures/contracts/contract_with_examples.json
653
- - spec/fixtures/contracts/simple_contract.json
654
- - spec/fixtures/contracts/strict_contract.json
655
- - spec/fixtures/contracts/templating_contract.json
656
- - spec/fixtures/deprecated_contracts/deprecated_contract.json
657
- - spec/fixtures/swagger/petstore.yaml
654
+ - spec/fixtures/contracts/deprecated/deprecated_contract.json
655
+ - spec/fixtures/contracts/legacy/contract.json
656
+ - spec/fixtures/contracts/legacy/contract_with_examples.json
657
+ - spec/fixtures/contracts/legacy/simple_contract.json
658
+ - spec/fixtures/contracts/legacy/strict_contract.json
659
+ - spec/fixtures/contracts/legacy/templating_contract.json
660
+ - spec/fixtures/contracts/swagger/petstore.yaml
658
661
  - spec/integration/e2e_spec.rb
659
662
  - spec/integration/forensics/integration_matcher_spec.rb
660
663
  - spec/integration/rspec_spec.rb
661
664
  - spec/integration/templating_spec.rb
662
- - spec/pacto/dummy_server.rb
663
- - spec/pacto/dummy_server/dummy.rb
664
- - spec/pacto/dummy_server/jruby_workaround_helper.rb
665
- - spec/pacto/dummy_server/playback_servlet.rb
666
665
  - spec/spec_helper.rb
667
666
  - spec/unit/actors/from_examples_spec.rb
668
667
  - spec/unit/actors/json_generator_spec.rb
669
668
  - spec/unit/pacto/actor_spec.rb
670
669
  - spec/unit/pacto/configuration_spec.rb
671
670
  - spec/unit/pacto/consumer/faraday_driver_spec.rb
672
- - spec/unit/pacto/contract_builder_spec.rb
673
671
  - spec/unit/pacto/contract_factory_spec.rb
674
672
  - spec/unit/pacto/contract_files_spec.rb
675
673
  - spec/unit/pacto/contract_set_spec.rb
@@ -685,20 +683,22 @@ test_files:
685
683
  - spec/unit/pacto/core/modes_spec.rb
686
684
  - spec/unit/pacto/erb_processor_spec.rb
687
685
  - spec/unit/pacto/extensions_spec.rb
688
- - spec/unit/pacto/generator/filters_spec.rb
689
- - spec/unit/pacto/generator/native_contract_generator_spec.rb
686
+ - spec/unit/pacto/formats/legacy/contract_builder_spec.rb
687
+ - spec/unit/pacto/formats/legacy/contract_factory_spec.rb
688
+ - spec/unit/pacto/formats/legacy/contract_generator_spec.rb
689
+ - spec/unit/pacto/formats/legacy/contract_spec.rb
690
+ - spec/unit/pacto/formats/legacy/generator/filters_spec.rb
691
+ - spec/unit/pacto/formats/legacy/request_clause_spec.rb
692
+ - spec/unit/pacto/formats/legacy/response_clause_spec.rb
693
+ - spec/unit/pacto/formats/swagger/contract_factory_spec.rb
694
+ - spec/unit/pacto/formats/swagger/contract_spec.rb
690
695
  - spec/unit/pacto/hooks/erb_hook_spec.rb
691
696
  - spec/unit/pacto/investigation_registry_spec.rb
692
697
  - spec/unit/pacto/logger_spec.rb
693
698
  - spec/unit/pacto/meta_schema_spec.rb
694
- - spec/unit/pacto/native_contract_factory_spec.rb
695
699
  - spec/unit/pacto/pacto_spec.rb
696
- - spec/unit/pacto/request_clause_spec.rb
697
700
  - spec/unit/pacto/request_pattern_spec.rb
698
- - spec/unit/pacto/response_clause_spec.rb
699
- - spec/unit/pacto/server/playback_servlet_spec.rb
700
701
  - spec/unit/pacto/stubs/observers/stenographer_spec.rb
701
702
  - spec/unit/pacto/stubs/uri_pattern_spec.rb
702
703
  - spec/unit/pacto/stubs/webmock_adapter_spec.rb
703
- - spec/unit/pacto/swagger_contract_factory_spec.rb
704
704
  - spec/unit/pacto/uri_spec.rb
@@ -1,125 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module Pacto
3
- class ContractBuilder < Hashie::Dash # rubocop:disable Metrics/ClassLength
4
- extend Forwardable
5
- attr_accessor :source
6
-
7
- def initialize(options = {})
8
- @schema_generator = options[:schema_generator] ||= JSON::SchemaGenerator
9
- @filters = options[:filters] ||= Pacto::Generator::Filters.new
10
- @data = { request: {}, response: {}, examples: {} }
11
- @source = 'Pacto' # Currently used by JSONSchemaGeneator, but not really useful
12
- end
13
-
14
- def name=(name)
15
- @data[:name] = name
16
- end
17
-
18
- def add_example(name, pacto_request, pacto_response)
19
- @data[:examples][name] ||= {}
20
- @data[:examples][name][:request] = clean(pacto_request.to_hash)
21
- @data[:examples][name][:response] = clean(pacto_response.to_hash)
22
- self
23
- end
24
-
25
- def infer_all
26
- # infer_file # The target file is being chosen inferred by the Generator
27
- infer_name
28
- infer_schemas
29
- end
30
-
31
- def infer_name
32
- if @data[:examples].empty?
33
- @data[:name] = @data[:request][:path] if @data[:request]
34
- return self
35
- end
36
-
37
- example, hint = example_and_hint
38
- @data[:name] = hint.nil? ? PactoRequest.new(example[:request]).uri.path : hint.service_name
39
- self
40
- end
41
-
42
- def infer_schemas
43
- return self if @data[:examples].empty?
44
-
45
- # TODO: It'd be awesome if we could infer across all examples
46
- example, _hint = example_and_hint
47
- sample_request_body = example[:request][:body]
48
- sample_response_body = example[:response][:body]
49
- @data[:request][:schema] = generate_schema(sample_request_body) if sample_request_body && !sample_request_body.empty?
50
- @data[:response][:schema] = generate_schema(sample_response_body) if sample_response_body && !sample_response_body.empty?
51
- self
52
- end
53
-
54
- def without_examples
55
- @export_examples = false
56
- self
57
- end
58
-
59
- def generate_contract(request, response)
60
- generate_request(request, response)
61
- generate_response(request, response)
62
- infer_all
63
- self
64
- end
65
-
66
- def generate_request(request, response)
67
- hint = hint_for(request)
68
- request = clean(
69
- headers: @filters.filter_request_headers(request, response),
70
- http_method: request.method,
71
- params: request.uri.query_values,
72
- path: hint.nil? ? request.uri.path : hint.path
73
- )
74
- @data[:request] = request
75
- self
76
- end
77
-
78
- def generate_response(request, response)
79
- response = clean(
80
- headers: @filters.filter_response_headers(request, response),
81
- status: response.status
82
- )
83
- @data[:response] = response
84
- self
85
- end
86
-
87
- def build_hash
88
- instance_eval(&block) if block_given?
89
- @final_data = @data.dup
90
- @final_data.delete(:examples) if exclude_examples?
91
- clean(@final_data)
92
- end
93
-
94
- def build(&block)
95
- Contract.new build_hash(&block)
96
- end
97
-
98
- protected
99
-
100
- def example_and_hint
101
- example = @data[:examples].values.first
102
- example_request = PactoRequest.new example[:request]
103
- [example, Pacto::Generator.hint_for(example_request)]
104
- end
105
-
106
- def exclude_examples?
107
- @export_examples == false
108
- end
109
-
110
- def generate_schema(body, generator_options = Pacto.configuration.generator_options)
111
- return if body.nil? || body.empty?
112
-
113
- body_schema = @schema_generator.generate @source, body, generator_options
114
- MultiJson.load(body_schema)
115
- end
116
-
117
- def clean(data)
118
- data.delete_if { |_k, v| v.nil? }
119
- end
120
-
121
- def hint_for(pacto_request)
122
- Pacto::Generator.hint_for(pacto_request)
123
- end
124
- end
125
- end
@@ -1,12 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- class InvalidContract < ArgumentError
3
- attr_reader :errors
4
-
5
- def initialize(errors)
6
- @errors = errors
7
- end
8
-
9
- def message
10
- @errors.join "\n"
11
- end
12
- end
@@ -1,42 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module Pacto
3
- module Generator
4
- class Filters
5
- CONNECTION_CONTROL_HEADERS = %w(
6
- Via
7
- Server
8
- Connection
9
- Transfer-Encoding
10
- Content-Length
11
- )
12
-
13
- FRESHNESS_HEADERS =
14
- %w(
15
- Date
16
- Last-Modified
17
- ETag
18
- )
19
-
20
- HEADERS_TO_FILTER = CONNECTION_CONTROL_HEADERS + FRESHNESS_HEADERS
21
-
22
- def filter_request_headers(request, response)
23
- # FIXME: Do we need to handle all these cases in real situations, or just because of stubbing?
24
- vary_headers = response.headers['vary'] || response.headers['Vary'] || []
25
- vary_headers = [vary_headers] if vary_headers.is_a? String
26
- vary_headers = vary_headers.map do |h|
27
- h.split(',').map(&:strip)
28
- end.flatten
29
-
30
- request.headers.select do |header|
31
- vary_headers.map(&:downcase).include? header.downcase
32
- end
33
- end
34
-
35
- def filter_response_headers(_request, response)
36
- Pacto::Extensions.normalize_header_keys(response.headers).reject do |header|
37
- (HEADERS_TO_FILTER.include? header) || (header.start_with?('X-'))
38
- end
39
- end
40
- end
41
- end
42
- end