yafs 0.0.5 → 0.0.6
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 +4 -4
- data/lib/fake/path.rb +52 -0
- data/lib/fake/request_handler.rb +2 -2
- data/lib/fake_service.rb +1 -0
- data/spec/fake/path_spec.rb +47 -0
- data/spec/fake/request_handler_spec.rb +8 -0
- data/spec/features/fake_service_spec.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fbee2989f0f9f1ea770e5ff1b352373caf72f2e
|
4
|
+
data.tar.gz: 3fb3a22d5ff95b6afd49a4169b6dcbbe4294b37e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559a21fd429505365299fc7c8360b99314469fb2ff64996832ad3044a902a481a7bc6f0d89a14408d175920748f57a3f77ff6cd40f6cc2207d305e0248af7108
|
7
|
+
data.tar.gz: fba1d3c614c4431e8223bda47004173ce4eae9b99dbbc60b816390a917bc910c389d8a7510c12a47d8ca23ab6bd211b57fe0d0af68d6e6768badabc69b482038
|
data/lib/fake/path.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Fake
|
2
|
+
class Path
|
3
|
+
|
4
|
+
attr_reader :path
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def eql?(path_str)
|
11
|
+
if dynamic?
|
12
|
+
dynamic_paths_eql?(path_str)
|
13
|
+
else
|
14
|
+
path == path_str
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def dynamic_paths_eql?(path_str)
|
21
|
+
parts = path.split('/')
|
22
|
+
other_parts = path_str.split('/')
|
23
|
+
return false if parts.length != other_parts.length
|
24
|
+
|
25
|
+
regexp_parts = convert_to_regexp(parts)
|
26
|
+
|
27
|
+
regexp_parts.each_with_index do |regexp, index|
|
28
|
+
return false unless regexp.match(other_parts[index])
|
29
|
+
end
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
def dynamic?
|
34
|
+
path.include?(':')
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert_to_regexp(parts)
|
38
|
+
parts.map do |part|
|
39
|
+
if dynamic_path_part?(':')
|
40
|
+
Regexp.new('.*')
|
41
|
+
else
|
42
|
+
Regexp.new('^#{part}$')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def dynamic_path_part?(part)
|
48
|
+
part.start_with?(':')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/fake/request_handler.rb
CHANGED
@@ -8,12 +8,12 @@ module Fake
|
|
8
8
|
# path: Path of the request like '/home/something'
|
9
9
|
def initialize(method, path)
|
10
10
|
@method = method
|
11
|
-
@path = path
|
11
|
+
@path = Path.new(path)
|
12
12
|
@responses = InfiniteQueue.new
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(request)
|
16
|
-
if
|
16
|
+
if @path.eql?(request.path) && request.request_method.eql?(@method.to_s.upcase)
|
17
17
|
current_response = @responses.next
|
18
18
|
raise "FAKE service: No response set for request #{presentation}" if current_response.nil?
|
19
19
|
current_response.evaluate()
|
data/lib/fake_service.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe Fake::Path do
|
5
|
+
|
6
|
+
describe "#eql?" do
|
7
|
+
context "when path is static" do
|
8
|
+
context "and paths are equals" do
|
9
|
+
|
10
|
+
it "returns true" do
|
11
|
+
expect(Fake::Path.new("/path").eql?("/path")).to eq true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "and paths are not equal" do
|
16
|
+
it "returns false" do
|
17
|
+
expect(Fake::Path.new("/something").eql?("/path")).to eq false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when path is dynamic" do
|
23
|
+
context "and paths are equals" do
|
24
|
+
it "returns true" do
|
25
|
+
expect(Fake::Path.new("/:id/path/:id2/value").eql?("/value/path/some/value")).to eq true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and different amount of path parts" do
|
30
|
+
it "returns false" do
|
31
|
+
expect(Fake::Path.new("/:id/path").eql?("/value/something/path")).to eq false
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns false" do
|
35
|
+
expect(Fake::Path.new("/:id/path/:id2/some").eql?("/value")).to eq false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "and paths are not equals" do
|
40
|
+
it "returns false" do
|
41
|
+
expect(Fake::Path.new("/:id/someghing/:id2/path").eql?("/value/something/path")).to eq false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -9,6 +9,14 @@ describe Fake::RequestHandler do
|
|
9
9
|
rh.responses << Fake::Response.new("", "200 OK", {})
|
10
10
|
expect(rh.call(get_request('http://localhost/home'))).not_to eq nil
|
11
11
|
end
|
12
|
+
|
13
|
+
context "when dynamic path used" do
|
14
|
+
it "returns response" do
|
15
|
+
rh = Fake::RequestHandler.new(:get, '/home/:id/new')
|
16
|
+
rh.responses << Fake::Response.new("", "200 OK", {})
|
17
|
+
expect(rh.call(get_request('http://localhost/home/5/new'))).not_to eq nil
|
18
|
+
end
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
14
22
|
context "when operation does not match with request handler operation" do
|
@@ -78,8 +78,8 @@ describe 'Fake Service' do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "dynamic paths" do
|
81
|
-
|
82
|
-
fs.get('/cart/:id/status').
|
81
|
+
it "routes request to match path variables" do
|
82
|
+
fs.get('/cart/:id/status').respond(body:"ok")
|
83
83
|
fs.start
|
84
84
|
expect(HTTParty.get('http://localhost:4567/cart/path/status').response.body).to eq "ok"
|
85
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yafs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mika Lackman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -32,12 +32,14 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- README.md
|
34
34
|
- lib/fake/fake.rb
|
35
|
+
- lib/fake/path.rb
|
35
36
|
- lib/fake/request.rb
|
36
37
|
- lib/fake/request_handler.rb
|
37
38
|
- lib/fake/requests.rb
|
38
39
|
- lib/fake/response.rb
|
39
40
|
- lib/fake/service.rb
|
40
41
|
- lib/fake_service.rb
|
42
|
+
- spec/fake/path_spec.rb
|
41
43
|
- spec/fake/request_handler_spec.rb
|
42
44
|
- spec/fake/response_spec.rb
|
43
45
|
- spec/features/fake_service_spec.rb
|
@@ -68,6 +70,7 @@ signing_key:
|
|
68
70
|
specification_version: 4
|
69
71
|
summary: Yet another fake http service for e2e tests
|
70
72
|
test_files:
|
73
|
+
- spec/fake/path_spec.rb
|
71
74
|
- spec/fake/request_handler_spec.rb
|
72
75
|
- spec/fake/response_spec.rb
|
73
76
|
- spec/features/fake_service_spec.rb
|