minitest-spec-rails 3.0.7 → 3.1.0

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.
Files changed (65) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG.md +46 -0
  4. data/Gemfile +3 -1
  5. data/Guardfile +7 -0
  6. data/README.md +195 -41
  7. data/Rakefile +4 -6
  8. data/lib/minitest-spec-rails.rb +8 -2
  9. data/lib/minitest-spec-rails/dsl.rb +52 -0
  10. data/lib/minitest-spec-rails/init/action_controller.rb +24 -0
  11. data/lib/minitest-spec-rails/init/action_dispatch.rb +17 -0
  12. data/lib/minitest-spec-rails/init/action_mailer.rb +26 -0
  13. data/lib/minitest-spec-rails/init/action_view.rb +38 -0
  14. data/lib/minitest-spec-rails/init/active_support.rb +28 -0
  15. data/lib/minitest-spec-rails/init/mini_shoulda.rb +47 -0
  16. data/lib/minitest-spec-rails/rails.rb +7 -0
  17. data/lib/minitest-spec-rails/version.rb +1 -1
  18. data/minitest-spec-rails.gemspec +21 -16
  19. data/test/cases/action_controller_test.rb +41 -0
  20. data/test/cases/action_dispatch_test.rb +48 -0
  21. data/test/cases/action_mailer_test.rb +42 -0
  22. data/test/cases/action_view_test.rb +44 -0
  23. data/test/cases/active_support_test.rb +43 -0
  24. data/test/cases/mini_shoulda_test.rb +38 -0
  25. data/test/dummy_app/app/controllers/application_controller.rb +7 -0
  26. data/test/dummy_app/app/controllers/users_controller.rb +8 -0
  27. data/test/dummy_app/app/helpers/application_helper.rb +2 -0
  28. data/test/dummy_app/app/helpers/foos_helper.rb +5 -0
  29. data/test/dummy_app/app/helpers/users_helper.rb +9 -0
  30. data/test/dummy_app/app/models/post.rb +6 -0
  31. data/test/dummy_app/app/models/user.rb +6 -0
  32. data/test/dummy_app/app/models/user_mailer.rb +10 -0
  33. data/test/dummy_app/app/views/user_mailer/welcome.erb +1 -0
  34. data/test/dummy_app/app/views/users/index.rhtml +2 -0
  35. data/test/dummy_app/config/boot.rb +126 -0
  36. data/test/dummy_app/config/database.yml +3 -0
  37. data/test/dummy_app/config/environment.rb +12 -0
  38. data/test/dummy_app/config/environments/test.rb +28 -0
  39. data/test/dummy_app/config/initializers/new_rails_defaults.rb +15 -0
  40. data/test/dummy_app/config/routes.rb +6 -0
  41. data/test/dummy_app/db/schema.rb +0 -0
  42. data/test/dummy_app/init.rb +13 -0
  43. data/test/dummy_app/log/.keep +0 -0
  44. data/test/dummy_app/public/.htaccess +40 -0
  45. data/test/dummy_app/public/404.html +30 -0
  46. data/test/dummy_app/public/422.html +30 -0
  47. data/test/dummy_app/public/500.html +30 -0
  48. data/test/dummy_app/script/console +3 -0
  49. data/test/dummy_app/script/generate +3 -0
  50. data/test/dummy_tests/application_controller_test.rb +93 -0
  51. data/test/dummy_tests/foo_helper_test.rb +12 -0
  52. data/test/dummy_tests/integration_test.rb +30 -0
  53. data/test/dummy_tests/user_mailer_test.rb +91 -0
  54. data/test/dummy_tests/user_test.rb +72 -0
  55. data/test/dummy_tests/users_controller_test.rb +23 -0
  56. data/test/dummy_tests/users_helper_test.rb +81 -0
  57. data/test/support/minitest.rb +7 -0
  58. data/test/support/shared_test_case_behavior.rb +30 -0
  59. data/test/test_helper.rb +12 -0
  60. data/test/test_helper_dummy.rb +8 -0
  61. metadata +238 -63
  62. data/lib/minitest-spec-rails/test_case.rb +0 -33
  63. data/lib/test/unit.rb +0 -9
  64. data/lib/test/unit/assertions.rb +0 -7
  65. data/lib/test/unit/testcase.rb +0 -23
@@ -0,0 +1,17 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionDispatchBehavior
4
+
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ register_spec_type(/(Acceptance|Integration) ?Test\z/i, self)
8
+ register_spec_type(self) { |desc| Class === desc && desc < self }
9
+ register_rails_test_case self
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+
17
+ ActionController::IntegrationTest.send :include, MiniTestSpecRails::Init::ActionDispatchBehavior
@@ -0,0 +1,26 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionMailerBehavior
4
+
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ register_spec_type(self) { |desc| Class === desc && desc < ActionMailer::Base }
8
+ register_spec_type(/Mailer( ?Test)?\z/i, self)
9
+ register_spec_type(self) { |desc| Class === desc && desc < self }
10
+ register_rails_test_case self
11
+ before { setup_minitest_spec_rails_mailer_class }
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def setup_minitest_spec_rails_mailer_class
18
+ describing_class.tests described_class
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+ ActionMailer::TestCase.send :include, MiniTestSpecRails::Init::ActionMailerBehavior
26
+
@@ -0,0 +1,38 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionViewBehavior
4
+
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ class_attribute :_helper_class
8
+ register_spec_type(/(Helper|View)( ?Test)?\z/i, self)
9
+ register_spec_type(self) { |desc| Class === desc && desc < self }
10
+ register_rails_test_case self
11
+ before { setup_minitest_spec_rails_helper_class }
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def helper_class=(new_class)
18
+ self._helper_class = new_class
19
+ end
20
+
21
+ def helper_class
22
+ if current_helper_class = self._helper_class
23
+ current_helper_class
24
+ else
25
+ self.helper_class = determine_default_helper_class(name)
26
+ end
27
+ end
28
+
29
+ def setup_minitest_spec_rails_helper_class
30
+ self.class.helper_class = described_class
31
+ self.class.send :include_helper_modules!
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ ActionView::TestCase.send :include, MiniTestSpecRails::Init::ActionViewBehavior
@@ -0,0 +1,28 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActiveSupportBehavior
4
+
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ extend MiniTest::Spec::DSL
8
+ include MiniTestSpecRails::DSL
9
+ register_spec_type(self) { |desc| Class === desc && desc < ActiveRecord::Base if defined?(ActiveRecord::Base) }
10
+ register_rails_test_case self
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
18
+ ActiveSupport::TestCase.send :include, MiniTestSpecRails::Init::ActiveSupportBehavior
19
+
20
+
21
+ # The AbstractController::Helpers#default_helper_module! blows up using
22
+ # ActiveSupport's modified LoadError class under Ruby 1.8 because describe
23
+ # blocks with spaces for their names have a `module_path` of something like
24
+ # "nested 1" while in Ruby 1.9 it is something like "#<Class:0x007fa256ea1118>"
25
+ # and hence wont find a #path match in REGEXPS due to the space. So add
26
+ # another that allows filenames with spaces in it.
27
+ #
28
+ MissingSourceFile::REGEXPS << %r{^Missing \w+ (?:file\s*)?(.*\.rb)$}i
@@ -0,0 +1,47 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module MiniShouldaBehavior
4
+
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ class << self
8
+
9
+ alias :context :describe
10
+ alias :should :it
11
+
12
+ def setup_with_minitest(*args, &block)
13
+ if args.first.is_a?(Symbol) && !block_given?
14
+ setup_without_minitest(args.first)
15
+ else
16
+ setup_without_minitest { |o| o.instance_eval(&block) }
17
+ end
18
+ end
19
+ alias_method_chain :setup, :minitest
20
+
21
+ def teardown_with_minitest(*args, &block)
22
+ if args.first.is_a?(Symbol) && !block_given?
23
+ teardown_without_minitest(args.first)
24
+ else
25
+ teardown_without_minitest { |o| o.instance_eval(&block) }
26
+ end
27
+ end
28
+ alias_method_chain :teardown, :minitest
29
+
30
+ end
31
+ extend ClassMethods
32
+ end
33
+ end
34
+
35
+ module ClassMethods
36
+
37
+ def should_eventually(desc)
38
+ it("should eventually #{desc}") { skip("Should eventually #{desc}") }
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ ActiveSupport::TestCase.send :include, MiniTestSpecRails::Init::MiniShouldaBehavior
@@ -0,0 +1,7 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest-spec-rails/init/active_support'
3
+ require 'minitest-spec-rails/init/mini_shoulda'
4
+ require 'minitest-spec-rails/init/action_view'
5
+ require 'minitest-spec-rails/init/action_controller'
6
+ require 'minitest-spec-rails/init/action_dispatch'
7
+ require 'minitest-spec-rails/init/action_mailer'
@@ -1,3 +1,3 @@
1
1
  module MiniTestSpecRails
2
- VERSION = "3.0.7"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -2,20 +2,25 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "minitest-spec-rails/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = 'minitest-spec-rails'
7
- s.version = MiniTestSpecRails::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Ken Collins']
10
- s.email = ['ken@metaskills.net']
11
- s.homepage = 'http://github.com/metaskills/minitest-spec-rails'
12
- s.summary = 'Drop in MiniTest::Spec support for Rails 3.x'
13
- s.description = 'Force ActiveSupport::TestCase to subclass MiniTest::Spec for a drop in behavior change.'
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ['lib']
18
- s.add_runtime_dependency 'minitest', '~> 2.1'
19
- s.add_runtime_dependency 'rails', '~> 3.0'
20
- s.add_development_dependency 'rake'
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'minitest-spec-rails'
7
+ gem.version = MiniTestSpecRails::VERSION
8
+ gem.platform = Gem::Platform::RUBY
9
+ gem.authors = ['Ken Collins']
10
+ gem.email = ['ken@metaskills.net']
11
+ gem.homepage = 'http://github.com/metaskills/minitest-spec-rails'
12
+ gem.summary = 'Make Rails Use MiniTest::Spec!'
13
+ gem.description = 'The minitest-spec-rails gem makes it easy to use the MiniTest::Spec DSL within your existing Rails 3 or 4 test suite.'
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+ gem.add_runtime_dependency 'minitest', '~> 4.7'
19
+ gem.add_runtime_dependency 'rails', '~> 2.3.0'
20
+ gem.add_runtime_dependency 'minitest_tu_shim', '~> 1.3.2'
21
+ gem.add_development_dependency 'guard-minitest'
22
+ gem.add_development_dependency 'minitest-emoji'
23
+ gem.add_development_dependency 'minitest-focus'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'sqlite3'
21
26
  end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class ModelsController < ApplicationController; end
4
+
5
+ class ActionControllerTest < MiniTestSpecRails::TestCase
6
+
7
+ it 'matches spec type for class constants' do
8
+ assert_controller MiniTest::Spec.spec_type(ApplicationController)
9
+ assert_controller MiniTest::Spec.spec_type(ModelsController)
10
+ end
11
+
12
+ it 'matches spec type for strings' do
13
+ assert_controller MiniTest::Spec.spec_type("WidgetController")
14
+ assert_controller MiniTest::Spec.spec_type("WidgetControllerTest")
15
+ assert_controller MiniTest::Spec.spec_type("Widget Controller Test")
16
+ # And is not case sensitive
17
+ assert_controller MiniTest::Spec.spec_type("widgetcontroller")
18
+ assert_controller MiniTest::Spec.spec_type("widgetcontrollertest")
19
+ assert_controller MiniTest::Spec.spec_type("widget controller test")
20
+ end
21
+
22
+ it 'wont match spec type for non space characters' do
23
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\tTest")
24
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\rTest")
25
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\nTest")
26
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\fTest")
27
+ refute_controller MiniTest::Spec.spec_type("Widget ControllerXTest")
28
+ end
29
+
30
+
31
+ private
32
+
33
+ def assert_controller(actual)
34
+ assert_equal ActionController::TestCase, actual
35
+ end
36
+
37
+ def refute_controller(actual)
38
+ refute_equal ActionController::TestCase, actual
39
+ end
40
+
41
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class ModelsController < ApplicationController; end
4
+
5
+ class ActionControllerTest < MiniTestSpecRails::TestCase
6
+
7
+ it 'resolves spect type for matching acceptance strings' do
8
+ assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptanceTest")
9
+ assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance Test")
10
+ assert_dispatch MiniTest::Spec.spec_type("widgetacceptancetest")
11
+ assert_dispatch MiniTest::Spec.spec_type("widget acceptance test")
12
+ end
13
+
14
+ it 'wont match spec type for space characters in acceptance strings' do
15
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\tTest")
16
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\rTest")
17
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\nTest")
18
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\fTest")
19
+ refute_dispatch MiniTest::Spec.spec_type("Widget AcceptanceXTest")
20
+ end
21
+
22
+ it 'resolves spec type for matching integration strings' do
23
+ assert_dispatch MiniTest::Spec.spec_type("WidgetIntegrationTest")
24
+ assert_dispatch MiniTest::Spec.spec_type("Widget Integration Test")
25
+ assert_dispatch MiniTest::Spec.spec_type("widgetintegrationtest")
26
+ assert_dispatch MiniTest::Spec.spec_type("widget integration test")
27
+ end
28
+
29
+ it 'wont match spec type for space characters in integration strings' do
30
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\tTest")
31
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\rTest")
32
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\nTest")
33
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\fTest")
34
+ refute_dispatch MiniTest::Spec.spec_type("Widget IntegrationXTest")
35
+ end
36
+
37
+
38
+ private
39
+
40
+ def assert_dispatch(actual)
41
+ assert_equal ActionController::IntegrationTest, actual
42
+ end
43
+
44
+ def refute_dispatch(actual)
45
+ refute_equal ActionController::IntegrationTest, actual
46
+ end
47
+
48
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class NotificationMailer < ActionMailer::Base; end
4
+ class Notifications < ActionMailer::Base; end
5
+
6
+ class ActionMailerTest < MiniTestSpecRails::TestCase
7
+
8
+ it 'matches spec type for class constants' do
9
+ assert_mailer MiniTest::Spec.spec_type(NotificationMailer)
10
+ assert_mailer MiniTest::Spec.spec_type(Notifications)
11
+ end
12
+
13
+ it 'matches spec type for strings' do
14
+ assert_mailer MiniTest::Spec.spec_type("WidgetMailer")
15
+ assert_mailer MiniTest::Spec.spec_type("WidgetMailerTest")
16
+ assert_mailer MiniTest::Spec.spec_type("Widget Mailer Test")
17
+ # And is not case sensitive
18
+ assert_mailer MiniTest::Spec.spec_type("widgetmailer")
19
+ assert_mailer MiniTest::Spec.spec_type("widgetmailertest")
20
+ assert_mailer MiniTest::Spec.spec_type("widget mailer test")
21
+ end
22
+
23
+ it 'wont match spec type for non space characters' do
24
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\tTest")
25
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\rTest")
26
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\nTest")
27
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\fTest")
28
+ refute_mailer MiniTest::Spec.spec_type("Widget MailerXTest")
29
+ end
30
+
31
+
32
+ private
33
+
34
+ def assert_mailer(actual)
35
+ assert_equal ActionMailer::TestCase, actual
36
+ end
37
+
38
+ def refute_mailer(actual)
39
+ refute_equal ActionMailer::TestCase, actual
40
+ end
41
+
42
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class ActionViewTest < MiniTestSpecRails::TestCase
4
+
5
+ it 'resolves spec type for matching helper strings' do
6
+ assert_view MiniTest::Spec.spec_type("WidgetHelper")
7
+ assert_view MiniTest::Spec.spec_type("WidgetHelperTest")
8
+ assert_view MiniTest::Spec.spec_type("Widget Helper Test")
9
+ # And is not case sensitive
10
+ assert_view MiniTest::Spec.spec_type("widgethelper")
11
+ assert_view MiniTest::Spec.spec_type("widgethelpertest")
12
+ assert_view MiniTest::Spec.spec_type("widget helper test")
13
+ end
14
+
15
+ it 'resolves spec type for matching view strings' do
16
+ assert_view MiniTest::Spec.spec_type("WidgetView")
17
+ assert_view MiniTest::Spec.spec_type("WidgetViewTest")
18
+ assert_view MiniTest::Spec.spec_type("Widget View Test")
19
+ # And is not case sensitive
20
+ assert_view MiniTest::Spec.spec_type("widgetview")
21
+ assert_view MiniTest::Spec.spec_type("widgetviewtest")
22
+ assert_view MiniTest::Spec.spec_type("widget view test")
23
+ end
24
+
25
+ it 'wont match spec type for non space characters' do
26
+ refute_view MiniTest::Spec.spec_type("Widget Helper\tTest")
27
+ refute_view MiniTest::Spec.spec_type("Widget Helper\rTest")
28
+ refute_view MiniTest::Spec.spec_type("Widget Helper\nTest")
29
+ refute_view MiniTest::Spec.spec_type("Widget Helper\fTest")
30
+ refute_view MiniTest::Spec.spec_type("Widget HelperXTest")
31
+ end
32
+
33
+
34
+ private
35
+
36
+ def assert_view(actual)
37
+ assert_equal ActionView::TestCase, actual
38
+ end
39
+
40
+ def refute_view(actual)
41
+ refute_equal ActionView::TestCase, actual
42
+ end
43
+
44
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class SomeRandomModel < ActiveRecord::Base; end
4
+
5
+ class ActiveSupportTest < MiniTestSpecRails::TestCase
6
+
7
+ it 'resolves spect type for active record constants' do
8
+ assert_support MiniTest::Spec.spec_type(SomeRandomModel)
9
+ assert_support MiniTest::Spec.spec_type(User)
10
+ end
11
+
12
+ it 'wont resolve spect type for random strings' do
13
+ assert_spec MiniTest::Spec.spec_type("Unmatched String")
14
+ end
15
+
16
+ private
17
+
18
+ def assert_support(actual)
19
+ assert_equal ActiveSupport::TestCase, actual
20
+ end
21
+
22
+ def assert_spec(actual)
23
+ assert_equal MiniTest::Spec, actual
24
+ end
25
+
26
+ end
27
+
28
+ class ActiveSupportCallbackTest < ActiveSupport::TestCase
29
+
30
+ setup :foo
31
+ setup :bar
32
+
33
+ it 'works' do
34
+ @foo.must_equal 'foo'
35
+ @bar.must_equal 'bar'
36
+ end
37
+
38
+ private
39
+
40
+ def foo ; @foo = 'foo' ; end
41
+ def bar ; @bar = 'bar' ; end
42
+
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper_dummy'
2
+
3
+ class PostTests < ActiveSupport::TestCase
4
+
5
+ i_suck_and_my_tests_are_order_dependent!
6
+
7
+ $teardown_ran = false
8
+
9
+ setup do
10
+ @post = user_post
11
+ end
12
+
13
+ teardown do
14
+ $teardown_ran = true
15
+ end
16
+
17
+ should 'setup correctly and $teardown_ran should still be false since this is the first test' do
18
+ @post.must_be_instance_of Post
19
+ $teardown_ran.must_equal false
20
+ end
21
+
22
+ should 'teardown correctly' do
23
+ $teardown_ran.must_equal true
24
+ end
25
+
26
+ should_eventually 'will be skipped' do
27
+ assert false
28
+ end
29
+
30
+ context 'level 1' do
31
+
32
+ should 'work' do
33
+ @post.must_be_instance_of Post
34
+ end
35
+
36
+ end
37
+
38
+ end