pact_expectations 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a1031066985d1224c3f5b3dc5a806cc8cdf833d
4
+ data.tar.gz: afe2226aa8917a460ce2de8ad969221e04adb6fb
5
+ SHA512:
6
+ metadata.gz: d0adb91f2d52689abd413122e252ce831667076130349970a5de0d20ab31f93f1cd5207267254a0c80f3a3357377837a97d8373ceaf28f702a5743477f56d83d
7
+ data.tar.gz: fa3113fc50a3ed05dc1e2e5b5cd7a063842097381c8b15eb462bfbfc0b07cb67685518f078489e7d32aca390bc53b63997fd1d234ad923c0beeae2166c59829b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pact_expectations.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # PactExpectations
2
+
3
+ Pact response convert to stub.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pact_expectations'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pact_expectations
20
+
21
+ ## Usage
22
+
23
+ for example
24
+
25
+ ```ruby
26
+ class APIClient
27
+ def item(id)
28
+ # api request
29
+ end
30
+ end
31
+
32
+ PactExpectations.add_response_body_for(
33
+ "a request for an item",
34
+ Pact.like(
35
+ id: 1,
36
+ name: "pen",
37
+ ),
38
+ )
39
+
40
+ ## Pact spec
41
+ describe APIClient, pact: true do
42
+ describe "#item" do
43
+ before do
44
+ api
45
+ .given("an item exists")
46
+ .upon_receiving("a request for an item")
47
+ .with(method: :get, path: "/item/1")
48
+ .will_respond_with(
49
+ status: 200,
50
+ body: PactExpectations.response_body_for("a request for an item"),
51
+ )
52
+ end
53
+ it { expect(APIClient.item(1).name).to eq "pen" }
54
+ end
55
+ end
56
+ end
57
+
58
+ ## stab
59
+ describe ItemsController do
60
+ describe "show" do
61
+ before do
62
+ allow(APIClient).to(
63
+ receive(:item).with(1).and_return(PactExpectations.reificated_body_for("a request for an item"))
64
+ )
65
+ end
66
+ it do
67
+ get :show, id: 1
68
+ expect(assigns[:item].name).to eq "pen"
69
+ end
70
+ end
71
+ end
72
+ ```
73
+
74
+ ### Verify expectation was called.
75
+
76
+ ```ruby
77
+ RSpec.configure do |config|
78
+ config.after(:suite) do
79
+ PactExpectations.verify if ENV["PACT_VERIFY_EXPECTATIONS"] == "1"
80
+ end
81
+ end
82
+ ```
83
+
84
+ ## Development
85
+
86
+ 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.
87
+
88
+ 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).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshiori/pact_expectations.
93
+
94
+ ## Special Thanks
95
+ [Taiki Ono](https://github.com/taiki45) gave me a lot of advice.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,88 @@
1
+ require "pact_expectations/version"
2
+ require "pact/support/version"
3
+ require "set"
4
+
5
+ class PactExpectations
6
+ class << self
7
+ def add_response_body_for(key, expectation = {})
8
+ raise DuplicatedKey if expectations.include?(key)
9
+ expectations[key] = expectation
10
+ end
11
+
12
+ def response_body_for(key)
13
+ raise NotFound unless expectations.include?(key)
14
+ response_call << key
15
+ expectations[key]
16
+ end
17
+
18
+ def reificated_body_for(key)
19
+ raise NotFound unless expectations.include?(key)
20
+ reificated_call << key
21
+ Pact::Reification.from_term(expectations[key])
22
+ end
23
+
24
+ def verify
25
+ not_call_responses = response_call ^ expectations.keys
26
+ not_call_reificated = reificated_call ^ expectations.keys
27
+
28
+ if !not_call_responses.empty? || !not_call_reificated.empty?
29
+ raise VerifyError.new(not_call_responses, not_call_reificated)
30
+ end
31
+ end
32
+
33
+ def reset!
34
+ @expectations = nil
35
+ @response_call = nil
36
+ @reificated_call = nil
37
+ end
38
+
39
+ private
40
+
41
+ def expectations
42
+ @expectations ||= {}
43
+ end
44
+
45
+ def response_call
46
+ @response_call ||= Set.new
47
+ end
48
+
49
+ def reificated_call
50
+ @reificated_call ||= Set.new
51
+ end
52
+ end
53
+ end
54
+ class PactExpectations::NotFound < StandardError; end
55
+ class PactExpectations::DuplicatedKey < StandardError; end
56
+ class PactExpectations::VerifyError < StandardError
57
+ def initialize(not_call_responses = [], not_call_reificated = [])
58
+ @not_call_responses = not_call_responses
59
+ @not_call_reificated = not_call_reificated
60
+ end
61
+
62
+ def message
63
+ message = String.new("\n")
64
+ unless @not_call_responses.empty?
65
+ message << create_not_call_message(
66
+ "Some expectations were defined but not used to construct the Contract",
67
+ @not_call_responses
68
+ )
69
+ end
70
+ unless @not_call_reificated.empty?
71
+ message << create_not_call_message(
72
+ "Some expectations were defined but not used to stub Remote Facade",
73
+ @not_call_reificated
74
+ )
75
+ end
76
+ message
77
+ end
78
+
79
+ private
80
+
81
+ def create_not_call_message(title, list)
82
+ message = String.new("#{title}:\n")
83
+ list.each do |key|
84
+ message << "- #{key}\n"
85
+ end
86
+ message << "\n"
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ class PactExpectations
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pact_expectations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pact_expectations"
8
+ spec.version = PactExpectations::VERSION
9
+ spec.authors = ["Yoshiori SHOJI"]
10
+ spec.email = ["yoshiori@gmail.com"]
11
+
12
+ spec.summary = %q{Pact response convert to stub.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/yoshiori/pact_expectations"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "pact-support", "~> 0.5.4"
20
+
21
+ spec.add_development_dependency "pact", "~> 1.9"
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pact_expectations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiori SHOJI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pact-support
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: pact
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Pact response convert to stub.
84
+ email:
85
+ - yoshiori@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - lib/pact_expectations.rb
97
+ - lib/pact_expectations/version.rb
98
+ - pact_expectations.gemspec
99
+ homepage: https://github.com/yoshiori/pact_expectations
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Pact response convert to stub.
122
+ test_files: []