pluginaweek / plugin_test_helper

Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application

plugin_test_helper / test / functional / plugin_test_controller_generator_test.rb
100644 26 lines (20 sloc) 0.9 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
 
class PluginTestControllerGeneratorTest < Test::Unit::TestCase
  def setup
    setup_app('empty')
    
    require 'rails_generator'
    require 'rails_generator/scripts/generate'
    Rails::Generator::Base.sources << Rails::Generator::PathSource.new(:plugin_test_controller, "#{Rails.root}/../../generators")
    Rails::Generator::Scripts::Generate.new.run(['plugin_test_controller', 'acts_as_foo', 'site', 'index'])
  end
  
  def test_should_create_controller
    assert File.exists?("#{Rails.root}/vendor/plugins/acts_as_foo/test/app_root/app/controllers/site_controller.rb")
  end
  
  def test_should_create_view
    assert File.exists?("#{Rails.root}/vendor/plugins/acts_as_foo/test/app_root/app/views/site/index.html.erb")
  end
  
  def teardown
    teardown_app
    FileUtils.rm_r(Dir.glob('test/app_root/*'))
  end
end