module TestBelt::Should
Public Instance Methods
should(matchers_or_desc, &block)
click to toggle source
Usage: class SomeTest < Test::Unit::TestCase
extend TestBelt::Should
end
# File lib/test_belt/should.rb, line 14 def should(matchers_or_desc, &block) tests = should_tests(matchers_or_desc, &block) context = should_context each_should(context, tests) do |name, code| define_method(name) do begin self.class._testbelt_setups.each {|sb| instance_eval(&sb)} instance_eval(&code) ensure self.class._testbelt_teardowns.reverse.each {|tb| instance_eval(&tb)} end end end end
should_eventually(matchers_or_desc, &block)
click to toggle source
This method is identical to the should version, however this one does nothing but skip any tests described or matched on
# File lib/test_belt/should.rb, line 32 def should_eventually(matchers_or_desc, &block) tests = should_tests(matchers_or_desc, &block) context = should_context each_should(context, tests) do |name, code| define_method(name) { skip } end end
Private Instance Methods
each_should(context, tests) { |should_test_name(context, t), t| ... }
click to toggle source
# File lib/test_belt/should.rb, line 43 def each_should(context, tests) tests.each do |t| yield should_test_name(context, t[0]), t[1] end end
should_context()
click to toggle source
# File lib/test_belt/should.rb, line 63 def should_context _testbelt_contexts end
should_test_name(context, name)
click to toggle source
# File lib/test_belt/should.rb, line 67 def should_test_name(context, name) test_name = ["test:", context, "should", "#{name}. "].compact.flatten.join(' ').to_sym if instance_methods.include?(test_name.to_s) warn " * WARNING: '#{test_name}' is already defined" end test_name end
should_tests(matchers_or_desc, &block)
click to toggle source
# File lib/test_belt/should.rb, line 49 def should_tests(matchers_or_desc, &block) unless matchers_or_desc.kind_of?(::Array) || block_given? raise ArgumentError, "either specify a test block and description or a set of matchers" end if matchers_or_desc.kind_of?(::Array) matchers_or_desc.collect do |matcher| [matcher.desc, Proc.new {assert_matcher(matcher)}] end else [[matchers_or_desc.to_s, block]] end end