moonmaster9000-dupe 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dupe/active_resource.rb +1 -1
- data/lib/dupe/dupe.rb +1 -78
- metadata +2 -2
data/lib/dupe/active_resource.rb
CHANGED
@@ -53,7 +53,7 @@ module ActiveResource
|
|
53
53
|
end
|
54
54
|
puts "\n Request attempts logged for this scenario:\n --------------------------------------------\n\n"
|
55
55
|
@request_log.each do |request|
|
56
|
-
puts " Request: #{request[:method].upcase} #{request[:path]}"
|
56
|
+
puts " Request: #{request[:method].to_s.upcase} #{request[:path]}"
|
57
57
|
puts " Headers: #{request[:headers].inspect}"
|
58
58
|
puts " Response Body:\n#{request[:response].body.split("\n").map {|s| (" "*6) + s}.join("\n")}"
|
59
59
|
puts " Response Code: #{request[:response].code}"
|
data/lib/dupe/dupe.rb
CHANGED
@@ -1,80 +1,3 @@
|
|
1
|
-
# Dupe allows you to define resources, create a pool of resources,
|
2
|
-
# extend those resources with your own custom response mocks, and even override the default
|
3
|
-
# mocks Dupe provides (<em>find(:all)</em> and <em>find(id)</em>).
|
4
|
-
#
|
5
|
-
# Dupe is ideally suited for working with Cucumber[http://cukes.info]. It also relies on ActiveResource::HttpMock[http://api.rubyonrails.org/classes/ActiveResource/HttpMock.html] for mocking
|
6
|
-
# resource responses.
|
7
|
-
#
|
8
|
-
# Let's suppose your cuking a book search application for a library that consumes a RESTFUL book datastore service via ActiveResource.
|
9
|
-
# You might start by writing the following feature in <em>RAILS_ROOT/features/library/find_book.feature</em>:
|
10
|
-
#
|
11
|
-
# Feature: find a book
|
12
|
-
# As a reader
|
13
|
-
# I want to search for books
|
14
|
-
# so that I can check them out and read them.
|
15
|
-
#
|
16
|
-
# Scenario: search by author
|
17
|
-
# Given an author "Arthur C. Clarke"
|
18
|
-
# And a book "2001: A Space Odyssey" by "Arthur C. Clarke"
|
19
|
-
# When I search for "Arthur C. Clarke"
|
20
|
-
# I should see "2001: A Space Odyssey"
|
21
|
-
#
|
22
|
-
# To get this to pass, you might first create an ActiveResource[http://api.rubyonrails.org/classes/ActiveResource/Base.html] model for a Book and an Author that will connect
|
23
|
-
# to the RESTful book service:
|
24
|
-
#
|
25
|
-
# class Book < ActiveResource::Base
|
26
|
-
# self.site = 'http://bookservice.domain'
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# class Author < ActiveResource::Base
|
30
|
-
# self.site = 'http://bookservice.domain'
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# Then you might create the following resource definition via Dupe.define (put it in a file with a .rb extension and place it in RAILS_ROOT/features/support/):
|
34
|
-
#
|
35
|
-
# Dupe.define :book do |define|
|
36
|
-
# define.author do |author_name|
|
37
|
-
# Dupe.find(:author) {|a| a.name == author_name}
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# and the following cucumber step definitions (utilizing Dupe.create):
|
42
|
-
#
|
43
|
-
# Given /^an author "([^\"]*)"$/ do |author|
|
44
|
-
# Dupe.create :author, :name => author
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# Given /^a book "([^\"]*)" by "([^\"]*)"$/ do |book, author|
|
48
|
-
# Dupe.create :book, :title => book, :author => author
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# Dupe.create will in turn mock two service responses for each resource. For example,
|
52
|
-
# for the Book resource, it will mock:
|
53
|
-
#
|
54
|
-
# # Book.find(:all) --> GET /books.xml
|
55
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
56
|
-
# <books type="array">
|
57
|
-
# <book>
|
58
|
-
# <id type="integer">1</id>
|
59
|
-
# <title>2001: A Space Odyssey</title>
|
60
|
-
# <author>
|
61
|
-
# <id type="integer">1</id>
|
62
|
-
# <name>Arthur C. Clarke</name>
|
63
|
-
# </author>
|
64
|
-
# </book>
|
65
|
-
# </books>
|
66
|
-
#
|
67
|
-
# # Book.find(1) --> GET /books/1.xml
|
68
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
69
|
-
# <book>
|
70
|
-
# <id type="integer">1</id>
|
71
|
-
# <title>2001: A Space Odyssey</title>
|
72
|
-
# <author>
|
73
|
-
# <id type="integer">1</id>
|
74
|
-
# <name>Arthur C. Clarke</name>
|
75
|
-
# </author>
|
76
|
-
# </book>
|
77
|
-
|
78
1
|
# Author:: Matt Parker (mailto:moonmaster9000@gmail.com)
|
79
2
|
# License:: Distributes under the same terms as Ruby
|
80
3
|
|
@@ -429,7 +352,7 @@ class Dupe
|
|
429
352
|
def find(*args, &block) # yield: record
|
430
353
|
all_or_first, factory_name = args[-2], args[-1]
|
431
354
|
match = block ? block : proc {true}
|
432
|
-
all_or_first = ((factory_name.to_s.
|
355
|
+
all_or_first = ((factory_name.to_s.plural?) ? :all : :first) unless all_or_first
|
433
356
|
factory_name = factory_name.to_s.singularize.to_sym
|
434
357
|
verify_factory_exists factory_name
|
435
358
|
result = factories[factory_name].find_records_like match
|
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.2.
|
4
|
+
version: 0.2.3
|
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-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|