yafs 0.0.2 → 0.0.3
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/request.rb +14 -0
- data/lib/fake/requests.rb +27 -0
- data/lib/fake_service.rb +4 -28
- data/spec/features/fake_service_spec.rb +37 -0
- 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: a4b12f8d927b65c8d4ebaaca97000c2634981ebd
|
4
|
+
data.tar.gz: 0d3b33afc2c86a9836f6c2a7fed056cf6b177627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a1e3d09db2a1505d0644f3879aa2dbe06a5f47afe56b971ac139d1a3ca78d705f360e80d213ce22c50607c748e3f3d4803058702ae5b3c9e39348189369563c
|
7
|
+
data.tar.gz: b14f0b4923ebf217ee75cb8e46f1017b155df21a0dc7159110dd5cb49858d4ef99d80a867c339a25796139531a9acf2880aa2c4049e6789b99a1ac3b9cbd779d
|
data/lib/fake/request.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fake
|
2
|
+
class Requests
|
3
|
+
attr_accessor :requests
|
4
|
+
include Singleton
|
5
|
+
class << self
|
6
|
+
def request(method, path)
|
7
|
+
matching_request = nil
|
8
|
+
instance.requests.each do |request|
|
9
|
+
if request.request_method == method.to_s.upcase &&
|
10
|
+
request.path == path
|
11
|
+
matching_request = request
|
12
|
+
end
|
13
|
+
end
|
14
|
+
matching_request
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_request(request)
|
18
|
+
instance.requests << request
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private
|
22
|
+
def initialize
|
23
|
+
@requests = []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/fake_service.rb
CHANGED
@@ -3,6 +3,8 @@ require 'singleton'
|
|
3
3
|
require 'WEBrick'
|
4
4
|
require_relative './fake/service.rb'
|
5
5
|
require_relative './fake/request_handler.rb'
|
6
|
+
require_relative './fake/requests.rb'
|
7
|
+
require_relative './fake/request.rb'
|
6
8
|
require_relative './fake/fake.rb'
|
7
9
|
|
8
10
|
Thread.abort_on_exception = true
|
@@ -62,7 +64,8 @@ module Fake
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def call(env)
|
65
|
-
request =
|
67
|
+
request = Fake::Request.new(env)
|
68
|
+
|
66
69
|
# TODO: Make this part of rack stack
|
67
70
|
Requests.add_request(request)
|
68
71
|
|
@@ -99,32 +102,5 @@ module Fake
|
|
99
102
|
end
|
100
103
|
end
|
101
104
|
end
|
102
|
-
class Requests
|
103
|
-
|
104
|
-
attr_accessor :requests
|
105
|
-
include Singleton
|
106
|
-
class << self
|
107
|
-
def request(method, path)
|
108
|
-
matching_request = nil
|
109
|
-
instance.requests.each do |request|
|
110
|
-
if request.request_method == method.to_s.upcase &&
|
111
|
-
request.path == path
|
112
|
-
matching_request = request
|
113
|
-
end
|
114
|
-
end
|
115
|
-
matching_request
|
116
|
-
end
|
117
|
-
|
118
|
-
def add_request(request)
|
119
|
-
instance.requests << request
|
120
|
-
end
|
121
|
-
end
|
122
|
-
private
|
123
|
-
def initialize
|
124
|
-
@requests = []
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
105
|
end
|
130
106
|
|
@@ -91,6 +91,43 @@ describe 'Fake Service' do
|
|
91
91
|
HTTParty.get('http://localhost:4567/cart?id=5&status=pending')
|
92
92
|
expect(Fake::Requests.request(:my_cart_request)).not_to be nil
|
93
93
|
end
|
94
|
+
|
95
|
+
context "from post request" do
|
96
|
+
before do
|
97
|
+
Fake.start(port:4567)
|
98
|
+
Fake.post('/').respond(status:400)
|
99
|
+
end
|
100
|
+
after do
|
101
|
+
Fake.stop
|
102
|
+
end
|
103
|
+
context "when content-type is 'application/json'" do
|
104
|
+
before do
|
105
|
+
HTTParty.post('http://localhost:4567/', body:{"data" => {"some"=>"1", "thing"=>"0"}}.to_json,
|
106
|
+
headers: {"Content-Type"=>"application/json"})
|
107
|
+
end
|
108
|
+
it "sets the parsed json to params" do
|
109
|
+
request = Fake::Requests.request(:post, '/')
|
110
|
+
expect(request.params['data']['some']).to eq '1'
|
111
|
+
expect(request.params['data']['thing']).to eq '0'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "the json is available for subsequent requests" do
|
115
|
+
request = Fake::Requests.request(:post, '/')
|
116
|
+
expect(request.params['data']['some']).to eq '1'
|
117
|
+
expect(request.params['data']['thing']).to eq '0'
|
118
|
+
request = Fake::Requests.request(:post, '/')
|
119
|
+
expect(request.params['data']['some']).to eq '1'
|
120
|
+
expect(request.params['data']['thing']).to eq '0'
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when post body not received" do
|
124
|
+
xit "raises error or what?" do
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
94
131
|
end
|
95
132
|
|
96
133
|
describe "ordering" do
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mika Lackman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -32,7 +32,9 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- README.md
|
34
34
|
- lib/fake/fake.rb
|
35
|
+
- lib/fake/request.rb
|
35
36
|
- lib/fake/request_handler.rb
|
37
|
+
- lib/fake/requests.rb
|
36
38
|
- lib/fake/service.rb
|
37
39
|
- lib/fake_service.rb
|
38
40
|
- spec/fake/request_handler_spec.rb
|
@@ -68,3 +70,4 @@ test_files:
|
|
68
70
|
- spec/features/fake_service_spec.rb
|
69
71
|
- spec/helpers.rb
|
70
72
|
- spec/spec_helper.rb
|
73
|
+
has_rdoc:
|