yafs 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbac96c9dc78bca768d564def895eff6f31fdf0
4
- data.tar.gz: a06fce9becf8697cad8d9141e79fdaa077e3c248
3
+ metadata.gz: 9fbee2989f0f9f1ea770e5ff1b352373caf72f2e
4
+ data.tar.gz: 3fb3a22d5ff95b6afd49a4169b6dcbbe4294b37e
5
5
  SHA512:
6
- metadata.gz: cab486448f9f7a603e5f78c562d99cdd94f1d7f6ec1abb9933b43b2f1431afe1d5627d4138eb3ff972d551418cf315ed167405a34f9a71f43125ce0aff2ebf11
7
- data.tar.gz: 3e71463bb73c5724a54bc9c87c075d80732657521ce19f39298a701395b80e97b689e3f607088284f3754629f3d09038aeae2da6ce6a27080140bcb65f8d3a11
6
+ metadata.gz: 559a21fd429505365299fc7c8360b99314469fb2ff64996832ad3044a902a481a7bc6f0d89a14408d175920748f57a3f77ff6cd40f6cc2207d305e0248af7108
7
+ data.tar.gz: fba1d3c614c4431e8223bda47004173ce4eae9b99dbbc60b816390a917bc910c389d8a7510c12a47d8ca23ab6bd211b57fe0d0af68d6e6768badabc69b482038
@@ -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
@@ -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 request.path.eql?(@path) && request.request_method.eql?(@method.to_s.upcase)
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()
@@ -7,6 +7,7 @@ require_relative './fake/requests.rb'
7
7
  require_relative './fake/request.rb'
8
8
  require_relative './fake/fake.rb'
9
9
  require_relative './fake/response.rb'
10
+ require_relative './fake/path.rb'
10
11
 
11
12
  Thread.abort_on_exception = true
12
13
 
@@ -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
- xit "routes request to match path variables" do
82
- fs.get('/cart/:id/status').response(body:"ok")
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.5
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-06 00:00:00.000000000 Z
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