module Thoughtbot::Shoulda
def add_context(context) # :nodoc:
def add_context(context) # :nodoc: self.contexts.push(context) end
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.current_context Shoulda.current_context.context(name, &blk) else context = Thoughtbot::Shoulda::Context.new(name, self, &blk) context.build end end
def contexts # :nodoc:
def contexts # :nodoc: @contexts ||= [] end
def current_context # :nodoc:
def current_context # :nodoc: self.contexts.last end
def remove_context # :nodoc:
def remove_context # :nodoc: self.contexts.pop end
def should(name, options = {}, &blk)
def should(name, options = {}, &blk) if Shoulda.current_context block_given? ? Shoulda.current_context.should(name, options, &blk) : Should.current_context.should_eventually(name) else context_name = self.name.gsub(/Test/, "") context = Thoughtbot::Shoulda::Context.new(context_name, self) do block_given? ? should(name, options, &blk) : should_eventually(name) end context.build end end
def should_eventually(name, options = {}, &blk)
def should_eventually(name, options = {}, &blk) context_name = self.name.gsub(/Test/, "") context = Thoughtbot::Shoulda::Context.new(context_name, self) do should_eventually(name, &blk) end context.build end