dupe 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +390 -147
- data/lib/dupe/active_resource_extensions.rb +25 -0
- data/lib/dupe/attribute_template.rb +71 -0
- data/lib/dupe/cucumber_hooks.rb +15 -7
- data/lib/dupe/custom_mocks.rb +102 -0
- data/lib/dupe/database.rb +51 -0
- data/lib/dupe/dupe.rb +359 -372
- data/lib/dupe/log.rb +38 -0
- data/lib/dupe/mock.rb +50 -0
- data/lib/dupe/model.rb +55 -0
- data/lib/dupe/network.rb +38 -0
- data/lib/dupe/record.rb +35 -56
- data/lib/dupe/rest_validation.rb +16 -0
- data/lib/dupe/schema.rb +36 -0
- data/lib/dupe/sequence.rb +11 -10
- data/lib/dupe/singular_plural_detection.rb +9 -0
- data/lib/dupe/string.rb +6 -8
- data/lib/dupe/symbol.rb +3 -0
- data/lib/dupe.rb +13 -12
- data/rails_generators/dupe/templates/custom_mocks.rb +4 -34
- data/rails_generators/dupe/templates/dupe_setup.rb +3 -23
- data/spec/lib_specs/active_resource_extensions_spec.rb +29 -0
- data/spec/lib_specs/attribute_template_spec.rb +173 -0
- data/spec/lib_specs/database_spec.rb +133 -0
- data/spec/lib_specs/dupe_spec.rb +307 -0
- data/spec/lib_specs/log_spec.rb +78 -0
- data/spec/lib_specs/logged_request_spec.rb +22 -0
- data/spec/lib_specs/mock_definitions_spec.rb +32 -0
- data/spec/lib_specs/mock_spec.rb +67 -0
- data/spec/lib_specs/model_spec.rb +90 -0
- data/spec/lib_specs/network_spec.rb +77 -0
- data/spec/lib_specs/record_spec.rb +70 -0
- data/spec/lib_specs/rest_validation_spec.rb +17 -0
- data/spec/lib_specs/schema_spec.rb +90 -0
- data/spec/lib_specs/sequence_spec.rb +26 -0
- data/spec/lib_specs/string_spec.rb +31 -0
- data/spec/lib_specs/symbol_spec.rb +17 -0
- data/spec/spec_helper.rb +2 -5
- metadata +29 -7
- data/lib/dupe/active_resource.rb +0 -135
- data/lib/dupe/attribute.rb +0 -17
- data/lib/dupe/configuration.rb +0 -20
- data/lib/dupe/mock_service_response.rb +0 -55
- data/spec/lib_specs/dupe_record_spec.rb +0 -57
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Network::Log::Request do
|
4
|
+
describe "##new" do
|
5
|
+
it "should set the verb, url, and response_body" do
|
6
|
+
r = Dupe::Network::Log::Request.new :get, "/knock-knock", "who's there?"
|
7
|
+
r.verb.should == :get
|
8
|
+
r.path.should == "/knock-knock"
|
9
|
+
r.response_body.should == "who's there?"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#pretty_print" do
|
14
|
+
it "should show the request type, request path, and request response" do
|
15
|
+
r = Dupe::Network::Log::Request.new :get, "/knock-knock", "who's there?"
|
16
|
+
r.pretty_print.should ==
|
17
|
+
"Request: GET /knock-knock\n" +
|
18
|
+
"Response:\n" +
|
19
|
+
" who's there?"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Mock Definition Methods" do
|
4
|
+
before do
|
5
|
+
Dupe.reset
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Get" do
|
9
|
+
it "should require a url pattern that is a regex" do
|
10
|
+
proc { Get() }.should raise_error(ArgumentError)
|
11
|
+
proc { Get 'not a regexp' }.should raise_error(ArgumentError)
|
12
|
+
proc { Get %r{/some_url} }.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create and return a Dupe::Network::Mock of type :get" do
|
16
|
+
Dupe.network.mocks[:get].should be_empty
|
17
|
+
@book = Dupe.create :book, :label => 'rooby'
|
18
|
+
Dupe.network.mocks[:get].should_not be_empty
|
19
|
+
Dupe.network.mocks[:get].length.should == 2
|
20
|
+
|
21
|
+
mock = Get %r{/books/([^&]+)\.xml} do |label|
|
22
|
+
Dupe.find(:book) {|b| b.label == label}
|
23
|
+
end
|
24
|
+
|
25
|
+
Dupe.network.mocks[:get].length.should == 3
|
26
|
+
Dupe.network.mocks[:get].last.should == mock
|
27
|
+
Dupe.network.mocks[:get].last.url_pattern.should == %r{/books/([^&]+)\.xml}
|
28
|
+
book = Dupe.find(:book)
|
29
|
+
Dupe.network.request(:get, '/books/rooby.xml').should == book.to_xml(:root => 'book')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Network::Mock do
|
4
|
+
before do
|
5
|
+
Dupe.reset
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "new" do
|
9
|
+
it "should require a valid REST type" do
|
10
|
+
proc { Dupe::Network::Mock.new :unknown, /\//, proc {} }.should raise_error(Dupe::Network::UnknownRestVerbError)
|
11
|
+
proc { Dupe::Network::Mock.new :get, /\//, proc {} }.should_not raise_error
|
12
|
+
proc { Dupe::Network::Mock.new :post, /\//, proc {} }.should_not raise_error
|
13
|
+
proc { Dupe::Network::Mock.new :put, /\//, proc {} }.should_not raise_error
|
14
|
+
proc { Dupe::Network::Mock.new :delete, /\//, proc {} }.should_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should require the url be a kind of regular expression" do
|
18
|
+
proc { Dupe::Network::Mock.new :get, '', proc {} }.should raise_error(
|
19
|
+
ArgumentError,
|
20
|
+
"The URL pattern parameter must be a type of regular expression."
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the @verb, @url, and @response parameters accordingly" do
|
25
|
+
url_pattern = /\//
|
26
|
+
response = proc {}
|
27
|
+
mock = Dupe::Network::Mock.new :get, url_pattern, response
|
28
|
+
mock.verb.should == :get
|
29
|
+
mock.url_pattern.should == url_pattern
|
30
|
+
mock.response.should == response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "match?" do
|
35
|
+
it "should determine if a given string matches the mock's url pattern" do
|
36
|
+
url = %r{/blogs/(\d+).xml}
|
37
|
+
response = proc {}
|
38
|
+
mock = Dupe::Network::Mock.new :get, url, response
|
39
|
+
mock.match?('/blogs/1.xml').should == true
|
40
|
+
mock.match?('/bogs/1.xml').should == false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "mocked_response" do
|
45
|
+
describe "on a mock object whose response returns a Dupe.find" do
|
46
|
+
it "should convert the response result to xml" do
|
47
|
+
url_pattern = %r{/books/(\d+)\.xml}
|
48
|
+
response = proc {|id| Dupe.find(:book) {|b| b.id == id.to_i}}
|
49
|
+
book = Dupe.create :book
|
50
|
+
mock = Dupe::Network::Mock.new :get, url_pattern, response
|
51
|
+
mock.mocked_response('/books/1.xml').should == book.to_xml(:root => 'book')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should add a request to the Dupe::Network#log" do
|
55
|
+
url_pattern = %r{/books/([a-zA-Z0-9-]+)\.xml}
|
56
|
+
response = proc {|label| Dupe.find(:book) {|b| b.label == label}}
|
57
|
+
book = Dupe.create :book, :label => 'rooby'
|
58
|
+
mock = Dupe::Network::Mock.new :get, url_pattern, response
|
59
|
+
Dupe.network.log.requests.length.should == 0
|
60
|
+
mock.mocked_response('/books/rooby.xml')
|
61
|
+
Dupe.network.log.requests.length.should == 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Model do
|
4
|
+
describe "new" do
|
5
|
+
it "should require a model name" do
|
6
|
+
proc { Dupe::Model.new }.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set the model name to what was passed in during initialization" do
|
10
|
+
m = Dupe::Model.new :book
|
11
|
+
m.name.should == :book
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should initialize an empty schema" do
|
15
|
+
m = Dupe::Model.new :book
|
16
|
+
m.schema.should be_kind_of(Dupe::Model::Schema)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should setup an id_sequence initialized to 0" do
|
20
|
+
m = Dupe::Model.new :book
|
21
|
+
m.id_sequence.current_value.should == 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "define" do
|
26
|
+
describe "when passed a proc" do
|
27
|
+
before do
|
28
|
+
@model = Dupe::Model.new :book
|
29
|
+
@definition = proc { |attrs|
|
30
|
+
attrs.author('Anonymous') do |dont_care|
|
31
|
+
'Flying Spaghetti Monster'
|
32
|
+
end
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should pass that proc off to it's schema" do
|
37
|
+
@model.schema.should_receive(:method_missing).once
|
38
|
+
@model.define @definition
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should result in a schema with the desired attribute templates" do
|
42
|
+
@model.define @definition
|
43
|
+
@model.schema.attribute_templates[:author].name.should == :author
|
44
|
+
@model.schema.attribute_templates[:author].default.should == 'Anonymous'
|
45
|
+
@model.schema.attribute_templates[:author].transformer.call(
|
46
|
+
'dont care'
|
47
|
+
).should == 'Flying Spaghetti Monster'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "create" do
|
53
|
+
before do
|
54
|
+
Dupe.define :book do |attrs|
|
55
|
+
attrs.title 'Untitled'
|
56
|
+
attrs.author 'Anon' do |author|
|
57
|
+
"Author: #{author}"
|
58
|
+
end
|
59
|
+
attrs.after_create do |book|
|
60
|
+
book.label = book.title.downcase.gsub(/\ +/, '-')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
@book_model = Dupe.models[:book]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "shouldn't require any parameters" do
|
68
|
+
proc {
|
69
|
+
@book_model.create
|
70
|
+
}.should_not raise_error
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return a Dupe::Database::Record instance with the desired parameters" do
|
74
|
+
book = @book_model.create
|
75
|
+
book.should be_kind_of(Dupe::Database::Record)
|
76
|
+
book.__model__.name.should == :book
|
77
|
+
book.id.should == 1
|
78
|
+
book.title.should == 'Untitled'
|
79
|
+
book.author.should == 'Anon'
|
80
|
+
book.label.should == 'untitled'
|
81
|
+
|
82
|
+
book = @book_model.create :title => 'Rooby On Rails', :author => 'Matt Parker'
|
83
|
+
book.__model__.name.should == :book
|
84
|
+
book.id.should == 2
|
85
|
+
book.title.should == 'Rooby On Rails'
|
86
|
+
book.label.should == 'rooby-on-rails'
|
87
|
+
book.author.should == 'Author: Matt Parker'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Network do
|
4
|
+
|
5
|
+
describe "new" do
|
6
|
+
before do
|
7
|
+
@network = Dupe::Network.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should initialize @mocks to a hash of empty arrays keyed with valid REST verbs" do
|
11
|
+
Dupe::Network::VERBS.each do |verb|
|
12
|
+
@network.mocks[verb].should == []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should initialize @log to a new Dupe::Network::Log" do
|
17
|
+
@network.log.should be_kind_of(Dupe::Network::Log)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "request" do
|
22
|
+
before do
|
23
|
+
@network = Dupe::Network.new
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should require a valid REST verb" do
|
27
|
+
proc { @network.request }.should raise_error
|
28
|
+
proc { @network.request :invalid_rest_verb, '/some_url' }.should raise_error(Dupe::Network::UnknownRestVerbError)
|
29
|
+
proc { @network.request :get, '/some_url' }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should require a URL" do
|
33
|
+
proc { @network.request :get }.should raise_error(ArgumentError)
|
34
|
+
proc { @network.request :get, 'some_url'}.should_not raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise an exception if the network has no mocks that match the url" do
|
38
|
+
proc { @network.request(:get, '/some_url')}.should raise_error(Dupe::Network::RequestNotFoundError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the appropriate mock response if a mock matches the url" do
|
42
|
+
@network.define_service_mock :get, %r{/greeting$}, proc { "hello" }
|
43
|
+
@network.request(:get, '/greeting').should == 'hello'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "define_service_mock" do
|
48
|
+
before do
|
49
|
+
@network = Dupe::Network.new
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should require a valid REST verb" do
|
53
|
+
proc { @network.define_service_mock }.should raise_error
|
54
|
+
proc { @network.define_service_mock :invalid_rest_verb, // }.should raise_error(Dupe::Network::UnknownRestVerbError)
|
55
|
+
proc { @network.define_service_mock :get, // }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should require a valid Regexp url pattern" do
|
59
|
+
proc { @network.define_service_mock :get, 'not a regular expression' }.should raise_error(ArgumentError)
|
60
|
+
proc { @network.define_service_mock :get, // }.should_not raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should create and return a new service mock when given valid parameters" do
|
64
|
+
verb = :get
|
65
|
+
pattern = //
|
66
|
+
response = proc { 'test' }
|
67
|
+
@network.mocks[:get].should be_empty
|
68
|
+
mock = @network.define_service_mock verb, pattern, response
|
69
|
+
@network.mocks[:get].should_not be_empty
|
70
|
+
@network.mocks[:get].length.should == 1
|
71
|
+
@network.mocks[:get].first.should == mock
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Database::Record do
|
4
|
+
describe "new" do
|
5
|
+
it "should create an object that is a kind of Hash" do
|
6
|
+
Dupe::Database::Record.new.should be_kind_of(Hash)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "id" do
|
11
|
+
it "should allow us to set the record id (and not the object id)" do
|
12
|
+
d = Dupe::Database::Record.new
|
13
|
+
d.id.should == nil
|
14
|
+
d[:id].should == nil
|
15
|
+
d.id = 1
|
16
|
+
d.id.should == 1
|
17
|
+
d[:id].should == 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "method_missing" do
|
22
|
+
it "should allow us to access hash keys as if they were object attributes" do
|
23
|
+
d = Dupe::Database::Record.new
|
24
|
+
d[:some_key].should == nil
|
25
|
+
d.some_key.should == nil
|
26
|
+
d.some_key = 1
|
27
|
+
d.some_key.should == 1
|
28
|
+
d[:some_key].should == 1
|
29
|
+
d[:another_key] = 2
|
30
|
+
d.another_key.should == 2
|
31
|
+
d[:another_key].should == 2
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "inspect" do
|
36
|
+
it "should show the class name" do
|
37
|
+
d = Dupe::Database::Record.new
|
38
|
+
d.inspect.should match(/^<#Dupe::Database::Record/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should show the key/value pairs as attributes" do
|
42
|
+
d = Dupe::Database::Record.new
|
43
|
+
d.title = 'test'
|
44
|
+
d.inspect.should match(/title="test"/)
|
45
|
+
d.author = Dupe::Database::Record.new
|
46
|
+
d.inspect.should match(/author=<#Dupe::Database::Record/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should show Fake::<model_name> when the record has a model" do
|
50
|
+
b = Dupe.create :book
|
51
|
+
b.inspect.should match(/^<#Duped::Book/)
|
52
|
+
b.author = Dupe.create :author
|
53
|
+
b.inspect.should match(/^<#Duped::Book/)
|
54
|
+
b.inspect.should match(/author=<#Duped::Author/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "__model__" do
|
59
|
+
it "should have a __model__ instance variable" do
|
60
|
+
proc {Dupe::Database::Record.new.__model__}.should_not raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should all you to set the __model_name__ instance variable" do
|
64
|
+
r = Dupe::Database::Record.new
|
65
|
+
proc {r.__model__ = :book}.should_not raise_error
|
66
|
+
r.__model__.should == :book
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Network::RestValidation do
|
4
|
+
before do
|
5
|
+
class TestRestValidation
|
6
|
+
include Dupe::Network::RestValidation
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "validate_request_type" do
|
11
|
+
it "should raise an exception if the request type isn't :get, :post, :put, or :delete" do
|
12
|
+
proc {
|
13
|
+
TestRestValidation.new.validate_request_type(:unknown_request_type)
|
14
|
+
}.should raise_error(Dupe::Network::UnknownRestVerbError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Dupe::Model::Schema do
|
4
|
+
describe "new" do
|
5
|
+
it "should initialize attribute_templates to an empty hash" do
|
6
|
+
Dupe::Model::Schema.new.attribute_templates.should == {}
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should initialize after_create_callbacks to an empty array" do
|
10
|
+
Dupe::Model::Schema.new.after_create_callbacks.should == []
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "dynamic attribute_template creation methods" do
|
15
|
+
before do
|
16
|
+
@schema = Dupe::Model::Schema.new
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "called with no parameters" do
|
20
|
+
it "should create a new attribute template with no transformer and no default value" do
|
21
|
+
@schema.title
|
22
|
+
@schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
|
23
|
+
@schema.attribute_templates[:title].name.should == :title
|
24
|
+
@schema.attribute_templates[:title].default.should be_nil
|
25
|
+
@schema.attribute_templates[:title].transformer.should be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "called with a single parameter, but no block" do
|
30
|
+
it "should create a new attribute template with a default value but no transformer" do
|
31
|
+
@schema.title 'Untitled'
|
32
|
+
@schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
|
33
|
+
@schema.attribute_templates[:title].name.should == :title
|
34
|
+
@schema.attribute_templates[:title].default.should == 'Untitled'
|
35
|
+
@schema.attribute_templates[:title].transformer.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "called with a block that accepts a parameter" do
|
40
|
+
it "should create a new attribute template without a default value, but with a tranformer" do
|
41
|
+
@schema.title {|dont_care| 'test'}
|
42
|
+
@schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
|
43
|
+
@schema.attribute_templates[:title].name.should == :title
|
44
|
+
@schema.attribute_templates[:title].default.should be_nil
|
45
|
+
@schema.attribute_templates[:title].transformer.should be_kind_of(Proc)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "called with a block that doesn't accept a parameter" do
|
50
|
+
it "should create a new attribute template without a transformer, and with the block as the default value" do
|
51
|
+
@schema.title { 'knock' * 3 }
|
52
|
+
@schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
|
53
|
+
@schema.attribute_templates[:title].name.should == :title
|
54
|
+
@schema.attribute_templates[:title].default.should be_kind_of(Proc)
|
55
|
+
@schema.attribute_templates[:title].default.call.should == "knockknockknock"
|
56
|
+
@schema.attribute_templates[:title].transformer.should be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "called with a block and a parameter" do
|
61
|
+
it "should create a new attribute template with a default value AND with a tranformer" do
|
62
|
+
@schema.title('Untitled') {|dont_care| 'test'}
|
63
|
+
@schema.attribute_templates[:title].should be_kind_of(Dupe::Model::Schema::AttributeTemplate)
|
64
|
+
@schema.attribute_templates[:title].name.should == :title
|
65
|
+
@schema.attribute_templates[:title].default.should == 'Untitled'
|
66
|
+
@schema.attribute_templates[:title].transformer.should be_kind_of(Proc)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#after_create" do
|
72
|
+
before do
|
73
|
+
@schema = Dupe::Model::Schema.new
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should require a block that accepts a single parameter" do
|
77
|
+
proc { @schema.after_create }.should raise_error(ArgumentError)
|
78
|
+
proc { @schema.after_create { "parameterless block" } }.should raise_error(ArgumentError)
|
79
|
+
proc { @schema.after_create {|s| s.title = 'test' } }.should_not raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should add the callback to the list of after_create_callbacks" do
|
83
|
+
@schema.after_create_callbacks.should be_empty
|
84
|
+
@schema.after_create {|s| s.title = 'test'}
|
85
|
+
@schema.after_create_callbacks.length.should == 1
|
86
|
+
@schema.after_create_callbacks.first.should be_kind_of(Proc)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Sequence do
|
4
|
+
describe "new" do
|
5
|
+
it "should intialize the current value to whatever is passed in (or 1 by default)" do
|
6
|
+
Sequence.new.current_value.should == 1
|
7
|
+
Sequence.new(500).current_value.should == 500
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "next" do
|
12
|
+
it "should return the next value in the sequence, then increment the current value" do
|
13
|
+
s = Sequence.new
|
14
|
+
s.next.should == 1
|
15
|
+
s.current_value.should == 2
|
16
|
+
s.next.should == 2
|
17
|
+
s.current_value.should == 3
|
18
|
+
|
19
|
+
s = Sequence.new(500)
|
20
|
+
s.next.should == 500
|
21
|
+
s.current_value.should == 501
|
22
|
+
s.next.should == 501
|
23
|
+
s.current_value.should == 502
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "plural?" do
|
5
|
+
it "should report plural symbols as plural" do
|
6
|
+
'apples'.plural?.should == true
|
7
|
+
'apple'.plural?.should == false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "singular?" do
|
12
|
+
it "should report singular items as singular" do
|
13
|
+
'apples'.singular?.should == false
|
14
|
+
'apple'.singular?.should == true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "indent" do
|
19
|
+
it "should default the indentional level to 2 spaces" do
|
20
|
+
'apples'.indent.should == " apples"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept an indentional level" do
|
24
|
+
'apples'.indent(4).should == " apples"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should indent each line of the string" do
|
28
|
+
"apples\noranges".indent(2).should == " apples\n oranges"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Symbol do
|
4
|
+
describe "plural?" do
|
5
|
+
it "should report plural symbols as plural" do
|
6
|
+
:apples.plural?.should == true
|
7
|
+
:apple.plural?.should == false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "singular?" do
|
12
|
+
it "should report singular items as singular" do
|
13
|
+
:apples.singular?.should == false
|
14
|
+
:apple.singular?.should == true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
$LOAD_PATH
|
2
|
-
# require 'rubygems'
|
3
|
-
# gem 'activeresource'
|
4
|
-
# gem 'rspec'
|
1
|
+
$LOAD_PATH.unshift './lib'
|
5
2
|
require 'rubygems'
|
6
3
|
gem 'activeresource'
|
7
4
|
gem 'rspec'
|
8
5
|
gem 'cucumber'
|
9
6
|
require 'cucumber'
|
10
|
-
require '
|
7
|
+
require 'active_resource'
|
11
8
|
require 'dupe'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dupe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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-
|
12
|
+
date: 2009-12-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,15 +36,23 @@ extra_rdoc_files:
|
|
36
36
|
files:
|
37
37
|
- README.rdoc
|
38
38
|
- lib/dupe.rb
|
39
|
-
- lib/dupe/
|
40
|
-
- lib/dupe/
|
41
|
-
- lib/dupe/configuration.rb
|
39
|
+
- lib/dupe/active_resource_extensions.rb
|
40
|
+
- lib/dupe/attribute_template.rb
|
42
41
|
- lib/dupe/cucumber_hooks.rb
|
42
|
+
- lib/dupe/custom_mocks.rb
|
43
|
+
- lib/dupe/database.rb
|
43
44
|
- lib/dupe/dupe.rb
|
44
|
-
- lib/dupe/
|
45
|
+
- lib/dupe/log.rb
|
46
|
+
- lib/dupe/mock.rb
|
47
|
+
- lib/dupe/model.rb
|
48
|
+
- lib/dupe/network.rb
|
45
49
|
- lib/dupe/record.rb
|
50
|
+
- lib/dupe/rest_validation.rb
|
51
|
+
- lib/dupe/schema.rb
|
46
52
|
- lib/dupe/sequence.rb
|
53
|
+
- lib/dupe/singular_plural_detection.rb
|
47
54
|
- lib/dupe/string.rb
|
55
|
+
- lib/dupe/symbol.rb
|
48
56
|
- rails_generators/dupe/dupe_generator.rb
|
49
57
|
- rails_generators/dupe/templates/custom_mocks.rb
|
50
58
|
- rails_generators/dupe/templates/dupe_setup.rb
|
@@ -77,6 +85,20 @@ signing_key:
|
|
77
85
|
specification_version: 3
|
78
86
|
summary: A tool that helps you mock services while cuking.
|
79
87
|
test_files:
|
80
|
-
- spec/lib_specs/
|
88
|
+
- spec/lib_specs/active_resource_extensions_spec.rb
|
89
|
+
- spec/lib_specs/attribute_template_spec.rb
|
90
|
+
- spec/lib_specs/database_spec.rb
|
81
91
|
- spec/lib_specs/dupe_spec.rb
|
92
|
+
- spec/lib_specs/log_spec.rb
|
93
|
+
- spec/lib_specs/logged_request_spec.rb
|
94
|
+
- spec/lib_specs/mock_definitions_spec.rb
|
95
|
+
- spec/lib_specs/mock_spec.rb
|
96
|
+
- spec/lib_specs/model_spec.rb
|
97
|
+
- spec/lib_specs/network_spec.rb
|
98
|
+
- spec/lib_specs/record_spec.rb
|
99
|
+
- spec/lib_specs/rest_validation_spec.rb
|
100
|
+
- spec/lib_specs/schema_spec.rb
|
101
|
+
- spec/lib_specs/sequence_spec.rb
|
102
|
+
- spec/lib_specs/string_spec.rb
|
103
|
+
- spec/lib_specs/symbol_spec.rb
|
82
104
|
- spec/spec_helper.rb
|