rdbi-driver-mock 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/rdbi/driver/mock.rb +135 -0
- data/rdbi-driver-mock.gemspec +52 -0
- data/test/helper.rb +10 -0
- metadata +89 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Erik Hollensbe
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= rdbi-driver-mock
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Erik Hollensbe. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rdbi-driver-mock"
|
8
|
+
gem.summary = %Q{Mock Driver for RDBI, used for testing}
|
9
|
+
gem.description = gem.summary
|
10
|
+
gem.email = "erik@hollensbe.org"
|
11
|
+
gem.homepage = "http://github.com/erikh/rdbi-driver-mock"
|
12
|
+
gem.authors = ["Erik Hollensbe"]
|
13
|
+
|
14
|
+
gem.add_development_dependency 'test-unit'
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module RDBI
|
2
|
+
class Driver
|
3
|
+
class Mock < RDBI::Driver
|
4
|
+
def initialize(*args)
|
5
|
+
super(Mock::DBH, *args)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# XXX STUB
|
10
|
+
class Mock::STH < RDBI::Statement
|
11
|
+
attr_accessor :result
|
12
|
+
attr_accessor :affected_count
|
13
|
+
attr_accessor :set_schema
|
14
|
+
attr_accessor :input_type_map
|
15
|
+
|
16
|
+
def initialize(query, dbh)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# just to be abundantly clear, this is a mock method intended to
|
21
|
+
# facilitate tests.
|
22
|
+
def new_execution(*binds)
|
23
|
+
this_data = if result
|
24
|
+
result
|
25
|
+
else
|
26
|
+
(0..4).to_a.collect do |x|
|
27
|
+
binds.collect do |bind|
|
28
|
+
case bind
|
29
|
+
when Integer
|
30
|
+
bind + x
|
31
|
+
else
|
32
|
+
bind.to_s + x.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
return Mock::Cursor.new(this_data), @set_schema || RDBI::Schema.new((0..9).to_a.map { |x| RDBI::Column.new(x) }), RDBI::Type.create_type_hash(RDBI::Type::Out)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Mock::DBH < RDBI::Database
|
43
|
+
extend MethLab
|
44
|
+
|
45
|
+
attr_accessor :next_action
|
46
|
+
|
47
|
+
def new_statement(query)
|
48
|
+
Mock::STH.new(query, self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ping
|
52
|
+
10
|
53
|
+
end
|
54
|
+
|
55
|
+
inline(:rollback) { super(); "rollback called" }
|
56
|
+
|
57
|
+
# XXX more methods to be defined this way.
|
58
|
+
inline(:commit) do |*args|
|
59
|
+
super(*args)
|
60
|
+
|
61
|
+
ret = nil
|
62
|
+
|
63
|
+
if next_action
|
64
|
+
ret = next_action.call(*args)
|
65
|
+
self.next_action = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
ret
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Mock::Cursor < RDBI::Cursor
|
73
|
+
def initialize(handle)
|
74
|
+
super(handle.dup)
|
75
|
+
@index = 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def fetch(count=1)
|
79
|
+
return [] if last_row?
|
80
|
+
a = []
|
81
|
+
count.times { a.push(next_row) }
|
82
|
+
return a
|
83
|
+
end
|
84
|
+
|
85
|
+
def next_row
|
86
|
+
retval = @handle[@index]
|
87
|
+
@index += 1
|
88
|
+
return retval
|
89
|
+
end
|
90
|
+
|
91
|
+
def result_count
|
92
|
+
@handle.size
|
93
|
+
end
|
94
|
+
|
95
|
+
def affected_count
|
96
|
+
16 # magic number
|
97
|
+
end
|
98
|
+
|
99
|
+
def first
|
100
|
+
@handle.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def last
|
104
|
+
@handle.last
|
105
|
+
end
|
106
|
+
|
107
|
+
def rest
|
108
|
+
oindex, @index = @index, @handle.size
|
109
|
+
@handle[oindex, @index]
|
110
|
+
end
|
111
|
+
|
112
|
+
def all
|
113
|
+
@handle.dup
|
114
|
+
end
|
115
|
+
|
116
|
+
def [](index)
|
117
|
+
@handle[index]
|
118
|
+
end
|
119
|
+
|
120
|
+
def last_row?
|
121
|
+
@index == @handle.size
|
122
|
+
end
|
123
|
+
|
124
|
+
def rewind
|
125
|
+
@index = 0
|
126
|
+
end
|
127
|
+
|
128
|
+
def empty?
|
129
|
+
@handle.empty?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# vim: syntax=ruby ts=2 et sw=2 sts=2
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rdbi-driver-mock}
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Erik Hollensbe"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.description = %q{Mock Driver for RDBI, used for testing}
|
14
|
+
s.email = %q{erik@hollensbe.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rdbi/driver/mock.rb",
|
27
|
+
"rdbi-driver-mock.gemspec",
|
28
|
+
"test/helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/erikh/rdbi-driver-mock}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{Mock Driver for RDBI, used for testing}
|
35
|
+
s.test_files = [
|
36
|
+
"test/helper.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdbi-driver-mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Erik Hollensbe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-21 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: test-unit
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Mock Driver for RDBI, used for testing
|
36
|
+
email: erik@hollensbe.org
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/rdbi/driver/mock.rb
|
52
|
+
- rdbi-driver-mock.gemspec
|
53
|
+
- test/helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/erikh/rdbi-driver-mock
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Mock Driver for RDBI, used for testing
|
88
|
+
test_files:
|
89
|
+
- test/helper.rb
|