mock_server 0.4.0 → 0.4.1
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.
- data/lib/mock_server/playback.rb +25 -19
- metadata +2 -2
data/lib/mock_server/playback.rb
CHANGED
@@ -55,14 +55,9 @@ module MockServer
|
|
55
55
|
request = Hashie::Mash.new hashified_request
|
56
56
|
|
57
57
|
# Filter out data records by path and method
|
58
|
-
|
59
|
-
record[:request][:path] == request[:path] and record[:request][:method] == request[:method]
|
60
|
-
}
|
58
|
+
data = filter_records(request)
|
61
59
|
|
62
|
-
|
63
|
-
matchers = @options[:matchers].select { |match|
|
64
|
-
request[:method].to_s.upcase == match[:method].to_s.upcase and request[:path] == match[:path]
|
65
|
-
}
|
60
|
+
matchers = filter_matchers(request)
|
66
61
|
|
67
62
|
data = false
|
68
63
|
matchers.detect { |matcher|
|
@@ -74,23 +69,34 @@ module MockServer
|
|
74
69
|
recorded_response[:body] = JSON.parse(recorded_response[:body]) rescue recorded_response[:body]
|
75
70
|
recorded_response = Hashie::Mash.new recorded_response
|
76
71
|
|
77
|
-
|
78
|
-
begin
|
79
|
-
result = matcher[:matcher].call(request, recorded_request, recorded_response)
|
80
|
-
rescue => matcher_err
|
81
|
-
store_matcher_exception(matcher_err)
|
82
|
-
result = false
|
83
|
-
end
|
84
|
-
result
|
85
|
-
else
|
86
|
-
true
|
87
|
-
end
|
88
|
-
result == true
|
72
|
+
test_request_and_matcher(matcher, request, recorded_request, recorded_response)
|
89
73
|
}
|
90
74
|
}
|
91
75
|
data
|
92
76
|
end
|
93
77
|
|
78
|
+
def filter_matchers(request)
|
79
|
+
@options[:matchers].select { |match|
|
80
|
+
request[:method].to_s.upcase == match[:method].to_s.upcase and request[:path] == match[:path]
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def filter_records(request)
|
85
|
+
@data.select { |record|
|
86
|
+
record[:request][:path] == request[:path] and record[:request][:method] == request[:method]
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_request_and_matcher(matcher, request, recorded_request, recorded_response)
|
91
|
+
return true if matcher[:matcher].nil?
|
92
|
+
begin
|
93
|
+
matcher[:matcher].call(request, recorded_request, recorded_response) == true
|
94
|
+
rescue => matcher_err
|
95
|
+
store_matcher_exception(matcher_err)
|
96
|
+
false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
94
100
|
def store_matcher_exception(exception)
|
95
101
|
@options[:matcher_exceptions] << exception
|
96
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-08-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|