minitest-rails 0.1.0.alpha → 0.1.0.alpha2

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.
@@ -37,8 +37,9 @@ This will add the <tt>minitest_helper.rb</tt> file to the <tt>test</tt> director
37
37
  == Usage
38
38
 
39
39
  We aim to expose MiniTest with minimal changes for testing within Rails.
40
- Your test classes will inherit from MiniTest::Rails::Spec (or Model, or Controller, etc) and you can use the MiniTest::Spec DSL.
41
- You can generate test files with the standard model, controller, scaffold, and other generators:
40
+ Your test classes will inherit from MiniTest::Rails::ActiveSupport::TestCase a opposed to ActiveSupport::TestCase.
41
+ You can use the MiniTest::Spec DSL.
42
+ You can generate test files with the standard model, controller, resource, and other generators:
42
43
 
43
44
  rails generate model User
44
45
 
@@ -46,12 +47,18 @@ And you can specify generating the tests using the MiniTest::Spec DSL on any of
46
47
 
47
48
  rails generate model User --spec
48
49
 
49
- And you can specify generating the fixture for a model by providing the <tt>--fixture</tt> option:
50
+ And you can specify not generating the fixture for a model by providing the <tt>--skip-fixture</tt> option:
50
51
 
51
- rails generate model User --fixture
52
+ rails generate model User --skip-fixture
52
53
 
53
54
  You can also set these as defaults by adding the following to the <tt>config/application.rb</tt> file:
54
55
 
55
56
  config.generators do |g|
56
- g.test_framework :mini_test, :spec => true, :fixture => true
57
+ g.test_framework :mini_test, :spec => true, :fixture => false
57
58
  end
59
+
60
+ == Get Involved
61
+
62
+ Join the mailing list to get help or offer suggestions.
63
+
64
+ https://groups.google.com/forum/#!forum/minitest-rails
@@ -10,9 +10,9 @@ module MiniTest
10
10
 
11
11
  def create_test_files
12
12
  if options[:spec]
13
- template "controller_spec.rb", "test/controllers/#{file_name}_controller_test.rb"
13
+ template "controller_spec.rb", File.join("test/controllers", class_path, "#{file_name}_controller_test.rb")
14
14
  else
15
- template "controller_test.rb", "test/controllers/#{file_name}_controller_test.rb"
15
+ template "controller_test.rb", File.join("test/controllers", class_path, "#{file_name}_controller_test.rb")
16
16
  end
17
17
  end
18
18
  end
@@ -9,9 +9,9 @@ module MiniTest
9
9
 
10
10
  def create_test_files
11
11
  if options[:spec]
12
- template "helper_spec.rb", "test/helpers/#{file_name}_helper_test.rb"
12
+ template "helper_spec.rb", File.join("test/helpers", class_path, "#{file_name}_helper_test.rb")
13
13
  else
14
- template "helper_test.rb", "test/helpers/#{file_name}_helper_test.rb"
14
+ template "helper_test.rb", File.join("test/helpers", class_path, "#{file_name}_helper_test.rb")
15
15
  end
16
16
  end
17
17
  end
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>HelperTest < MiniTest::Rails::Helper
4
+ class <%= class_name %>HelperTest < MiniTest::Unit::TestCase
5
5
 
6
6
  def test_sanity
7
7
  flunk "Need real tests"
@@ -7,6 +7,13 @@ require "minitest/rails"
7
7
  # Uncomment if you want awesome colorful output
8
8
  # require "minitest/pride"
9
9
 
10
+ class MiniTest::Rails::ActiveSupport::TestCase
11
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
12
+ fixtures :all
13
+
14
+ # Add more helper methods to be used by all tests here...
15
+ end
16
+
10
17
  # Do you want all existing Rails tests to use MiniTest::Rails?
11
18
  # Comment out the following and either:
12
19
  # A) Change the require on the existing tests to `require "minitest_helper"`
@@ -9,9 +9,9 @@ module MiniTest
9
9
 
10
10
  def create_test_files
11
11
  if options[:spec]
12
- template 'integration_spec.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
12
+ template 'integration_spec.rb', File.join('test/acceptance', class_path, "#{file_name}_test.rb")
13
13
  else
14
- template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
14
+ template 'integration_test.rb', File.join('test/acceptance', class_path, "#{file_name}_test.rb")
15
15
  end
16
16
  end
17
17
  end
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
- # To be handled correctly this spec must end with "Integration Test"
4
- describe "<%= class_name %> Integration Test" do
3
+ # To be handled correctly this spec must end with "Acceptance Test"
4
+ describe "<%= class_name %> Acceptance Test" do
5
5
  # it "must be a real test" do
6
6
  # flunk "Need real tests"
7
7
  # end
@@ -3,8 +3,8 @@ require "generators/mini_test"
3
3
  module MiniTest
4
4
  module Generators
5
5
  class ModelGenerator < Base
6
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
- class_option :fixture, :type => :boolean, :default => false, :desc => "Create fixture file"
6
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
+ class_option :fixture, :type => :boolean, :default => true, :desc => "Create fixture file"
8
8
  class_option :spec, :type => :boolean, :default => false, :desc => "Use MiniTest::Spec DSL"
9
9
 
10
10
  check_class_collision :suffix => "Test"
@@ -12,9 +12,9 @@ module MiniTest
12
12
 
13
13
  def create_test_files
14
14
  if options[:spec]
15
- template "controller_spec.rb", "test/controllers/#{file_name}_controller_test.rb"
15
+ template "controller_spec.rb", File.join("test/controllers", class_path, "#{file_name}_controller_test.rb")
16
16
  else
17
- template "controller_test.rb", "test/controllers/#{file_name}_controller_test.rb"
17
+ template "controller_test.rb", File.join("test/controllers", class_path, "#{file_name}_controller_test.rb")
18
18
  end
19
19
  end
20
20
  end
@@ -3,7 +3,7 @@ require "minitest/unit"
3
3
 
4
4
  module MiniTest
5
5
  module Rails
6
- VERSION = "0.1.0.alpha"
6
+ VERSION = "0.1.0.alpha2"
7
7
  class Railtie < ::Rails::Railtie
8
8
  config.app_generators.integration_tool :mini_test
9
9
  config.app_generators.test_framework :mini_test
@@ -9,8 +9,7 @@ require "minitest/rails/action_dispatch"
9
9
 
10
10
  # Enable turn if it is available
11
11
  begin
12
- require 'turn'
13
- MiniTest::Unit.use_natural_language_case_names = true
12
+ require 'turn/autorun'
14
13
  rescue LoadError
15
14
  end
16
15
 
@@ -23,7 +22,7 @@ if defined?(ActiveRecord::Base)
23
22
  MiniTest::Rails::ActionDispatch::IntegrationTest.fixture_path = MiniTest::Rails::ActiveSupport::TestCase.fixture_path
24
23
 
25
24
  def create_fixtures(*table_names, &block)
26
- Fixtures.create_fixtures(MiniTest::Rails::ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
25
+ ActiveRecord::Fixtures.create_fixtures(MiniTest::Rails::ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
27
26
  end
28
27
  end
29
28
 
@@ -17,5 +17,5 @@ module MiniTest
17
17
  end
18
18
 
19
19
  # Register by name
20
- MiniTest::Spec.register_spec_type(/IntegrationTest$/, MiniTest::Rails::ActionDispatch::IntegrationTest)
21
- MiniTest::Spec.register_spec_type(/Integration Test$/, MiniTest::Rails::ActionDispatch::IntegrationTest)
20
+ MiniTest::Spec.register_spec_type(/AcceptanceTest$/, MiniTest::Rails::ActionDispatch::IntegrationTest)
21
+ MiniTest::Spec.register_spec_type(/Acceptance Test$/, MiniTest::Rails::ActionDispatch::IntegrationTest)
@@ -20,9 +20,17 @@ module MiniTest
20
20
  assert yield, msg
21
21
  end
22
22
 
23
- # Use AS::TestCase for the base class when describing a model
24
- register_spec_type(self) do |desc|
25
- desc < ActiveRecord::Base
23
+ if defined?(ActiveRecord::Base)
24
+ # Use AS::TestCase for the base class when describing a model
25
+ register_spec_type(self) do |desc|
26
+ desc < ActiveRecord::Base
27
+ end
28
+ end
29
+
30
+ # For backward compatibility with Test::Unit
31
+ def build_message(message, template = nil, *args)
32
+ template = template.gsub('<?>', '<%s>')
33
+ message || sprintf(template, *args)
26
34
  end
27
35
 
28
36
  Assertion = ::MiniTest::Assertion
@@ -40,6 +48,10 @@ module MiniTest
40
48
  :sorted
41
49
  end
42
50
 
51
+ def describe(*args, &block)
52
+ Kernel.describe(args, block)
53
+ end
54
+
43
55
  include ::ActiveSupport::Testing::SetupAndTeardown
44
56
  include ::ActiveSupport::Testing::Assertions
45
57
  include ::ActiveSupport::Testing::Deprecation
@@ -1,29 +1,42 @@
1
1
  require 'rake/testtask'
2
+ require 'rails/test_unit/sub_test_task'
2
3
 
3
- MINITEST_TASKS = %w(models controllers helpers mailers integration) #views
4
+ TASKS = %w(models controllers helpers mailers acceptance) #views
5
+ MINITEST_TASKS = TASKS.map { |sub| "minitest:#{sub}" }
4
6
 
5
- desc 'Runs all tests'
7
+ desc "Runs minitest"
6
8
  task :test do
7
- errors = MINITEST_TASKS.collect do |task|
8
- begin
9
- Rake::Task["test:#{task}"].invoke
10
- nil
11
- rescue => e
12
- task
13
- end
14
- end.compact
15
- abort "Errors running #{errors * ', '}!" if errors.any?
9
+ Rake::Task['minitest'].invoke
10
+ end
11
+
12
+ desc "Runs #{MINITEST_TASKS.join(", ")} together"
13
+ task :minitest do
14
+ Rake::Task['minitest:run'].invoke
16
15
  end
17
16
 
18
- namespace :test do
19
- task :prepare do
20
- # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
17
+ namespace 'minitest' do
18
+
19
+ task :run do
20
+ errors = MINITEST_TASKS.collect do |task|
21
+ begin
22
+ Rake::Task[task].invoke
23
+ nil
24
+ rescue => e
25
+ { :task => task, :exception => e }
26
+ end
27
+ end.compact
28
+
29
+ if errors.any?
30
+ puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
31
+ abort
32
+ end
21
33
  end
22
34
 
23
- MINITEST_TASKS.each do |sub|
24
- Rake::TestTask.new(sub => 'test:prepare') do |t|
25
- t.libs << 'test'
35
+ TASKS.each do |sub|
36
+ Rails::SubTestTask.new(sub => 'test:prepare') do |t|
37
+ t.libs.push 'test'
26
38
  t.pattern = "test/#{sub}/**/*_test.rb"
27
39
  end
28
40
  end
41
+
29
42
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "minitest-rails"
5
- s.version = "0.1.0.alpha.20120525143907"
5
+ s.version = "0.1.0.alpha2.20120706021507"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mike Moore"]
9
- s.date = "2012-05-25"
9
+ s.date = "2012-07-06"
10
10
  s.description = "Adds MiniTest as the default testing library in Rails 3."
11
11
  s.email = ["mike@blowmage.com"]
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "Manifest.txt", "README.rdoc"]
@@ -25,6 +25,18 @@ class TestControllerGenerator < MiniTest::Unit::TestCase
25
25
  FileUtils.rm_r "test/controllers"
26
26
  end
27
27
 
28
+ def test_namespaced_controller_generator
29
+ text = capture(:stdout) do
30
+ MiniTest::Generators::ControllerGenerator.start ["admin/user"]
31
+ end
32
+ assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
33
+ assert File.exists? "test/controllers/admin/user_controller_test.rb"
34
+ contents = open("test/controllers/admin/user_controller_test.rb").read
35
+ assert_match(/class Admin::UserControllerTest/m, contents)
36
+ ensure
37
+ FileUtils.rm_r "test/controllers"
38
+ end
39
+
28
40
  def test_controller_generator_spec
29
41
  text = capture(:stdout) do
30
42
  MiniTest::Generators::ControllerGenerator.start ["user", "--spec"]
@@ -36,4 +48,17 @@ class TestControllerGenerator < MiniTest::Unit::TestCase
36
48
  ensure
37
49
  FileUtils.rm_r "test/controllers"
38
50
  end
51
+
52
+ def test_namespaced_controller_generator_spec
53
+ text = capture(:stdout) do
54
+ MiniTest::Generators::ControllerGenerator.start ["admin/user", "--spec"]
55
+ end
56
+ assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
57
+ assert File.exists? "test/controllers/admin/user_controller_test.rb"
58
+ contents = open("test/controllers/admin/user_controller_test.rb").read
59
+ assert_match(/describe Admin::UserController do/m, contents)
60
+ ensure
61
+ FileUtils.rm_r "test/controllers"
62
+ end
63
+
39
64
  end
@@ -18,13 +18,25 @@ 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::Rails::Helper/m, contents)
21
+ assert_match(/class UserHelperTest < MiniTest::Unit::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
25
25
  FileUtils.rm_r "test/helpers"
26
26
  end
27
27
 
28
+ def test_namespaced_helper_generator
29
+ text = capture(:stdout) do
30
+ MiniTest::Generators::HelperGenerator.start ["admin/user"]
31
+ end
32
+ assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
33
+ assert File.exists? "test/helpers/admin/user_helper_test.rb"
34
+ contents = open("test/helpers/admin/user_helper_test.rb").read
35
+ assert_match(/class Admin::UserHelperTest < MiniTest::Unit::TestCase/m, contents)
36
+ ensure
37
+ FileUtils.rm_r "test/helpers"
38
+ end
39
+
28
40
  def test_helper_generator_spec
29
41
  text = capture(:stdout) do
30
42
  MiniTest::Generators::HelperGenerator.start ["user", "--spec"]
@@ -36,4 +48,17 @@ class TestHelperGenerator < MiniTest::Unit::TestCase
36
48
  ensure
37
49
  FileUtils.rm_r "test/helpers"
38
50
  end
51
+
52
+ def test_helper_generator_spec
53
+ text = capture(:stdout) do
54
+ MiniTest::Generators::HelperGenerator.start ["admin/user", "--spec"]
55
+ end
56
+ assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
57
+ assert File.exists? "test/helpers/admin/user_helper_test.rb"
58
+ contents = open("test/helpers/admin/user_helper_test.rb").read
59
+ assert_match(/describe Admin::UserHelper do/m, contents)
60
+ ensure
61
+ FileUtils.rm_r "test/helpers"
62
+ end
63
+
39
64
  end
@@ -23,6 +23,7 @@ class TestModelGenerator < MiniTest::Unit::TestCase
23
23
  # TODO: Don"t write the files
24
24
  # I agree, it would be better to mock the file getting written
25
25
  FileUtils.rm_r "test/models"
26
+ FileUtils.rm_r "test/fixtures"
26
27
  end
27
28
 
28
29
  def test_model_generator_spec
@@ -31,8 +32,29 @@ class TestModelGenerator < MiniTest::Unit::TestCase
31
32
  end
32
33
  assert_match(/create test\/models\/user_test.rb/m, text)
33
34
  assert File.exists? "test/models/user_test.rb"
35
+ assert File.exists? "test/fixtures/users.yml"
34
36
  contents = open("test/models/user_test.rb").read
35
37
  assert_match(/describe User do/m, contents)
38
+ ensure
39
+ FileUtils.rm_r "test/models"
40
+ FileUtils.rm_r "test/fixtures"
41
+ end
42
+
43
+ def test_model_generator_fixture
44
+ text = capture(:stdout) do
45
+ MiniTest::Generators::ModelGenerator.start ["user"]
46
+ end
47
+ assert File.exists? "test/fixtures/users.yml"
48
+ ensure
49
+ FileUtils.rm_r "test/models"
50
+ FileUtils.rm_r "test/fixtures"
51
+ end
52
+
53
+ def test_model_generator_no_fixture
54
+ text = capture(:stdout) do
55
+ MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
56
+ end
57
+ refute File.exists? "test/fixtures/users.yml"
36
58
  ensure
37
59
  FileUtils.rm_r "test/models"
38
60
  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.0.alpha
4
+ version: 0.1.0.alpha2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70157709898300 !ruby/object:Gem::Requirement
16
+ requirement: &70311455892940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70157709898300
24
+ version_requirements: *70311455892940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70157709897860 !ruby/object:Gem::Requirement
27
+ requirement: &70311455892500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70157709897860
35
+ version_requirements: *70311455892500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &70157709897420 !ruby/object:Gem::Requirement
38
+ requirement: &70311455892060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.10'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70157709897420
46
+ version_requirements: *70311455892060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &70157709896980 !ruby/object:Gem::Requirement
49
+ requirement: &70311455891620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70157709896980
57
+ version_requirements: *70311455891620
58
58
  description: Adds MiniTest as the default testing library in Rails 3.
59
59
  email:
60
60
  - mike@blowmage.com