migration_test_helper 1.2.1 → 1.3.1

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/Rakefile CHANGED
@@ -16,7 +16,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
16
16
  rdoc.rdoc_files.include('lib/**/*.rb')
17
17
  end
18
18
 
19
- GEM_VERSION = '1.2.1'
19
+ GEM_VERSION = '1.3.1'
20
20
 
21
21
  Hoe.new('migration_test_helper',GEM_VERSION) do |p|
22
22
  p.author = "Micah Alles"
@@ -1,4 +1,17 @@
1
- # desc "Explaining what the task does"
2
- # task :migration_test_helper do
3
- # # Task goes here
4
- # end
1
+
2
+ namespace :test do
3
+
4
+ Rake::TestTask.new(:migrations => "db:test:prepare") do |t|
5
+ t.libs << "test"
6
+ t.pattern = 'test/migration/**/*_test.rb'
7
+ t.verbose = true
8
+ end
9
+ Rake::Task['test:migrations'].comment = "Run the migration tests in test/migration"
10
+
11
+ task :migration => 'test:migration'
12
+ end
13
+
14
+ task :test do
15
+ Rake::Task['test:migration'].invoke rescue got_error = true
16
+ raise "Test failures" if got_error
17
+ end
@@ -0,0 +1,17 @@
1
+ class Test::Unit::TestCase
2
+
3
+ def self.running_in_foundry
4
+ File.expand_path(File.dirname(__FILE__)) =~ /\/rails_plugin_foundry\//
5
+ end
6
+
7
+ def running_in_foundry
8
+ self.class.running_in_foundry
9
+ end
10
+
11
+ def self.in_foundry_should(behave,&block)
12
+ should(behave,&block) if running_in_foundry
13
+ end
14
+
15
+ def test_PLACEHOLDER; end
16
+
17
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/foundry_only_helper')
3
+
4
+ class FullMigrationTestGeneratorTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ return unless running_in_foundry
8
+ rm_migration_test_path
9
+ end
10
+
11
+ def teardown
12
+ return unless running_in_foundry
13
+ rm_migration_test_path
14
+ end
15
+
16
+
17
+ #
18
+ # HELPERS
19
+ #
20
+
21
+ def migration_test_file
22
+ migration_test_path + "/full_migration_test.rb"
23
+ end
24
+
25
+ def run_generator
26
+ run_in_rails_root 'script/generate full_migration_test'
27
+ end
28
+
29
+ #
30
+ # TESTS
31
+ #
32
+
33
+ in_foundry_should "generate full migration test" do
34
+ run_generator
35
+ assert File.exists?(migration_test_file), "No test file made: #{migration_test_file}"
36
+ generated_code = File.read(migration_test_file)
37
+ source_code = File.read(plugin_path('generators/full_migration_test/templates/full_migration_test.rb'))
38
+ assert_equal source_code, generated_code, "Wrong code generated in #{migration_test_file}"
39
+ end
40
+
41
+ in_foundry_should "create a test that fails in expected fashion" do
42
+ run_generator
43
+ cd RAILS_ROOT do
44
+ @output = `ruby test/migration/full_migration_test.rb`
45
+ end
46
+
47
+ check_output '1 tests, 1 assertions, 1 failures, 0 errors'
48
+ check_output 'implement me'
49
+ check_output 'test_full_migration(FullMigrationTest)'
50
+ end
51
+
52
+ end
@@ -1,6 +1,7 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
3
3
  require 'logger'
4
+ require 'fileutils'
4
5
  require 'test_help'
5
6
 
6
7
  plugin_path = RAILS_ROOT + "/vendor/plugins/migration_test_helper"
@@ -16,6 +17,7 @@ Test::Unit::TestCase.fixture_path = plugin_path + "/test/fixtures/"
16
17
  $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
17
18
 
18
19
  class Test::Unit::TestCase
20
+ include FileUtils
19
21
  def plugin_path(path)
20
22
  File.expand_path(File.dirname(__FILE__) + '/../' + path)
21
23
  end
@@ -26,4 +28,48 @@ class Test::Unit::TestCase
26
28
  load(schema_file) if File.exist?(schema_file)
27
29
  end
28
30
  end
31
+
32
+ def migration_test_path
33
+ File.expand_path(RAILS_ROOT + "/test/migration")
34
+ end
35
+
36
+ def run_in_rails_root(command)
37
+ cd RAILS_ROOT do
38
+ @output = `#{command}`
39
+ end
40
+ end
41
+
42
+ def check_output(string_or_regexp)
43
+ assert_not_nil @output, "No output collected"
44
+ case string_or_regexp
45
+ when String
46
+ assert_match(/#{Regexp.escape(string_or_regexp)}/, @output)
47
+ when Regexp
48
+ assert_match(string_or_regexp, @output)
49
+ else
50
+ raise "Can't check output using oddball object #{string_or_regexp.inspect}"
51
+ end
52
+ end
53
+
54
+ def rm_migration_test_path
55
+ rm_rf migration_test_path
56
+ end
57
+
58
+ def self.should(behave,&block)
59
+ return unless running_in_foundry
60
+ @context ||= nil
61
+ @context_setup ||= nil
62
+ context_string = @context.nil? ? '' : @context + ' '
63
+ mname = "test #{context_string}should #{behave}"
64
+ context_setup = @context_setup
65
+ if block_given?
66
+ define_method(mname) do
67
+ instance_eval(&context_setup) unless context_setup.nil?
68
+ instance_eval(&block)
69
+ end
70
+ else
71
+ puts ">>> UNIMPLEMENTED CASE: #{name.sub(/Test$/,'')} should #{behave}"
72
+ end
73
+ end
74
+
29
75
  end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/foundry_only_helper')
3
+
4
+ class MigrationTestGeneratorTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ return unless running_in_foundry
8
+ rm_migration_test_path
9
+ rm_migrations
10
+ end
11
+
12
+ def teardown
13
+ return unless running_in_foundry
14
+ rm_migration_test_path
15
+ rm_migrations
16
+ end
17
+
18
+
19
+ #
20
+ # HELPERS
21
+ #
22
+
23
+ def generate_migration(expected_version, name)
24
+ run_in_rails_root "script/generate migration #{name}"
25
+ migration_file = "db/migrate/#{expected_version}_#{name}.rb"
26
+ assert File.exists?(migration_file), "Migration not there: #{migration_file}"
27
+ end
28
+
29
+ def generate_migration_test(version)
30
+ run_in_rails_root "script/generate migration_test #{version}"
31
+
32
+ end
33
+
34
+ def rm_migrations
35
+ rm Dir["db/migrate/*.rb"]
36
+ end
37
+
38
+ #
39
+ # TESTS
40
+ #
41
+
42
+ in_foundry_should "generate a migration test for schema 1" do
43
+ generate_migration '001', 'create_the_dogs_table'
44
+
45
+ generate_migration_test '1'
46
+
47
+ migration_test_file = "test/migration/001_create_the_dogs_table_test.rb"
48
+ assert File.exists?(migration_test_file), "Migration test not there: #{migration_test_file}"
49
+
50
+ run_in_rails_root "ruby #{migration_test_file}"
51
+ check_output 'test_migration_should_create_the_dogs_table(CreateTheDogsTableTest)'
52
+ check_output '1) Failure:'
53
+ check_output 'TODO: setup test data.'
54
+ check_output '1 tests, 1 assertions, 1 failures, 0 errors'
55
+ end
56
+
57
+ in_foundry_should "generate a migration test for schema 2" do
58
+ generate_migration '001', 'create_the_dogs_table'
59
+ generate_migration '002', 'transfer_cats_data'
60
+ generate_migration_test '002'
61
+ migration_test_file = "test/migration/002_transfer_cats_data_test.rb"
62
+ assert File.exists?(migration_test_file), "Migration test not there: #{migration_test_file}"
63
+
64
+ run_in_rails_root "ruby #{migration_test_file}"
65
+ check_output 'test_migration_should_transfer_cats_data(TransferCatsDataTest)'
66
+ check_output '1) Failure:'
67
+ check_output 'TODO: setup test data.'
68
+ check_output '1 tests, 1 assertions, 1 failures, 0 errors'
69
+ end
70
+
71
+ in_foundry_should "fail if no schema version is provided" do
72
+ generate_migration '001', 'create_the_dogs_table'
73
+ generate_migration_test ''
74
+ check_output 'Usage: script/generate migration_test MigrationTestName [options]'
75
+ end
76
+
77
+ in_foundry_should "fail if bad schema version is provided" do
78
+ generate_migration '001', 'create_the_dogs_table'
79
+ generate_migration_test 'oops'
80
+ check_output(/Invalid schema version 'oops'/i)
81
+ end
82
+
83
+ in_foundry_should "fail if schema version does not correspond to existing migration" do
84
+ generate_migration '001', 'create_the_dogs_table'
85
+ generate_migration_test '2'
86
+ check_output "No migration found for schema version 002"
87
+ end
88
+
89
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: migration_test_helper
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.1
7
- date: 2007-02-03 00:00:00 -05:00
6
+ version: 1.3.1
7
+ date: 2007-02-27 00:00:00 -05:00
8
8
  summary: A Rails plugin for testing migrations
9
9
  require_paths:
10
10
  - lib
@@ -25,13 +25,17 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Micah Alles
30
31
  files:
31
32
  - test/config
32
33
  - test/db
34
+ - test/foundry_only_helper.rb
35
+ - test/full_migration_test_generator_test.rb
33
36
  - test/helper.rb
34
37
  - test/log
38
+ - test/migration_test_generator_test.rb
35
39
  - test/migration_test_helper_test.rb
36
40
  - test/config/database.yml
37
41
  - test/db/migrate_bad