minitest-rails 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -34,7 +34,10 @@ lib/minitest/rails/action_dispatch.rb
34
34
  lib/minitest/rails/action_mailer.rb
35
35
  lib/minitest/rails/action_view.rb
36
36
  lib/minitest/rails/active_support.rb
37
+ lib/minitest/rails/declarative.rb
38
+ lib/minitest/rails/mochaing.rb
37
39
  lib/minitest/rails/tasks/minitest.rake
40
+ lib/minitest/rails/tasks/sub_test_task.rb
38
41
  minitest-rails.gemspec
39
42
  test/test_controller_generator.rb
40
43
  test/test_helper_generator.rb
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = minitest-rails
2
2
 
3
- MiniTest integration for Rails 3.
3
+ MiniTest integration for Rails 3.x
4
4
 
5
5
  == Install
6
6
 
@@ -75,6 +75,10 @@ And add the following to your test helper file:
75
75
 
76
76
  See the <tt>minitest-rails-capybara</tt> project for more information.
77
77
 
78
+ == Incompatibilities
79
+
80
+ Existing tests that call <tt>describe</tt> will not work, since <tt>describe</tt> is used by MiniTest::Spec blocks.
81
+
78
82
  == Get Involved
79
83
 
80
84
  Join the mailing list to get help or offer suggestions.
data/Rakefile CHANGED
@@ -10,8 +10,8 @@ Hoe.plugins.delete :rubyforge
10
10
  Hoe.spec 'minitest-rails' do
11
11
  developer 'Mike Moore', 'mike@blowmage.com'
12
12
 
13
- self.summary = 'MiniTest integration for Rails 3.'
14
- self.description = 'Adds MiniTest as the default testing library in Rails 3.'
13
+ self.summary = 'MiniTest integration for Rails 3.x'
14
+ self.description = 'Adds MiniTest as the default testing library in Rails 3.x'
15
15
  self.urls = ['http://blowmage.com/minitest-rails']
16
16
 
17
17
  self.history_file = "CHANGELOG.rdoc"
@@ -6,6 +6,13 @@ module MiniTest
6
6
  def self.source_root
7
7
  @_minitest_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'mini_test', generator_name, 'templates'))
8
8
  end
9
+
10
+ begin
11
+ # This method doesn't exist in Rails 3.0
12
+ def module_namespacing(&block)
13
+ yield if block_given?
14
+ end
15
+ end unless respond_to?(:module_namespacing)
9
16
  end
10
17
  end
11
18
  end
@@ -3,7 +3,7 @@ require "minitest/unit"
3
3
 
4
4
  module MiniTest
5
5
  module Rails
6
- VERSION = "0.1"
6
+ VERSION = "0.1.1"
7
7
  class Railtie < ::Rails::Railtie
8
8
  if ::Rails.version.to_f >= 3.1
9
9
  config.app_generators.integration_tool :mini_test
@@ -2,10 +2,10 @@ require 'minitest/spec'
2
2
  require 'active_support/testing/setup_and_teardown'
3
3
  require 'active_support/testing/assertions'
4
4
  require 'active_support/testing/deprecation'
5
- require 'active_support/testing/declarative'
5
+ require 'minitest/rails/declarative'
6
6
  require 'active_support/testing/pending'
7
7
  require 'active_support/testing/isolation'
8
- require 'active_support/testing/mochaing'
8
+ require 'minitest/rails/mochaing'
9
9
  require 'active_support/core_ext/kernel/reporting'
10
10
 
11
11
  module MiniTest
@@ -42,15 +42,11 @@ module MiniTest
42
42
  yield if $tags[tag]
43
43
  end
44
44
 
45
- def describe(*args, &block)
46
- Kernel.describe(args, block)
47
- end
48
-
49
45
  include ::ActiveSupport::Testing::SetupAndTeardown
50
46
  include ::ActiveSupport::Testing::Assertions
51
47
  include ::ActiveSupport::Testing::Deprecation
52
48
  include ::ActiveSupport::Testing::Pending
53
- extend ::ActiveSupport::Testing::Declarative
49
+ extend Testing::Declarative
54
50
 
55
51
  # test/unit backwards compatibility methods
56
52
  alias :assert_raise :assert_raises
@@ -0,0 +1,27 @@
1
+ module MiniTest
2
+ module Rails
3
+ module ActiveSupport
4
+ module Testing
5
+ module Declarative
6
+
7
+ # test "verify something" do
8
+ # ...
9
+ # end
10
+ def test(name, &block)
11
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
12
+ defined = instance_method(test_name) rescue false
13
+ raise "#{test_name} is already defined in #{self}" if defined
14
+ if block_given?
15
+ define_method(test_name, &block)
16
+ else
17
+ define_method(test_name) do
18
+ flunk "No implementation provided for #{name}"
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ begin
2
+ require 'active_support/testing/mochaing'
3
+ rescue LoadError
4
+ begin
5
+ silence_warnings { require 'mocha' }
6
+ rescue LoadError
7
+ # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
8
+ Object.const_set :Mocha, Module.new
9
+ Mocha.const_set :ExpectationError, Class.new(StandardError)
10
+ end
11
+ end
@@ -1,32 +1,61 @@
1
1
  require 'rake/testtask'
2
- require 'rails/test_unit/sub_test_task'
2
+ require 'minitest/rails/tasks/sub_test_task'
3
3
 
4
- TASKS = %w(models controllers helpers mailers acceptance) #views
5
- MINITEST_TASKS = TASKS.map { |sub| "minitest:#{sub}" }
4
+ # The default tests to run, update this list to change behavior
5
+ MINITEST_TASKS = %w(models helpers controllers mailers acceptance) #views
6
+
7
+ def all_directories_under_test
8
+ Dir['test/*/'].map {|dir| /test\/(.+?)\//.match(dir)[1] }
9
+ end
10
+
11
+ def all_minitest_directories
12
+ (MINITEST_TASKS + all_directories_under_test).uniq
13
+ end
6
14
 
7
15
  desc "Runs minitest"
8
16
  task :test do
17
+ # Add to existing task if exists, or create new task otherwise
9
18
  Rake::Task['minitest'].invoke
10
19
  end
11
20
 
21
+ namespace 'test' do
22
+ task :prepare do
23
+ # Define here in case test_unit isn't loaded
24
+ end
25
+ end
26
+
12
27
  desc "Runs #{MINITEST_TASKS.join(", ")} together"
13
28
  task :minitest do
14
- Rake::Task['minitest:run'].invoke
29
+ Rake::Task['minitest:default'].invoke
15
30
  end
16
31
 
17
32
  namespace 'minitest' do
18
33
 
19
- task :prepare do
20
- # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
34
+ # Only run the default tasks defined in MINITEST_TASKS
35
+ task :default do
36
+ errors = MINITEST_TASKS.collect do |task|
37
+ begin
38
+ Rake::Task["minitest:#{task}"].invoke
39
+ nil
40
+ rescue => e
41
+ { :task => "minitest:#{task}", :exception => e }
42
+ end
43
+ end.compact
44
+
45
+ if errors.any?
46
+ puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
47
+ abort
48
+ end
21
49
  end
22
50
 
23
- task :run do
24
- errors = MINITEST_TASKS.collect do |task|
51
+ # Run all tests in all the test directories
52
+ task :all do
53
+ errors = all_minitest_directories.collect do |task|
25
54
  begin
26
- Rake::Task[task].invoke
55
+ Rake::Task["minitest:#{task}"].invoke
27
56
  nil
28
57
  rescue => e
29
- { :task => task, :exception => e }
58
+ { :task => "minitest:#{task}", :exception => e }
30
59
  end
31
60
  end.compact
32
61
 
@@ -36,10 +65,10 @@ namespace 'minitest' do
36
65
  end
37
66
  end
38
67
 
39
- TASKS.each do |sub|
40
- Rails::SubTestTask.new(sub => 'minitest:prepare') do |t|
68
+ all_minitest_directories.each do |task|
69
+ MiniTest::Rails::Tasks::SubTestTask.new(task => 'test:prepare') do |t|
41
70
  t.libs.push 'test'
42
- t.pattern = "test/#{sub}/**/*_test.rb"
71
+ t.pattern = "test/#{task}/**/*_test.rb"
43
72
  end
44
73
  end
45
74
 
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+
3
+ module MiniTest
4
+ module Rails
5
+ module Tasks
6
+ # Silence the default description to cut down on `rake -T` noise.
7
+ class SubTestTask < Rake::TestTask
8
+ def desc(string)
9
+ # Ignore the description.
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,21 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "minitest-rails"
5
- s.version = "0.1.20120709115419"
5
+ s.version = "0.1.1.20120717012609"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mike Moore"]
9
- s.date = "2012-07-09"
10
- s.description = "Adds MiniTest as the default testing library in Rails 3."
9
+ s.date = "2012-07-17"
10
+ s.description = "Adds MiniTest as the default testing library in Rails 3.x"
11
11
  s.email = ["mike@blowmage.com"]
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "Manifest.txt", "README.rdoc"]
13
- s.files = [".autotest", ".gemtest", "CHANGELOG.rdoc", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "lib/generators/mini_test.rb", "lib/generators/mini_test/controller/controller_generator.rb", "lib/generators/mini_test/controller/templates/controller_spec.rb", "lib/generators/mini_test/controller/templates/controller_test.rb", "lib/generators/mini_test/helper/helper_generator.rb", "lib/generators/mini_test/helper/templates/helper_spec.rb", "lib/generators/mini_test/helper/templates/helper_test.rb", "lib/generators/mini_test/install/install_generator.rb", "lib/generators/mini_test/install/templates/test/minitest_helper.rb", "lib/generators/mini_test/integration/integration_generator.rb", "lib/generators/mini_test/integration/templates/integration_spec.rb", "lib/generators/mini_test/integration/templates/integration_test.rb", "lib/generators/mini_test/mailer/mailer_generator.rb", "lib/generators/mini_test/mailer/templates/mailer_spec.rb", "lib/generators/mini_test/mailer/templates/mailer_test.rb", "lib/generators/mini_test/model/model_generator.rb", "lib/generators/mini_test/model/templates/fixtures.yml", "lib/generators/mini_test/model/templates/model_spec.rb", "lib/generators/mini_test/model/templates/model_test.rb", "lib/generators/mini_test/scaffold/scaffold_generator.rb", "lib/generators/mini_test/scaffold/templates/controller_spec.rb", "lib/generators/mini_test/scaffold/templates/controller_test.rb", "lib/minitest-rails.rb", "lib/minitest/rails.rb", "lib/minitest/rails/action_controller.rb", "lib/minitest/rails/action_dispatch.rb", "lib/minitest/rails/action_mailer.rb", "lib/minitest/rails/action_view.rb", "lib/minitest/rails/active_support.rb", "lib/minitest/rails/tasks/minitest.rake", "minitest-rails.gemspec", "test/test_controller_generator.rb", "test/test_helper_generator.rb", "test/test_install_generator.rb", "test/test_mailer_generator.rb", "test/test_minitest.rb", "test/test_model_generator.rb", "test/test_scaffold_generator.rb"]
13
+ s.files = [".autotest", ".gemtest", "CHANGELOG.rdoc", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "lib/generators/mini_test.rb", "lib/generators/mini_test/controller/controller_generator.rb", "lib/generators/mini_test/controller/templates/controller_spec.rb", "lib/generators/mini_test/controller/templates/controller_test.rb", "lib/generators/mini_test/helper/helper_generator.rb", "lib/generators/mini_test/helper/templates/helper_spec.rb", "lib/generators/mini_test/helper/templates/helper_test.rb", "lib/generators/mini_test/install/install_generator.rb", "lib/generators/mini_test/install/templates/test/minitest_helper.rb", "lib/generators/mini_test/integration/integration_generator.rb", "lib/generators/mini_test/integration/templates/integration_spec.rb", "lib/generators/mini_test/integration/templates/integration_test.rb", "lib/generators/mini_test/mailer/mailer_generator.rb", "lib/generators/mini_test/mailer/templates/mailer_spec.rb", "lib/generators/mini_test/mailer/templates/mailer_test.rb", "lib/generators/mini_test/model/model_generator.rb", "lib/generators/mini_test/model/templates/fixtures.yml", "lib/generators/mini_test/model/templates/model_spec.rb", "lib/generators/mini_test/model/templates/model_test.rb", "lib/generators/mini_test/scaffold/scaffold_generator.rb", "lib/generators/mini_test/scaffold/templates/controller_spec.rb", "lib/generators/mini_test/scaffold/templates/controller_test.rb", "lib/minitest-rails.rb", "lib/minitest/rails.rb", "lib/minitest/rails/action_controller.rb", "lib/minitest/rails/action_dispatch.rb", "lib/minitest/rails/action_mailer.rb", "lib/minitest/rails/action_view.rb", "lib/minitest/rails/active_support.rb", "lib/minitest/rails/declarative.rb", "lib/minitest/rails/mochaing.rb", "lib/minitest/rails/tasks/minitest.rake", "lib/minitest/rails/tasks/sub_test_task.rb", "minitest-rails.gemspec", "test/test_controller_generator.rb", "test/test_helper_generator.rb", "test/test_install_generator.rb", "test/test_mailer_generator.rb", "test/test_minitest.rb", "test/test_model_generator.rb", "test/test_scaffold_generator.rb"]
14
14
  s.homepage = "http://blowmage.com/minitest-rails"
15
15
  s.rdoc_options = ["--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "minitest-rails"
18
18
  s.rubygems_version = "1.8.24"
19
- s.summary = "MiniTest integration for Rails 3."
19
+ s.summary = "MiniTest integration for Rails 3.x"
20
20
  s.test_files = ["test/test_controller_generator.rb", "test/test_helper_generator.rb", "test/test_install_generator.rb", "test/test_mailer_generator.rb", "test/test_minitest.rb", "test/test_model_generator.rb", "test/test_scaffold_generator.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
@@ -18,7 +18,7 @@ class TestHelperGenerator < MiniTest::Unit::TestCase
18
18
  assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
19
19
  assert File.exists? "test/helpers/user_helper_test.rb"
20
20
  contents = open("test/helpers/user_helper_test.rb").read
21
- assert_match(/class UserHelperTest < MiniTest::Unit::TestCase/m, contents)
21
+ assert_match(/class UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
22
22
  ensure
23
23
  # TODO: Don"t write the files
24
24
  # I agree, it would be better to mock the file getting written
@@ -32,7 +32,7 @@ class TestHelperGenerator < MiniTest::Unit::TestCase
32
32
  assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
33
33
  assert File.exists? "test/helpers/admin/user_helper_test.rb"
34
34
  contents = open("test/helpers/admin/user_helper_test.rb").read
35
- assert_match(/class Admin::UserHelperTest < MiniTest::Unit::TestCase/m, contents)
35
+ assert_match(/class Admin::UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
36
36
  ensure
37
37
  FileUtils.rm_r "test/helpers"
38
38
  end
@@ -49,7 +49,7 @@ class TestHelperGenerator < MiniTest::Unit::TestCase
49
49
  FileUtils.rm_r "test/helpers"
50
50
  end
51
51
 
52
- def test_helper_generator_spec
52
+ def test_namespaced_helper_generator_spec
53
53
  text = capture(:stdout) do
54
54
  MiniTest::Generators::HelperGenerator.start ["admin/user", "--spec"]
55
55
  end
@@ -44,16 +44,18 @@ class TestModelGenerator < MiniTest::Unit::TestCase
44
44
  text = capture(:stdout) do
45
45
  MiniTest::Generators::ModelGenerator.start ["user"]
46
46
  end
47
+ assert_match(/create test\/fixtures\/users.yml/m, text)
47
48
  assert File.exists? "test/fixtures/users.yml"
48
49
  ensure
49
50
  FileUtils.rm_r "test/models"
50
51
  FileUtils.rm_r "test/fixtures"
51
52
  end
52
53
 
53
- def test_model_generator_no_fixture
54
+ def test_model_generator_skip_fixture
54
55
  text = capture(:stdout) do
55
56
  MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
56
57
  end
58
+ refute_match(/create test\/fixtures\/users.yml/m, text)
57
59
  refute File.exists? "test/fixtures/users.yml"
58
60
  ensure
59
61
  FileUtils.rm_r "test/models"
@@ -15,10 +15,10 @@ class TestScaffoldGenerator < MiniTest::Unit::TestCase
15
15
  text = capture(:stdout) do
16
16
  MiniTest::Generators::ScaffoldGenerator.start ["user"]
17
17
  end
18
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
19
- assert File.exists? "test/controllers/user_controller_test.rb"
20
- contents = open("test/controllers/user_controller_test.rb").read
21
- assert_match(/class UserControllerTest/m, contents)
18
+ assert_match(/create test\/controllers\/users_controller_test.rb/m, text)
19
+ assert File.exists? "test/controllers/users_controller_test.rb"
20
+ contents = open("test/controllers/users_controller_test.rb").read
21
+ assert_match(/class UsersControllerTest/m, contents)
22
22
  ensure
23
23
  # TODO: Don"t write the files
24
24
  # I agree, it would be better to mock the file getting written
@@ -29,10 +29,10 @@ class TestScaffoldGenerator < MiniTest::Unit::TestCase
29
29
  text = capture(:stdout) do
30
30
  MiniTest::Generators::ScaffoldGenerator.start ["user", "--spec"]
31
31
  end
32
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
33
- assert File.exists? "test/controllers/user_controller_test.rb"
34
- contents = open("test/controllers/user_controller_test.rb").read
35
- assert_match(/describe UserController do/m, contents)
32
+ assert_match(/create test\/controllers\/users_controller_test.rb/m, text)
33
+ assert File.exists? "test/controllers/users_controller_test.rb"
34
+ contents = open("test/controllers/users_controller_test.rb").read
35
+ assert_match(/describe UsersController do/m, contents)
36
36
  ensure
37
37
  FileUtils.rm_r "test/controllers"
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -75,7 +75,7 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3.0'
78
- description: Adds MiniTest as the default testing library in Rails 3.
78
+ description: Adds MiniTest as the default testing library in Rails 3.x
79
79
  email:
80
80
  - mike@blowmage.com
81
81
  executables: []
@@ -121,7 +121,10 @@ files:
121
121
  - lib/minitest/rails/action_mailer.rb
122
122
  - lib/minitest/rails/action_view.rb
123
123
  - lib/minitest/rails/active_support.rb
124
+ - lib/minitest/rails/declarative.rb
125
+ - lib/minitest/rails/mochaing.rb
124
126
  - lib/minitest/rails/tasks/minitest.rake
127
+ - lib/minitest/rails/tasks/sub_test_task.rb
125
128
  - minitest-rails.gemspec
126
129
  - test/test_controller_generator.rb
127
130
  - test/test_helper_generator.rb
@@ -155,7 +158,7 @@ rubyforge_project: minitest-rails
155
158
  rubygems_version: 1.8.24
156
159
  signing_key:
157
160
  specification_version: 3
158
- summary: MiniTest integration for Rails 3.
161
+ summary: MiniTest integration for Rails 3.x
159
162
  test_files:
160
163
  - test/test_controller_generator.rb
161
164
  - test/test_helper_generator.rb