module Shoulda::Context::DSL::ClassMethods
def before_should(name, &blk)
end
end
end
User.expects(:find).with(:all).returns(@users)
before_should "find all users" do
# runs before "get :index"
should respond_with(:success)
setup { get :index }
context "on GET" do
end
User.stubs(:find).returns(@users)
@users = [Factory(:user)]
setup do
context "the index action" do
class UserControllerTest < Test::Unit::TestCase
=== Example:
context's setup. These are especially useful when setting expectations.
Before statements are should statements that run before the current
== Before statements
def before_should(name, &blk) should(name, :before => blk) { assert true } end
def context(name, &blk)
def context(name, &blk) if Shoulda::Context.current_context Shoulda::Context.current_context.context(name, &blk) else context = Shoulda::Context::Context.new(name, self, &blk) context.build end end
def described_type
class UserTest; described_type; end
Returns the class being tested, as determined by the test class name.
def described_type @described_type ||= self.name. gsub(/Test$/, ''). split('::'). inject(Object) do |parent, local_name| parent.const_get(local_name, false) end end
def should(name_or_matcher, options = {}, &blk)
def should(name_or_matcher, options = {}, &blk) if Shoulda::Context.current_context Shoulda::Context.current_context.should(name_or_matcher, options, &blk) else context_name = self.name.gsub(/Test$/, "") if name context = Shoulda::Context::Context.new(context_name, self) do should(name_or_matcher, options, &blk) end context.build end end
def should_eventually(name, options = {}, &blk)
def should_eventually(name, options = {}, &blk) context_name = self.name.gsub(/Test$/, "") context = Shoulda::Context::Context.new(context_name, self) do should_eventually(name, &blk) end context.build end
def should_not(matcher)
=== Example:
pass unless the matcher matches the subject.
to generate a test name and negative failure message, and the test will
Allows negative tests using matchers. The matcher's description is used
def should_not(matcher) if Shoulda::Context.current_context Shoulda::Context.current_context.should_not(matcher) else context_name = self.name.gsub(/Test$/, "") if name context = Shoulda::Context::Context.new(context_name, self) do should_not(matcher) end context.build end end
def subject(&block)
should validate_uniqueness_of(:email)
# uses the existing user
subject { User.first }
class UserTest < Test::Unit::TestCase
Sets the return value of the subject instance method:
def subject(&block) @subject_block = block end
def subject_block # :nodoc:
def subject_block # :nodoc: @subject_block ||= nil end