imedo-dry_plugin_test_helper 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -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.3.gem
29
+ $ sudo gem install pkg/dry_plugin_test_helper-0.0.4.gem
30
30
 
31
31
  == Usage
32
32
 
@@ -35,8 +35,7 @@ In your plugin test helper use these lines:
35
35
  require 'rubygems'
36
36
  require 'dry_plugin_test_helper'
37
37
 
38
- PluginTestEnvironment.init_env(File.dirname(__FILE__))
39
-
38
+ PluginTestEnvironment.initialize_environment(File.dirname(__FILE__))
40
39
 
41
40
  This sets up the test environment which means you have a stub rails app with
42
41
  you plugin loaded and also the following models:
@@ -59,14 +58,19 @@ this:
59
58
  end
60
59
 
61
60
  end
61
+
62
+ The database is automatically filled with the standard fixtures supplied by the gem.
63
+ If you want to use your own fixtures (e.g. if you use additionals models) create them
64
+ in the test/fixtures directory of your plugin. Note that the standard fixtures won't
65
+ get loaded if you use your own so you might have to add fixtures for the standard
66
+ models if you need them.
62
67
 
63
- If you don't want the standard models you can initialize the test environment
64
- like this:
68
+ If you don't want the standard models (= database tables and fixtures) you can
69
+ initialize the test environment like this:
65
70
 
66
- PluginTestEnvironment.init_env(File.dirname(__FILE__), false)
71
+ PluginTestEnvironment.initialize_environment(File.dirname(__FILE__), :use_standard_migration => false)
67
72
 
68
73
  == TODO
69
- * Tests for the test gem itself
70
74
  * support for RSpec and other testing frameworks (might already work - haven't tried it)
71
75
  * Automatic Rails version discovery
72
76
  * Clean up / strip down rails env to bare minimum
@@ -6,36 +6,3 @@ ENV['RAILS_ENV'] ||= 'sqlite3'
6
6
 
7
7
  require File.dirname(__FILE__) + '/silent_logger'
8
8
  require File.dirname(__FILE__) + '/plugin_test_environment'
9
-
10
- require 'time'
11
-
12
-
13
- # Code by Jay Fields
14
- # http://blog.jayfields.com/2007/11/ruby-timeis.html
15
- class Time
16
- def self.metaclass
17
- class << self; self; end
18
- end
19
-
20
- def self.is(point_in_time)
21
- new_time = case point_in_time
22
- when String then Time.parse(point_in_time)
23
- when Time then point_in_time
24
- else raise ArgumentError.new("argument should be a string or time instance")
25
- end
26
- class << self
27
- alias old_now now
28
- end
29
- metaclass.class_eval do
30
- define_method :now do
31
- new_time
32
- end
33
- end
34
- yield
35
- class << self
36
- alias now old_now
37
- undef old_now
38
- end
39
- end
40
- end
41
-
@@ -2,13 +2,124 @@ class PluginTestEnvironment
2
2
 
3
3
  cattr_accessor :plugin_path
4
4
 
5
- def self.init_env(dir, standard_migration = true)
6
- self.plugin_path = "#{dir}/.."
5
+ # initializes the test environment
6
+ #
7
+ #
8
+ def self.initialize_environment(plugin_dir, options = {:use_standard_migration => true})
9
+ self.plugin_path = File.join(plugin_dir, '..')
10
+ require File.dirname(__FILE__) + '/../rails_root/config/boot.rb'
11
+
12
+ Rails::Initializer.run do |config|
13
+ config.logger = SilentLogger.new
14
+ config.log_level = :debug
15
+
16
+ config.cache_classes = false
17
+ config.whiny_nils = true
18
+
19
+ config.load_paths << "#{File.dirname(__FILE__)}/../../../lib/"
20
+
21
+ yield config if block_given?
22
+ end
23
+
7
24
  require File.dirname(__FILE__) + '/../rails_root/config/environment.rb'
8
- ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate") if standard_migration
25
+
26
+ Test::Unit::TestCase.class_eval do
27
+ cattr_accessor :rails_root
28
+ self.rails_root = PluginTestEnvironment.plugin_path
29
+ end
30
+
31
+ initialize_fixtures unless options[:skip_fixtures]
32
+
33
+ ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate") if options[:use_standard_migration]
9
34
  plugin_migration
10
35
  end
11
36
 
37
+ def self.initialize_engines_environment(plugin_dir, options = {:use_standard_migration => true})
38
+ initialize_environment(plugin_dir, options.merge(:skip_fixtures => true)) do |config|
39
+ initialize_engines
40
+ set_app_load_paths(config)
41
+ set_nested_plugin_load_paths(config)
42
+ yield config if block_given?
43
+ end
44
+
45
+ set_app_view_path
46
+ load_nested_plugins
47
+ set_nested_plugin_view_paths
48
+
49
+ initialize_fixtures unless options[:skip_fixtures]
50
+ end
51
+
52
+ def self.initialize_engines
53
+ require "#{self.plugin_path}/vendor/plugins/engines/boot"
54
+ Engines.use_plugin_asset_directory = false
55
+ end
56
+
57
+ def self.set_app_load_paths(config)
58
+ Dir["#{self.plugin_path}/app/**"].each do |path|
59
+ config.load_paths << path
60
+ end
61
+ end
62
+
63
+ def self.set_nested_plugin_load_paths(config)
64
+ Dir["#{self.plugin_path}/vendor/plugins/*/init.rb"].each do |plugin|
65
+ nested_plugin_dir = File.dirname(plugin)
66
+ Dir["#{nested_plugin_dir}/lib", "#{nested_plugin_dir}/app/**"].each do |path|
67
+ config.load_paths << path
68
+ end
69
+ end
70
+ end
71
+
72
+ def self.set_app_view_path
73
+ view_path = File.join(self.plugin_path, 'app', 'views')
74
+ if File.exist?(view_path)
75
+ ActionController::Base.view_paths.insert(1, view_path)
76
+ end
77
+ end
78
+
79
+ def self.load_nested_plugins
80
+ Dir.glob("#{self.plugin_path}/vendor/plugins/*/init.rb").each do |plugin|
81
+ require plugin
82
+ end
83
+ end
84
+
85
+ def self.set_nested_plugin_view_paths
86
+ Dir.glob("#{self.plugin_path}/vendor/plugins/*/init.rb").each do |plugin|
87
+ nested_plugin_dir = File.dirname(plugin)
88
+ view_path = File.join(nested_plugin_dir, 'app', 'views')
89
+ if File.exist?(view_path)
90
+ ActionController::Base.view_paths.insert(1, view_path)
91
+ end
92
+ end
93
+ end
94
+
95
+ def self.initialize_fixtures
96
+ require 'test_help'
97
+
98
+ Test::Unit::TestCase.fixture_path = PluginTestEnvironment.fixture_path
99
+ $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
100
+
101
+ Test::Unit::TestCase.class_eval do
102
+ def create_fixtures(*table_names)
103
+ if block_given?
104
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
105
+ else
106
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
107
+ end
108
+ end
109
+
110
+ self.use_transactional_fixtures = false
111
+ self.use_instantiated_fixtures = false
112
+ end
113
+ end
114
+
115
+ # initializes the test environment
116
+ #
117
+ # deprecated - use PluginTestEnvironment#initialize_environment instead
118
+ def self.init_env(plugin_dir, use_standard_migration = true)
119
+ puts "This method is deprecated please use PluginTestEnvironment#initialize_environment instead"
120
+ initialize_environment(plugin_dir, :use_standard_migration => use_standard_migration)
121
+ end
122
+
12
123
  def self.fixture_path
13
124
  if File.exists?(PluginTestEnvironment.plugin_path + '/test/fixtures')
14
125
  PluginTestEnvironment.plugin_path + '/test/fixtures'
@@ -22,13 +133,13 @@ class PluginTestEnvironment
22
133
  end
23
134
 
24
135
  def self.plugin_migration
25
- begin
26
- require "#{PluginTestEnvironment.plugin_path}/test/migration"
136
+ custom_migration = "#{PluginTestEnvironment.plugin_path}/test/migration.rb"
137
+ if File.exists?(custom_migration)
138
+ require custom_migration
27
139
  Migration.up
28
- rescue LoadError
29
140
  end
30
- end
31
-
141
+ end
142
+
32
143
  class Migration < ActiveRecord::Migration
33
144
  def self.setup(&block)
34
145
  self.class.send(:define_method, :up, &block)
data/lib/silent_logger.rb CHANGED
@@ -4,6 +4,8 @@ class SilentLogger < Logger
4
4
  super(STDOUT)
5
5
  end
6
6
 
7
+ # adds log message
8
+ # which will get swallowed
7
9
  def add(severity, message = nil, progname = nil, &block)
8
10
  # shhh
9
11
  end
@@ -1,41 +1,11 @@
1
1
  # Specifies gem version of Rails to use when vendor/rails is not present
2
2
  #RAILS_GEM_VERSION = '1.1.6'
3
- RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
3
+ #RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
4
4
 
5
5
  require File.join(File.dirname(__FILE__), 'boot')
6
- #require 'plugin_dependencies'
7
-
8
- Rails::Initializer.run do |config|
9
- config.logger = SilentLogger.new
10
- config.log_level = :debug
11
-
12
- config.cache_classes = false
13
- config.whiny_nils = true
14
- #config.breakpoint_server = true
15
- config.load_paths << "#{File.dirname(__FILE__)}/../../../lib/"
16
- end
17
6
 
18
7
  Dependencies.log_activity = false
19
8
 
20
- require 'test_help'
21
-
22
-
23
- Test::Unit::TestCase.fixture_path = PluginTestEnvironment.fixture_path
24
- $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
25
-
26
- class Test::Unit::TestCase #:nodoc:
27
- def create_fixtures(*table_names)
28
- if block_given?
29
- Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
30
- else
31
- Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
32
- end
33
- end
34
-
35
- self.use_transactional_fixtures = false
36
- self.use_instantiated_fixtures = false
37
- end
38
-
39
9
  # Load the testing framework
40
10
  silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
41
11
 
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.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Volkmer
@@ -9,7 +9,7 @@ autorequire: active_record
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-18 00:00:00 -07:00
12
+ date: 2008-11-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,15 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.15.3
23
23
  version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: sqlite3-ruby
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.2.1
32
+ version:
24
33
  description:
25
34
  email: hvolkmer@imedo.de
26
35
  executables: []
@@ -30,30 +39,30 @@ extensions: []
30
39
  extra_rdoc_files:
31
40
  - README.rdoc
32
41
  files:
33
- - lib/silent_logger.rb
34
42
  - lib/dry_plugin_test_helper.rb
35
43
  - lib/plugin_test_environment.rb
36
- - rails_root/db
37
- - rails_root/db/migrate
38
- - rails_root/db/migrate/001_create_environment.rb
44
+ - lib/silent_logger.rb
39
45
  - rails_root/app
40
46
  - rails_root/app/controllers
41
47
  - rails_root/app/controllers/application.rb
42
48
  - rails_root/app/models
43
- - rails_root/app/models/author.rb
44
- - rails_root/app/models/user.rb
45
49
  - rails_root/app/models/article.rb
50
+ - rails_root/app/models/author.rb
46
51
  - rails_root/app/models/comment.rb
52
+ - rails_root/app/models/user.rb
47
53
  - rails_root/config
48
- - rails_root/config/routes.rb
49
- - rails_root/config/environments
50
- - rails_root/config/environments/sqlite3.rb
51
- - rails_root/config/environments/sqlite.rb
52
- - rails_root/config/environments/postgresql.rb
53
- - rails_root/config/environments/mysql.rb
54
+ - rails_root/config/boot.rb
54
55
  - rails_root/config/database.yml
55
56
  - rails_root/config/environment.rb
56
- - rails_root/config/boot.rb
57
+ - rails_root/config/environments
58
+ - rails_root/config/environments/mysql.rb
59
+ - rails_root/config/environments/postgresql.rb
60
+ - rails_root/config/environments/sqlite.rb
61
+ - rails_root/config/environments/sqlite3.rb
62
+ - rails_root/config/routes.rb
63
+ - rails_root/db
64
+ - rails_root/db/migrate
65
+ - rails_root/db/migrate/001_create_environment.rb
57
66
  - rails_root/script
58
67
  - rails_root/script/console
59
68
  - rails_root/vendor
@@ -84,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
93
  requirements: []
85
94
 
86
95
  rubyforge_project:
87
- rubygems_version: 1.0.1
96
+ rubygems_version: 1.2.0
88
97
  signing_key:
89
98
  specification_version: 2
90
99
  summary: Providing dry standard test environment for Ruby on Rails plugins