test-mysqld 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -4,35 +4,49 @@ require "tmpdir"
4
4
 
5
5
  module Test
6
6
  class Mysqld
7
+ def self.auto_start
8
+ @@auto_start ||= false
9
+ end
10
+
11
+ def self.auto_start=(value)
12
+ @@auto_start = !!value
13
+ end
14
+
15
+ def self.database
16
+ @@database ||= 'test'
17
+ end
18
+
19
+ def self.database=(database)
20
+ @@database = database
21
+ end
22
+
7
23
  def initialize(options={})
8
24
  parse_options options
9
25
  raise "mysqld is alread running (#{mycnf["pid-file"]})" if FileTest.exist? mycnf["pid-file"]
10
- if options[:auto_start]
11
- setup
12
- start
13
- end
14
26
  setup
27
+ start if options[:auto_start] || self.class.auto_start
15
28
  end
16
29
 
17
30
  def dsn(options={})
18
31
  options.tap do |option|
19
- options[:port] ||= mycnf["port"] if mycnf["port"]
20
- if options[:port]
21
- options[:host] ||= mycnf["bind-address"] || "127.0.0.1"
22
- else
23
- options[:socket] ||= mycnf["socket"]
24
- end
32
+ options[:host] ||= mycnf["bind-address"] if mycnf["bind-address"]
33
+ options[:port] ||= mycnf["port"]
34
+ options[:socket] ||= mycnf["socket"]
25
35
  options[:username] ||= "root"
26
- options[:database] ||= "test"
36
+ options[:database] ||= self.class.database
27
37
  end
28
38
  end
29
39
 
40
+ def mycnf_file
41
+ File.open(base_dir + '/etc/my.cnf', 'rb'){ |f| f.read }
42
+ end
43
+
30
44
  def setup
31
45
  File.open(base_dir + '/etc/my.cnf', 'wb') do |f|
32
46
  f.puts "[mysqld]"
33
47
  mycnf.each do |key, val|
34
- if val.nil? or val.empty?
35
- f.puts "#{val}"
48
+ if val.nil?
49
+ f.puts "#{key}"
36
50
  else
37
51
  f.puts "#{key}=#{val}"
38
52
  end
@@ -103,6 +117,7 @@ module Test
103
117
  @mycnf["socket"] ||= base_dir + '/tmp/mysql.sock'
104
118
  @mycnf["datadir"] ||= base_dir + '/var'
105
119
  @mycnf["pid-file"] ||= base_dir + '/tmp/mysql.pid'
120
+ @mycnf["port"] ||= 13306
106
121
 
107
122
  @mysqld = options[:mysqld] || find_mysqld
108
123
  @mysql_install_db = options[:mysql_install_db] || find_mysql_install_db
@@ -135,7 +150,7 @@ module Test
135
150
 
136
151
  def create_database
137
152
  connection = mysql2_or_mysql_connection
138
- connection.query("CREATE DATABASE IF NOT EXISTS test")
153
+ connection.query("CREATE DATABASE IF NOT EXISTS #{connection.escape self.class.database}")
139
154
  connection.close
140
155
  end
141
156
 
@@ -168,7 +183,9 @@ module Test
168
183
  end
169
184
  if defined? ::Mysql
170
185
  opts = dsn :database => 'mysql'
171
- Mysql.new(opts[:username], nil, opts[:host], opts[:port], opts[:database], opts[:socket], opts[:flags])
186
+ conn = Mysql.new(opts[:host], opts[:username], opts[:password], opts[:database], opts[:port], opts[:socket], opts[:flags])
187
+ def conn.escape(str); escape_string str; end
188
+ conn
172
189
  else
173
190
  nil
174
191
  end
@@ -1,9 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'test-mysqld'
3
+ require 'test/mysqld'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
-
8
+
9
9
  end
@@ -1,7 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "TestMysqld" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
3
+ describe Test::Mysqld do
4
+ describe ".auto_start" do
5
+ subject { Test::Mysqld }
6
+ its(:auto_start) { should be_false }
7
+
8
+ context "after set true" do
9
+ before { Test::Mysqld.auto_start = true }
10
+ its(:auto_start) { should be_true }
11
+ end
12
+
13
+ describe "should be true or false" do
14
+ it "set Integer" do
15
+ Test::Mysqld.auto_start = 1
16
+ Test::Mysqld.auto_start.should be_true
17
+ end
18
+
19
+ it "set String" do
20
+ Test::Mysqld.auto_start = "false"
21
+ Test::Mysqld.auto_start.should be_true
22
+ end
23
+
24
+ it "set nil" do
25
+ Test::Mysqld.auto_start = nil
26
+ Test::Mysqld.auto_start.should be_false
27
+ end
28
+ end
6
29
  end
7
30
  end
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{test-mysqld}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["miyucy"]
12
+ s.date = %q{2011-05-19}
13
+ s.description = %q{port of Test::mysqld (mysqld runner for tests)}
14
+ s.email = %q{miyucy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/test/mysqld.rb",
26
+ "spec/spec.opts",
27
+ "spec/spec_helper.rb",
28
+ "spec/test-mysqld_spec.rb",
29
+ "test-mysqld.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/miyucy/test-mysqld}
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.6.2}
34
+ s.summary = %q{port of Test::mysqld}
35
+ s.test_files = [
36
+ "spec/spec_helper.rb",
37
+ "spec/test-mysqld_spec.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
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<rspec>, [">= 1.2.9"])
45
+ else
46
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ end
51
+ end
52
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-mysqld
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 29
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - miyucy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-10 00:00:00 +09:00
18
+ date: 2011-05-19 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,6 @@ extra_rdoc_files:
45
45
  - README.rdoc
46
46
  files:
47
47
  - .document
48
- - .gitignore
49
48
  - LICENSE
50
49
  - README.rdoc
51
50
  - Rakefile
@@ -54,13 +53,14 @@ files:
54
53
  - spec/spec.opts
55
54
  - spec/spec_helper.rb
56
55
  - spec/test-mysqld_spec.rb
56
+ - test-mysqld.gemspec
57
57
  has_rdoc: true
58
58
  homepage: http://github.com/miyucy/test-mysqld
59
59
  licenses: []
60
60
 
61
61
  post_install_message:
62
- rdoc_options:
63
- - --charset=UTF-8
62
+ rdoc_options: []
63
+
64
64
  require_paths:
65
65
  - lib
66
66
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -84,10 +84,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements: []
85
85
 
86
86
  rubyforge_project:
87
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.6.2
88
88
  signing_key:
89
89
  specification_version: 3
90
90
  summary: port of Test::mysqld
91
91
  test_files:
92
- - spec/test-mysqld_spec.rb
93
92
  - spec/spec_helper.rb
93
+ - spec/test-mysqld_spec.rb
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC