1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Documentation

git-svn-id: https://svn.thoughtbot.com/plugins/tb_test_helpers/trunk@42 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
This commit is contained in:
tsaleh 2007-03-14 19:12:11 +00:00
parent 6730ae5f39
commit 0a6da8b218
5 changed files with 223 additions and 212 deletions

1
README
View file

@ -0,0 +1 @@
== Example

View file

@ -1,6 +1,7 @@
class Test::Unit::TestCase
class Test # :nodoc:
class Unit # :nodoc:
class TestCase
class << self
# Ensures that the model cannot be saved if one of the attributes listed is not present.
# Requires an existing record
def should_require_attributes(*attributes)
@ -195,4 +196,6 @@ class Test::Unit::TestCase
end
end
end
end
end
end

View file

@ -1,11 +1,12 @@
module TBTestHelpers
module TBTestHelpers # :nodoc:
module Should
def Should.included(other)
def Should.included(other) # :nodoc:
@@_context_names = []
@@_setup_blocks = []
@@_teardown_blocks = []
end
# Creates a context block with the given name. The context block can contain setup, should, should_eventually, and teardown blocks.
def context(name, &context_block)
@@_context_names << name
context_block.bind(self).call
@ -14,17 +15,17 @@ module TBTestHelpers
@@_teardown_blocks.pop
end
# Run before every should block in the current context
def setup(&setup_block)
@@_setup_blocks << setup_block
end
# Run after every should block in the current context
def teardown(&teardown_block)
@@_teardown_blocks << teardown_block
end
# Defines a specification. Can be called either inside our outside of a context.
#
#
def should(name, opts = {}, &should_block)
unless @@_context_names.empty?
test_name = "test #{@@_context_names.join(" ")} should #{name}"
@ -48,11 +49,13 @@ module TBTestHelpers
define_method test_name_sym do |*args|
setup_block.bind(self).call if setup_block
should_block.bind(self).call(*args)
ensure
teardown_block.bind(self).call if teardown_block
end
end
end
# Defines a specification that is not yet implemented. Will be displayed as an 'X' when running tests, and failures will not be shown.
def should_eventually(name, &block)
should("eventually #{name}", {:unimplemented => true}, &block)
end

View file

@ -1,7 +1,9 @@
require 'active_record_helpers'
require 'should'
class Test::Unit::TestCase
class Test # :nodoc:
class Unit # :nodoc:
class TestCase
class << self
include TBTestHelpers::Should
@ -28,6 +30,7 @@ class Test::Unit::TestCase
assert_difference(object, method, 0, reload, &block)
end
# Logs a message, tagged with TESTING: and the name of the calling method.
def report!(msg = "")
@controller.logger.info("TESTING: #{caller.first}: #{msg}")
end
@ -43,6 +46,7 @@ class Test::Unit::TestCase
assert_equal(a1, a2)
end
end
end
end

View file

@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), 'test_helper')
class ContextTest < Test::Unit::TestCase
class ContextTest < Test::Unit::TestCase # :nodoc:
context "context with setup block" do
setup do