interpol 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -178,6 +178,17 @@ Interpol.default_configuration do |config|
178
178
  #
179
179
  # Used by Interpol::DocumentationApp.
180
180
  config.documentation_title = "Acme Widget API Documentaton"
181
+
182
+ # Sets a callback that can be used to filter example data.
183
+ # This is useful when you want your stub app to serve data
184
+ # that is a bit dynamic. You can set multiple of these, and
185
+ # each will be called in declared order.
186
+ #
187
+ # Used by Interpol::StubApp, Interpol::TestHelper::RSpec and
188
+ # Interpol::TestHelper::TestUnit.
189
+ config.filter_example_data do |example, request_env|
190
+ example.data["current_url"] = Rack::Request.new(request_env).url
191
+ end
181
192
  end
182
193
 
183
194
  ```
@@ -52,7 +52,7 @@ module Interpol
52
52
  @definitions.fetch([message_type, version]) do
53
53
  message = "No definition found for #{name} endpoint for version #{version}"
54
54
  message << " and message_type #{message_type}"
55
- raise ArgumentError.new(message)
55
+ raise NoEndpointDefinitionFoundError.new(message)
56
56
  end
57
57
  end
58
58
 
@@ -252,7 +252,7 @@ module Interpol
252
252
  private
253
253
 
254
254
  def deep_dup
255
- dup.tap { |d| d.data = dup_hash(d.data) }
255
+ dup.tap { |d| d.data = dup_object(d.data) }
256
256
  end
257
257
 
258
258
  DUPPERS = { Hash => :dup_hash, Array => :dup_array }
@@ -20,7 +20,7 @@ module Interpol
20
20
 
21
21
  def example_for(endpoint, version, message_type)
22
22
  example = endpoint.find_example_for!(version, message_type)
23
- rescue ArgumentError
23
+ rescue NoEndpointDefinitionFoundError
24
24
  interpol_config.request_version_unavailable(self, version, endpoint.available_versions)
25
25
  else
26
26
  example.apply_filters(interpol_config.filter_example_data_blocks, request.env)
@@ -1,8 +1,22 @@
1
1
  require 'interpol'
2
+ require 'rack/mock'
2
3
 
3
4
  module Interpol
4
5
  module TestHelper
5
6
  module Common
7
+ def define_interpol_example_tests(&block)
8
+ config = Configuration.default.customized_duplicate(&block)
9
+
10
+ each_example_from(config.endpoints) do |endpoint, definition, example, example_index|
11
+ description = "#{endpoint.name} (v #{definition.version}) has " +
12
+ "valid data for example #{example_index + 1}"
13
+ example = filtered_example(config, endpoint, example)
14
+ define_test(description) { example.validate! }
15
+ end
16
+ end
17
+
18
+ private
19
+
6
20
  def each_example_from(endpoints)
7
21
  endpoints.each do |endpoint|
8
22
  endpoint.definitions.each do |definitions|
@@ -15,14 +29,10 @@ module Interpol
15
29
  end
16
30
  end
17
31
 
18
- def define_interpol_example_tests(&block)
19
- config = Configuration.default.customized_duplicate(&block)
20
-
21
- each_example_from(config.endpoints) do |endpoint, definition, example, example_index|
22
- description = "#{endpoint.name} (v #{definition.version}) has " +
23
- "valid data for example #{example_index + 1}"
24
- define_test(description) { example.validate! }
25
- end
32
+ def filtered_example(config, endpoint, example)
33
+ path = endpoint.route.gsub(':', '') # turn path params into static segments
34
+ rack_env = ::Rack::MockRequest.env_for(path)
35
+ example.apply_filters(config.filter_example_data_blocks, rack_env)
26
36
  end
27
37
  end
28
38
 
@@ -1,3 +1,3 @@
1
1
  module Interpol
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interpol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json-schema
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
218
  version: '0'
219
219
  segments:
220
220
  - 0
221
- hash: -810990702936122317
221
+ hash: 3468144605140067563
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  none: false
224
224
  requirements:
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  version: '0'
228
228
  segments:
229
229
  - 0
230
- hash: -810990702936122317
230
+ hash: 3468144605140067563
231
231
  requirements: []
232
232
  rubyforge_project:
233
233
  rubygems_version: 1.8.24