moonmaster9000-dupe 0.1.2 → 0.2.0
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/README.rdoc +1 -1
- data/lib/dupe/active_resource.rb +80 -0
- data/lib/dupe/cucumber_hooks.rb +5 -0
- data/lib/dupe/dupe.rb +24 -3
- metadata +4 -3
data/README.rdoc
CHANGED
|
@@ -81,4 +81,4 @@ From here, you could start scaffolding your controllers, with the assumption tha
|
|
|
81
81
|
|
|
82
82
|
== More
|
|
83
83
|
|
|
84
|
-
Dupe supports attribute defaults, attribute
|
|
84
|
+
Dupe supports attribute defaults, attribute transformations, stubbing, resource associations, custom resource mocks, and more. Want to learn more? Consult the API documentation at http://moonmaster9000.github.com/dupe/api/
|
data/lib/dupe/active_resource.rb
CHANGED
|
@@ -25,3 +25,83 @@ module ActiveResource #:nodoc:
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
module ActiveResource
|
|
29
|
+
class Connection #:nodoc:
|
|
30
|
+
|
|
31
|
+
class << self
|
|
32
|
+
attr_reader :request_log
|
|
33
|
+
|
|
34
|
+
def log_request(method, path, headers, response)
|
|
35
|
+
@request_log ||= []
|
|
36
|
+
@request_log << {
|
|
37
|
+
:method => method,
|
|
38
|
+
:path => path,
|
|
39
|
+
:headers => headers,
|
|
40
|
+
:response => response
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def flush_request_log
|
|
45
|
+
@request_log = []
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def print_request_log
|
|
49
|
+
@request_log ||= []
|
|
50
|
+
if @request_log.empty?
|
|
51
|
+
puts(" -----No request attempts logged for this scenario")
|
|
52
|
+
return
|
|
53
|
+
end
|
|
54
|
+
puts " Request attempts logged for this scenario:\n --------------------------------------------\n\n"
|
|
55
|
+
@request_log.each do |request|
|
|
56
|
+
puts " Request: #{request[:method].upcase} #{request[:path]}"
|
|
57
|
+
puts " Headers: #{request[:headers].inspect}"
|
|
58
|
+
puts " Response Body:\n#{request[:response].body.split("\n").map {|s| (" "*6) + s}.join("\n")}"
|
|
59
|
+
puts " Response Code: #{request[:response].code}"
|
|
60
|
+
puts " Response Headers: #{request[:response].headers}"
|
|
61
|
+
puts " Response Message: #{request[:response].message}"
|
|
62
|
+
puts "\n\n"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Execute a GET request.
|
|
68
|
+
# Used to get (find) resources.
|
|
69
|
+
def get(path, headers = {})
|
|
70
|
+
response = request(:get, path, build_request_headers(headers, :get))
|
|
71
|
+
ActiveResource::Connection.log_request(:get, path, headers, response)
|
|
72
|
+
format.decode(response.body)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
|
|
76
|
+
# Used to delete resources.
|
|
77
|
+
def delete(path, headers = {})
|
|
78
|
+
response = request(:delete, path, build_request_headers(headers, :delete))
|
|
79
|
+
ActiveResource::Connection.log_request(:delete, path, headers, response)
|
|
80
|
+
response
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Execute a PUT request (see HTTP protocol documentation if unfamiliar).
|
|
84
|
+
# Used to update resources.
|
|
85
|
+
def put(path, body = '', headers = {})
|
|
86
|
+
response = request(:put, path, body.to_s, build_request_headers(headers, :put))
|
|
87
|
+
ActiveResource::Connection.log_request(:put, path, headers, response)
|
|
88
|
+
response
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Execute a POST request.
|
|
92
|
+
# Used to create new resources.
|
|
93
|
+
def post(path, body = '', headers = {})
|
|
94
|
+
response = request(:post, path, body.to_s, build_request_headers(headers, :post))
|
|
95
|
+
ActiveResource::Connection.log_request(:post, path, headers, response)
|
|
96
|
+
response
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Execute a HEAD request.
|
|
100
|
+
# Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
|
|
101
|
+
def head(path, headers = {})
|
|
102
|
+
response = request(:head, path, build_request_headers(headers))
|
|
103
|
+
ActiveResource::Connection.log_request(:head, path, headers, response)
|
|
104
|
+
response
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/lib/dupe/cucumber_hooks.rb
CHANGED
data/lib/dupe/dupe.rb
CHANGED
|
@@ -87,7 +87,8 @@ class Dupe
|
|
|
87
87
|
attr_reader :records #:nodoc:
|
|
88
88
|
|
|
89
89
|
class << self
|
|
90
|
-
attr_accessor :factories
|
|
90
|
+
attr_accessor :factories #:nodoc:
|
|
91
|
+
attr_accessor :global_configuration #:nodoc:
|
|
91
92
|
|
|
92
93
|
# Create data definitions for your resources. This allows you to setup default values for columns
|
|
93
94
|
# and even provide data transformations.
|
|
@@ -287,7 +288,22 @@ class Dupe
|
|
|
287
288
|
@factories[factory].stub_services_with(options[:template], options[:count].to_i, (options[:sequence_start_value] || 1), options[:sequence])
|
|
288
289
|
end
|
|
289
290
|
|
|
290
|
-
#
|
|
291
|
+
# === Global Configuration
|
|
292
|
+
#
|
|
293
|
+
# On a global level, configure supports the following options (expect this list to grow as the app grows):
|
|
294
|
+
# debug: list the attempted requests and mocked responses that happened during the course of a scenario
|
|
295
|
+
#
|
|
296
|
+
# To turn on debugging, simply do:
|
|
297
|
+
# Dupe.configure do |global_config|
|
|
298
|
+
# global_config.debug true
|
|
299
|
+
# end
|
|
300
|
+
#
|
|
301
|
+
# === Factory Configuration
|
|
302
|
+
#
|
|
303
|
+
# On a factory level, configure support the following options (expect this list to grow as the app grows):
|
|
304
|
+
# record_identifiers: a list of attributes that are unique to each record in that resource factory.
|
|
305
|
+
#
|
|
306
|
+
# The "record_identifiers" configuration option allows you to override the array record identifiers for your resources ([:id], by default)
|
|
291
307
|
#
|
|
292
308
|
# For example, suppose the RESTful application your trying to consume supports lookups by both a textual 'label'
|
|
293
309
|
# and a numeric 'id', and that it contains an author service where the author with id '1' has the label 'arthur-c-clarke'.
|
|
@@ -319,7 +335,8 @@ class Dupe
|
|
|
319
335
|
# <name>Arthur C. Clarke</name>
|
|
320
336
|
# <label>arthur-c-clarke</label>
|
|
321
337
|
# </author>
|
|
322
|
-
def configure(factory) # yield: configure
|
|
338
|
+
def configure(factory=nil) # yield: configure
|
|
339
|
+
yield global_configuration and return unless factory
|
|
323
340
|
setup_factory(factory)
|
|
324
341
|
yield @factories[factory].config
|
|
325
342
|
end
|
|
@@ -436,6 +453,10 @@ class Dupe
|
|
|
436
453
|
@factories ||= {}
|
|
437
454
|
end
|
|
438
455
|
|
|
456
|
+
def global_configuration #:nodoc:
|
|
457
|
+
@global_configuration ||= Configuration.new
|
|
458
|
+
end
|
|
459
|
+
|
|
439
460
|
private
|
|
440
461
|
|
|
441
462
|
def setup_factory(factory)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moonmaster9000-dupe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Parker
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-15 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -53,6 +53,7 @@ files:
|
|
|
53
53
|
- lib/dupe/sequence.rb
|
|
54
54
|
has_rdoc: false
|
|
55
55
|
homepage: http://github.com/moonmaster9000/dupe
|
|
56
|
+
licenses:
|
|
56
57
|
post_install_message:
|
|
57
58
|
rdoc_options:
|
|
58
59
|
- --charset=UTF-8
|
|
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
74
|
requirements: []
|
|
74
75
|
|
|
75
76
|
rubyforge_project:
|
|
76
|
-
rubygems_version: 1.
|
|
77
|
+
rubygems_version: 1.3.5
|
|
77
78
|
signing_key:
|
|
78
79
|
specification_version: 3
|
|
79
80
|
summary: A tool that helps you mock services while cuking.
|