Browse files

! Refactored MiniTest::Spec into MiniTest::Spec::DSL.

[git-p4: depot-paths = "//src/minitest/dev/": change = 8289]
  • Loading branch information...
1 parent e9d4ea1 commit 06b9ce3884919b1bd29306d4cce7e8c55f8b3ff4 @zenspider zenspider committed Mar 7, 2013
Showing with 25 additions and 17 deletions.
  1. +25 −17 lib/minitest/spec.rb
View
42 lib/minitest/spec.rb
@@ -81,6 +81,11 @@ def describe desc, additional_desc = nil, &block # :doc:
# For a list of expectations, see MiniTest::Expectations.
class MiniTest::Spec < MiniTest::Unit::TestCase
+
+ ##
+ # Oh look! A MiniTest::Spec::DSL module! Eat your heart out DHH.
+
+ module DSL
##
# Contains pairs of matchers and Spec classes to be used to
# calculate the superclass of a top-level describe. This allows for
@@ -106,7 +111,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
# desc.superclass == ActiveRecord::Base
# end
- def self.register_spec_type(*args, &block)
+ def register_spec_type(*args, &block)
if block then
matcher, klass = block, args.first
else
@@ -120,7 +125,7 @@ def self.register_spec_type(*args, &block)
#
# spec_type("BlahController") # => MiniTest::Spec::Rails
- def self.spec_type desc
+ def spec_type desc
TYPES.find { |matcher, klass|
if matcher.respond_to? :call then
matcher.call desc
@@ -131,18 +136,18 @@ def self.spec_type desc
end
@@describe_stack = []
- def self.describe_stack # :nodoc:
+ def describe_stack # :nodoc:
@@describe_stack
end
##
# Returns the children of this spec.
- def self.children
+ def children
@children ||= []
end
- def self.nuke_test_methods! # :nodoc:
+ def nuke_test_methods! # :nodoc:
self.public_instance_methods.grep(/^test_/).each do |name|
self.send :undef_method, name
end
@@ -155,7 +160,7 @@ def self.nuke_test_methods! # :nodoc:
#
# Equivalent to MiniTest::Unit::TestCase#setup.
- def self.before type = nil, &block
+ def before type = nil, &block
define_method :setup do
super()
self.instance_eval(&block)
@@ -169,7 +174,7 @@ def self.before type = nil, &block
#
# Equivalent to MiniTest::Unit::TestCase#teardown.
- def self.after type = nil, &block
+ def after type = nil, &block
define_method :teardown do
self.instance_eval(&block)
super()
@@ -187,7 +192,7 @@ def self.after type = nil, &block
# Hint: If you _do_ want inheritence, use minitest/unit. You can mix
# and match between assertions and expectations as much as you want.
- def self.it desc = "anonymous", &block
+ def it desc = "anonymous", &block
block ||= proc { skip "(no tests defined)" }
@specs ||= 0
@@ -209,7 +214,7 @@ def self.it desc = "anonymous", &block
#
# Why use let instead of def? I honestly don't know.
- def self.let name, &block
+ def let name, &block
define_method name do
@_memoized ||= {}
@_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
@@ -220,11 +225,11 @@ def self.let name, &block
# Another lazy man's accessor generator. Made even more lazy by
# setting the name for you to +subject+.
- def self.subject &block
+ def subject &block
let :subject, &block
end
- def self.create name, desc # :nodoc:
+ def create name, desc # :nodoc:
cls = Class.new(self) do
@name = name
@desc = desc
@@ -237,17 +242,20 @@ def self.create name, desc # :nodoc:
cls
end
- def self.to_s # :nodoc:
- defined?(@name) ? @name : super
- end
-
# :stopdoc:
- class << self
attr_reader :desc
alias :specify :it
alias :name :to_s
- end
# :startdoc:
+ end
+
+ extend DSL
+
+ TYPES = DSL::TYPES
+
+ def self.to_s # :nodoc:
+ defined?(@name) ? @name : super
+ end
end
##

12 comments on commit 06b9ce3

@metaskills

An059

Let's suit up gentleman! This just turned the tide :)

cc/@blowmage

@metaskills

@zenspider Would you like me to test this first before releasing a new gem version?

@metaskills

Which is kind of hard to do with this repo using bundler :(

@blowmage

@metaskills I pulled minitest, bumped the version, packaged and installed the gem, then updated my project's Gemfile to use that version. This is for testing purposes only. :)

I don't use bundler for minitest-rails, but I do have a a barebones rails app as part of my tests that does.

@metaskills

Thanks Mike! That will work and I guess I will have to do it, for each ruby version I test :)

@metaskills

@zenspider & @blowmage,

I got this working in minitest-spec-rails here. I am really happy with the fact I can ditch all my Test::Unit hacks. When minitest v4.6.3 is released, I will be ready!

@metaskills

NOTE, I am having issues with Ruby 1.8.7 now, will investigate.

@metaskills

I think it has to do with the class name's coming back as "dunno". Any thoughts?

@zenspider
Seattle Ruby Brigade member
@metaskills

Sure... I am working on this diff of minitest now https://gist.github.com/metaskills/5125357

This is the basic error.

module DSL
  def to_s
    super
  end
  alias :name :to_s
end

class Bar
  extend DSL
end

puts Bar.to_s
puts Bar.name # dsl_fail.rb:3:in `name': super: no superclass method `to_s' for Bar:Class (NoMethodError)
              # from dsl_fail.rb:13
@metaskills

FYI, I can confirm that fixing this in some way does resolve my 1.8 usage of MiniTest::Spec::DSL.

@metaskills

Ryan, any word on this? I would love to get out a new version of minitest-spec-rails.

Please sign in to comment.