webtrap 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e32a4e898ff867cc637d3d172aac40ded927bc32
4
+ data.tar.gz: 32235a98f61b4479aa6e3d1d96bfa481e1ecfe8e
5
+ SHA512:
6
+ metadata.gz: 741d50fb982ea969bc9630abae14ba8ddc7269b300ca82c4fdae8e1c7d1f9ea86e0622e0fde45617e7c6a7f56415d49b6687cc9cae1286567697c27363aee99a
7
+ data.tar.gz: 42b5e1a259c7904857dbf27b35f268f7cd962dc882f7bdb0852b98d875110a6f35dfb670084b09f7cc2d9fa533fba0bc7902811c52e4e5af6d7674f794a6d5af
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ webtrap (0.0.0)
5
+ equivalent-xml (~> 0.6.0)
6
+ rspec (~> 3.0)
7
+ sinatra (~> 1.0)
8
+ webmock (~> 2.0)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ addressable (2.5.0)
14
+ public_suffix (~> 2.0, >= 2.0.2)
15
+ builder (3.2.3)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ cucumber (2.4.0)
19
+ builder (>= 2.1.2)
20
+ cucumber-core (~> 1.5.0)
21
+ cucumber-wire (~> 0.0.1)
22
+ diff-lcs (>= 1.1.3)
23
+ gherkin (~> 4.0)
24
+ multi_json (>= 1.7.5, < 2.0)
25
+ multi_test (>= 0.1.2)
26
+ cucumber-core (1.5.0)
27
+ gherkin (~> 4.0)
28
+ cucumber-wire (0.0.1)
29
+ diff-lcs (1.3)
30
+ equivalent-xml (0.6.0)
31
+ nokogiri (>= 1.4.3)
32
+ gherkin (4.0.0)
33
+ hashdiff (0.3.2)
34
+ mini_portile2 (2.1.0)
35
+ multi_json (1.12.1)
36
+ multi_test (0.1.2)
37
+ nokogiri (1.6.8.1)
38
+ mini_portile2 (~> 2.1.0)
39
+ public_suffix (2.0.5)
40
+ rack (1.6.5)
41
+ rack-protection (1.5.3)
42
+ rack
43
+ rake (10.4.2)
44
+ rspec (3.5.0)
45
+ rspec-core (~> 3.5.0)
46
+ rspec-expectations (~> 3.5.0)
47
+ rspec-mocks (~> 3.5.0)
48
+ rspec-core (3.5.4)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-expectations (3.5.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.5.0)
53
+ rspec-mocks (3.5.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.5.0)
56
+ rspec-support (3.5.0)
57
+ safe_yaml (1.0.4)
58
+ sinatra (1.4.8)
59
+ rack (~> 1.5)
60
+ rack-protection (~> 1.4)
61
+ tilt (>= 1.3, < 3)
62
+ tilt (2.0.6)
63
+ webmock (2.3.2)
64
+ addressable (>= 2.3.6)
65
+ crack (>= 0.3.2)
66
+ hashdiff
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ bundler (~> 1.13)
73
+ cucumber (~> 2.0)
74
+ rake (~> 10.0)
75
+ webtrap!
76
+
77
+ BUNDLED WITH
78
+ 1.13.6
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Pedro Costa
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.
22
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Send Request
2
+ ============
3
+
4
+ Not the best name for this.
@@ -0,0 +1,43 @@
1
+ require "webmock/rspec"
2
+
3
+ module WebTrap
4
+ module RSpec
5
+ module Matchers
6
+ class SendRequest
7
+ def matches?(transmission_proc)
8
+ perform_transmission(transmission_proc)
9
+ request_sent?
10
+ end
11
+
12
+ def failure_message
13
+ "expected block to send an HTTP request, but nothing was sent out"
14
+ end
15
+
16
+ def supports_block_expectations?
17
+ true
18
+ end
19
+
20
+ def with_xml(xml)
21
+ SendRequestWithXml.new(xml)
22
+ end
23
+
24
+ private
25
+
26
+ def perform_transmission(transmission_proc)
27
+ WebMock.disable_net_connect!
28
+ begin
29
+ transmission_proc.call
30
+ @request_sent = false
31
+ rescue WebMock::NetConnectNotAllowedError
32
+ @request_sent = true
33
+ end
34
+ WebMock.allow_net_connect!
35
+ end
36
+
37
+ def request_sent?
38
+ @request_sent
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ require "equivalent-xml"
2
+ require "webmock/rspec"
3
+
4
+ module WebTrap
5
+ module RSpec
6
+ module Matchers
7
+ class SendRequestWithXml < SendRequest
8
+ attr_reader :expected_payload
9
+
10
+ def initialize(expected_payload)
11
+ @expected_payload = expected_payload
12
+ end
13
+
14
+ def matches?(transmission_proc)
15
+ perform_transmission(transmission_proc)
16
+ request_sent? && valid_payload?
17
+ end
18
+
19
+ def failure_message
20
+ return super unless request_sent?
21
+
22
+ "expected block to send an HTTP request with XML body, but payload was not equivalent"
23
+ end
24
+
25
+ def supports_block_expectations?
26
+ true
27
+ end
28
+
29
+ private
30
+
31
+ def perform_transmission(transmission_proc)
32
+ WebMock.disable_net_connect!
33
+ WebMock::API.stub_request(:post, /.*/).to_rack(server)
34
+
35
+ transmission_proc.call
36
+
37
+ WebMock.allow_net_connect!
38
+ end
39
+
40
+ def server
41
+ expected_payload = self.expected_payload
42
+
43
+ @_server ||= ::Class.new(::WebTrap::Server) do
44
+ @payload_was_valid = false
45
+ @request_received = false
46
+
47
+ post "*" do
48
+ actual_payload = request.body.string
49
+
50
+ self.class.request_received = true
51
+ self.class.payload_was_valid = EquivalentXml.equivalent?(actual_payload, expected_payload)
52
+ end
53
+ end
54
+ end
55
+
56
+ def request_sent?
57
+ super || server.request_received?
58
+ end
59
+
60
+ def valid_payload?
61
+ server.payload_was_valid?
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ require "webtrap/rspec/matchers/send_request"
2
+ require "webtrap/rspec/matchers/send_request_with_xml"
3
+
4
+ module WebTrap
5
+ module RSpec
6
+ module Matchers
7
+ def send_request
8
+ SendRequest.new
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ RSpec.configure do |c|
15
+ c.include WebTrap::RSpec::Matchers
16
+ end
@@ -0,0 +1,3 @@
1
+ require "webtrap/server"
2
+
3
+ require "webtrap/rspec/matchers"
@@ -0,0 +1,24 @@
1
+ require "sinatra"
2
+
3
+ module WebTrap
4
+ class Server < Sinatra::Base
5
+ @payload_was_valid = false
6
+ @request_received = false
7
+
8
+ def self.payload_was_valid?
9
+ @payload_was_valid
10
+ end
11
+
12
+ def self.payload_was_valid=(payload_was_valid)
13
+ @payload_was_valid = payload_was_valid
14
+ end
15
+
16
+ def self.request_received?
17
+ @request_received
18
+ end
19
+
20
+ def self.request_received=(request_received)
21
+ @request_received = request_received
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module WebTrap
2
+ VERSION = "0.0.0"
3
+ end
data/webtrap.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "webtrap/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webtrap"
8
+ spec.version = WebTrap::VERSION
9
+ spec.authors = ["Pedro Costa"]
10
+ spec.email = ["pedro@subvisual.co"]
11
+
12
+ spec.summary = %(Test your outgoing requests.)
13
+ spec.description = <<-EOS
14
+ WebTrap allows you to write tests that assert on outgoing requests. This
15
+ allows you to verify that such requests match the documentation of external
16
+ services without actually having to hit them.
17
+ EOS
18
+ spec.homepage = "https://github.com/pfac/webtrap"
19
+ spec.license = "MIT"
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ else
26
+ raise <<-EOS
27
+ RubyGems 2.0 or newer is required to protect against public gem pushes.
28
+ EOS
29
+ end
30
+
31
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency "equivalent-xml", "~> 0.6.0"
39
+ spec.add_dependency "rspec", "~> 3.0"
40
+ spec.add_dependency "sinatra", "~> 1.0"
41
+ spec.add_dependency "webmock", "~> 2.0"
42
+
43
+ spec.add_development_dependency "bundler", "~> 1.13"
44
+ spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "cucumber", "~> 2.0"
46
+ end
47
+
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webtrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Costa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: equivalent-xml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ description: |2
112
+ WebTrap allows you to write tests that assert on outgoing requests. This
113
+ allows you to verify that such requests match the documentation of external
114
+ services without actually having to hit them.
115
+ email:
116
+ - pedro@subvisual.co
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".ruby-version"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - lib/webtrap/rspec.rb
127
+ - lib/webtrap/rspec/matchers.rb
128
+ - lib/webtrap/rspec/matchers/send_request.rb
129
+ - lib/webtrap/rspec/matchers/send_request_with_xml.rb
130
+ - lib/webtrap/server.rb
131
+ - lib/webtrap/version.rb
132
+ - webtrap.gemspec
133
+ homepage: https://github.com/pfac/webtrap
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.5.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Test your outgoing requests.
158
+ test_files: []