imedo-dry_plugin_test_helper 0.0.6 → 0.0.7
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 +4 -5
- data/lib/dry_plugin_test_helper.rb +0 -5
- data/lib/plugin_test_environment.rb +43 -10
- data/{rails_root → rails_root_fixtures}/app/models/article.rb +0 -0
- data/{rails_root → rails_root_fixtures}/app/models/author.rb +0 -0
- data/{rails_root → rails_root_fixtures}/app/models/comment.rb +0 -0
- data/{rails_root → rails_root_fixtures}/app/models/user.rb +0 -0
- data/rails_root_fixtures/config/database.yml +12 -0
- data/{rails_root → rails_root_fixtures}/db/migrate/001_create_environment.rb +0 -0
- data/{rails_root → rails_root_fixtures}/vendor/plugins/plugin_to_test/init.rb +2 -2
- metadata +17 -40
- data/rails_root/app/controllers/application.rb +0 -2
- data/rails_root/config/boot.rb +0 -45
- data/rails_root/config/database.yml +0 -21
- data/rails_root/config/environment.rb +0 -11
- data/rails_root/config/environments/mysql.rb +0 -0
- data/rails_root/config/environments/postgresql.rb +0 -0
- data/rails_root/config/environments/sqlite.rb +0 -0
- data/rails_root/config/environments/sqlite3.rb +0 -0
- data/rails_root/config/environments/test.rb +0 -0
- data/rails_root/config/routes.rb +0 -9
- data/rails_root/script/console +0 -3
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ Bugs:: No dedicated bug tracker yet - Email us or just send pull requests
|
|
9
9
|
Makes your plugin tests dry and isolates plugin tests from you real app.
|
10
10
|
|
11
11
|
== Dependencies
|
12
|
-
* Rails 2.0.2 (should work also with 1.2)
|
12
|
+
* Rails > 2.0.2 (should work also with 1.2)
|
13
13
|
* sqlite3 - http://www.sqlite.org/
|
14
14
|
|
15
15
|
== Installation
|
@@ -26,7 +26,7 @@ download the source code and build the gem yourself
|
|
26
26
|
$ git clone git://github.com/imedo/dry_plugin_test_helper.git
|
27
27
|
$ cd dry_plugin_test_helper
|
28
28
|
$ rake
|
29
|
-
$ sudo gem install pkg/dry_plugin_test_helper-0.0.
|
29
|
+
$ sudo gem install pkg/dry_plugin_test_helper-0.0.7.gem
|
30
30
|
|
31
31
|
== Usage
|
32
32
|
|
@@ -37,8 +37,7 @@ In your plugin test helper use these lines:
|
|
37
37
|
|
38
38
|
PluginTestEnvironment.initialize_environment(File.dirname(__FILE__))
|
39
39
|
|
40
|
-
This sets up the test environment which means you have a stub rails app with
|
41
|
-
you plugin loaded and also the following models:
|
40
|
+
This sets up the test environment in $HOME/.dry_plugin_test_helper/2.3/ (for Rails 2.3) which means you have a stub rails app with you plugin loaded and also the following models:
|
42
41
|
|
43
42
|
* Article: belongs_to :author, has_many :comments
|
44
43
|
* Author: has_many :articles
|
@@ -70,7 +69,7 @@ initialize the test environment like this:
|
|
70
69
|
|
71
70
|
PluginTestEnvironment.initialize_environment(File.dirname(__FILE__), :use_standard_migration => false)
|
72
71
|
|
72
|
+
|
73
73
|
== TODO
|
74
74
|
* support for RSpec and other testing frameworks (might already work - haven't tried it)
|
75
75
|
* Automatic Rails version discovery
|
76
|
-
* Clean up / strip down rails env to bare minimum
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class PluginTestEnvironment
|
2
2
|
|
3
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :plugin_path
|
5
|
+
end
|
4
6
|
|
5
7
|
# initializes the test environment
|
6
8
|
#
|
@@ -14,8 +16,10 @@ class PluginTestEnvironment
|
|
14
16
|
plugin_dir = find_plugin_dir_by_caller
|
15
17
|
end
|
16
18
|
end
|
19
|
+
|
17
20
|
self.plugin_path = File.join(plugin_dir, '..')
|
18
|
-
require
|
21
|
+
require rails_root_dir(options[:rails_version]) + '/config/boot.rb'
|
22
|
+
require File.dirname(__FILE__) + '/silent_logger'
|
19
23
|
|
20
24
|
Rails::Initializer.run do |config|
|
21
25
|
config.logger = SilentLogger.new
|
@@ -29,8 +33,8 @@ class PluginTestEnvironment
|
|
29
33
|
yield config if block_given?
|
30
34
|
end
|
31
35
|
|
32
|
-
require
|
33
|
-
|
36
|
+
require rails_root_dir(options[:rails_version]) + '/config/environment.rb'
|
37
|
+
|
34
38
|
Test::Unit::TestCase.class_eval do
|
35
39
|
cattr_accessor :rails_root
|
36
40
|
self.rails_root = PluginTestEnvironment.plugin_path
|
@@ -42,6 +46,35 @@ class PluginTestEnvironment
|
|
42
46
|
plugin_migration
|
43
47
|
end
|
44
48
|
|
49
|
+
def self.rails_root_dir(rails_version)
|
50
|
+
rails_dir = File.join(test_helper_base_dir, "#{rails_version || latest_rails_version}/")
|
51
|
+
init_environment(rails_version || latest_rails_version) unless File.exists?(rails_dir)
|
52
|
+
rails_dir
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.test_helper_base_dir
|
56
|
+
File.join(ENV['HOME'], ".dry_plugin_test_helper")
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.latest_rails_version
|
60
|
+
Gem.cache.find_name(/^rails$/).map { |g| g.version.version }.last
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.init_environment(rails_version)
|
64
|
+
target_directory = File.join(test_helper_base_dir, rails_version)
|
65
|
+
FileUtils.mkdir_p target_directory
|
66
|
+
system("rails _#{rails_version}_ #{File.expand_path(target_directory)}")
|
67
|
+
FileUtils.cp_r File.dirname(__FILE__) + '/../rails_root_fixtures/app/models', target_directory + '/app'
|
68
|
+
FileUtils.cp_r File.dirname(__FILE__) + '/../rails_root_fixtures/db/migrate', target_directory + '/db'
|
69
|
+
FileUtils.cp_r File.dirname(__FILE__) + '/../rails_root_fixtures/vendor/plugins/plugin_to_test', target_directory + '/vendor/plugins/'
|
70
|
+
FileUtils.cp File.dirname(__FILE__) + '/../rails_root_fixtures/config/database.yml', target_directory + '/config/database.yml'
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.remove_environment_for_rails_version(version)
|
74
|
+
dir = File.join(test_helper_base_dir, version)
|
75
|
+
FileUtils.rm_r(dir) if File.exists?(dir)
|
76
|
+
end
|
77
|
+
|
45
78
|
def self.initialize_engines_environment(plugin_dir, options = {:use_standard_migration => true})
|
46
79
|
initialize_environment(plugin_dir, options.merge(:skip_fixtures => true)) do |config|
|
47
80
|
initialize_engines
|
@@ -143,6 +176,12 @@ class PluginTestEnvironment
|
|
143
176
|
def self.plugin_migration
|
144
177
|
custom_migration = "#{PluginTestEnvironment.plugin_path}/test/migration.rb"
|
145
178
|
if File.exists?(custom_migration)
|
179
|
+
self.const_set(:Migration, Class.new(ActiveRecord::Migration))
|
180
|
+
Migration.class_eval do
|
181
|
+
def self.setup(&block)
|
182
|
+
self.class.send(:define_method, :up, &block)
|
183
|
+
end
|
184
|
+
end
|
146
185
|
require custom_migration
|
147
186
|
Migration.up
|
148
187
|
end
|
@@ -153,10 +192,4 @@ class PluginTestEnvironment
|
|
153
192
|
File.dirname(caller[1].split(":").first)
|
154
193
|
end
|
155
194
|
|
156
|
-
class Migration < ActiveRecord::Migration
|
157
|
-
def self.setup(&block)
|
158
|
-
self.class.send(:define_method, :up, &block)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
195
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,3 +1,3 @@
|
|
1
|
-
init_path = PluginTestEnvironment.plugin_path + "/init.rb" #
|
2
|
-
|
1
|
+
init_path = PluginTestEnvironment.plugin_path + "/init.rb" #
|
2
|
+
|
3
3
|
silence_warnings { eval(IO.read(init_path), binding, init_path) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imedo-dry_plugin_test_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Volkmer
|
@@ -9,19 +9,9 @@ autorequire: active_record
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: activerecord
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.15.3
|
24
|
-
version:
|
25
15
|
- !ruby/object:Gem::Dependency
|
26
16
|
name: sqlite3-ruby
|
27
17
|
type: :runtime
|
@@ -44,34 +34,21 @@ files:
|
|
44
34
|
- lib/dry_plugin_test_helper.rb
|
45
35
|
- lib/plugin_test_environment.rb
|
46
36
|
- lib/silent_logger.rb
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
- rails_root/config/environments/sqlite.rb
|
63
|
-
- rails_root/config/environments/sqlite3.rb
|
64
|
-
- rails_root/config/environments/test.rb
|
65
|
-
- rails_root/config/routes.rb
|
66
|
-
- rails_root/db
|
67
|
-
- rails_root/db/migrate
|
68
|
-
- rails_root/db/migrate/001_create_environment.rb
|
69
|
-
- rails_root/script
|
70
|
-
- rails_root/script/console
|
71
|
-
- rails_root/vendor
|
72
|
-
- rails_root/vendor/plugins
|
73
|
-
- rails_root/vendor/plugins/plugin_to_test
|
74
|
-
- rails_root/vendor/plugins/plugin_to_test/init.rb
|
37
|
+
- rails_root_fixtures/app
|
38
|
+
- rails_root_fixtures/app/models
|
39
|
+
- rails_root_fixtures/app/models/article.rb
|
40
|
+
- rails_root_fixtures/app/models/author.rb
|
41
|
+
- rails_root_fixtures/app/models/comment.rb
|
42
|
+
- rails_root_fixtures/app/models/user.rb
|
43
|
+
- rails_root_fixtures/config
|
44
|
+
- rails_root_fixtures/config/database.yml
|
45
|
+
- rails_root_fixtures/db
|
46
|
+
- rails_root_fixtures/db/migrate
|
47
|
+
- rails_root_fixtures/db/migrate/001_create_environment.rb
|
48
|
+
- rails_root_fixtures/vendor
|
49
|
+
- rails_root_fixtures/vendor/plugins
|
50
|
+
- rails_root_fixtures/vendor/plugins/plugin_to_test
|
51
|
+
- rails_root_fixtures/vendor/plugins/plugin_to_test/init.rb
|
75
52
|
- fixtures/articles.yml
|
76
53
|
- README.rdoc
|
77
54
|
has_rdoc: true
|
data/rails_root/config/boot.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
|
2
|
-
|
3
|
-
unless defined?(RAILS_ROOT)
|
4
|
-
root_path = File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
7
|
-
require 'pathname'
|
8
|
-
root_path = Pathname.new(root_path).cleanpath(true).to_s
|
9
|
-
end
|
10
|
-
|
11
|
-
RAILS_ROOT = root_path
|
12
|
-
end
|
13
|
-
|
14
|
-
unless defined?(Rails::Initializer)
|
15
|
-
if File.directory?("#{RAILS_ROOT}/vendor/rails")
|
16
|
-
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
17
|
-
else
|
18
|
-
require 'rubygems'
|
19
|
-
|
20
|
-
environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
|
21
|
-
environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
|
22
|
-
rails_gem_version = $1
|
23
|
-
|
24
|
-
if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
|
25
|
-
# Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
|
26
|
-
rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
|
27
|
-
|
28
|
-
if rails_gem
|
29
|
-
gem "rails", "=#{rails_gem.version.version}"
|
30
|
-
require rails_gem.full_gem_path + '/lib/initializer'
|
31
|
-
else
|
32
|
-
STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
|
33
|
-
Install the missing gem with 'gem install -v=#{version} rails', or
|
34
|
-
change environment.rb to define RAILS_GEM_VERSION with your desired version.
|
35
|
-
)
|
36
|
-
exit 1
|
37
|
-
end
|
38
|
-
else
|
39
|
-
gem "rails"
|
40
|
-
require 'initializer'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
Rails::Initializer.run(:set_load_path)
|
45
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
sqlite:
|
2
|
-
:adapter: sqlite
|
3
|
-
:dbfile: ':memory:'
|
4
|
-
sqlite3:
|
5
|
-
:adapter: sqlite3
|
6
|
-
:dbfile: ':memory:'
|
7
|
-
test:
|
8
|
-
:adapter: sqlite3
|
9
|
-
:dbfile: ':memory:'
|
10
|
-
postgresql:
|
11
|
-
:adapter: postgresql
|
12
|
-
:username: postgres
|
13
|
-
:password: postgres
|
14
|
-
:database: most_popular_test
|
15
|
-
:min_messages: ERROR
|
16
|
-
mysql:
|
17
|
-
:adapter: mysql
|
18
|
-
:host: localhost
|
19
|
-
:username: root
|
20
|
-
:password:
|
21
|
-
:database: most_popular_test
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# Specifies gem version of Rails to use when vendor/rails is not present
|
2
|
-
#RAILS_GEM_VERSION = '1.1.6'
|
3
|
-
#RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), 'boot')
|
6
|
-
|
7
|
-
Dependencies.log_activity = false
|
8
|
-
|
9
|
-
# Load the testing framework
|
10
|
-
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
11
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/rails_root/config/routes.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
ActionController::Routing::Routes.draw do |map|
|
2
|
-
# Allow downloading Web Service WSDL as a file with an extension
|
3
|
-
# instead of a file named 'wsdl'
|
4
|
-
map.connect ':controller/service.wsdl', :action => 'wsdl'
|
5
|
-
|
6
|
-
# Default route
|
7
|
-
map.connect ':controller/:action/:id.:format'
|
8
|
-
map.connect ':controller/:action/:id'
|
9
|
-
end
|
data/rails_root/script/console
DELETED