faraday_simulation 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +7 -6
- data/lib/faraday_simulation.rb +2 -0
- data/lib/faraday_simulation/stub.rb +1 -1
- data/lib/faraday_simulation/version.rb +1 -1
- data/test/unit/test_adapter.rb +9 -0
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# FaradaySimulation
|
2
2
|
|
3
|
-
A [Faraday]() extension to provide
|
4
|
-
|
5
|
-
your app is running in
|
3
|
+
A [Faraday](https://github.com/technoweenie/faraday) extension to provide
|
4
|
+
dynamic stubbing. This makes it much easier to simulate the behavior
|
5
|
+
of the target service in your tests and when your app is running in
|
6
|
+
development mode.
|
6
7
|
|
7
8
|
|
8
9
|
## Usage
|
9
10
|
|
10
11
|
The `FaradaySimulation::Adapter` class is the equivalent of Faraday's own
|
11
|
-
test adapter, but
|
12
|
+
test adapter, but the stubbing is more powerful:
|
12
13
|
|
13
14
|
conn = Faraday::Connection.new { |builder|
|
14
15
|
builder.use(FaradaySimulation::Adapter) { |stub|
|
@@ -29,8 +30,8 @@ any string, and that string will be the value of `env[:params]['foo']` in
|
|
29
30
|
your stub block.
|
30
31
|
|
31
32
|
For more complex routes, you can define the stub with a regular expression.
|
32
|
-
Any regex group
|
33
|
-
|
33
|
+
Any regex group in the matching regex will be placed in `env[:segments]`.
|
34
|
+
For example:
|
34
35
|
|
35
36
|
stub.get(/\/foo\/([A-Z]+)\//) { |env|
|
36
37
|
[200, {}, "Segment is #{env[:segments][0]}"]
|
data/lib/faraday_simulation.rb
CHANGED
@@ -36,7 +36,7 @@ class FaradaySimulation::Stub < Faraday::Adapter::Test::Stub
|
|
36
36
|
params_match?(request_params) &&
|
37
37
|
(body.to_s.size.zero? || request_body == body)
|
38
38
|
)
|
39
|
-
self.segments = md.to_a.slice(1, md.size)
|
39
|
+
self.segments = md.to_a.slice(1, md.size).collect { |s| CGI.unescape(s) }
|
40
40
|
true
|
41
41
|
else
|
42
42
|
false
|
data/test/unit/test_adapter.rb
CHANGED
@@ -56,6 +56,15 @@ class FaradaySimulation::TestAdapter < Test::Unit::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
|
59
|
+
def test_segment_params_escaped
|
60
|
+
@stubs.get(/\/endpoint\/([^\/]+)\//) { |env|
|
61
|
+
assert_equal('foo bar', env[:segments][0])
|
62
|
+
}
|
63
|
+
@conn.get('/endpoint/foo%20bar')
|
64
|
+
@conn.get('/endpoint/foo+bar')
|
65
|
+
end
|
66
|
+
|
67
|
+
|
59
68
|
def test_multiple_segment_params
|
60
69
|
@stubs.get(/\/endpoint\/([^\/]+)\/junk\/(.*)/) { |env|
|
61
70
|
assert_equal('slug', env[:segments][0])
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joseph Pearson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-07-
|
17
|
+
date: 2012-07-24 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|