module Spec::Example::Subject::ExampleGroupMethods

def explicit_subject

def explicit_subject
  group = self
  while group.respond_to?(:explicit_subject_block)
    return group.explicit_subject_block if group.explicit_subject_block
    group = group.superclass
  end
end

def implicit_subject

def implicit_subject
  (described_class ? proc {described_class.new} : proc {description_args.first})
end

def its(attribute, &block)

def its(attribute, &block)
  describe(attribute) do
    example do
      self.class.class_eval do
        define_method(:subject) do
          super().send(attribute)
        end
      end
      instance_eval(&block)
    end
  end
end

def subject(&block)

See +ExampleMethods#should+ for more information about this approach.

end
its(:currency) { should == :USD }
it { should_not be_overdrawn }
it { should have_a_balance_of(50, :USD) }
subject { CheckingAccount.new(:amount => 50, :currency => :USD) }
describe CheckingAccount, "with $50" do

== Examples

implicit receiver (through delegation) of calls to +should+.
Defines an explicit subject for an example group which can then be the
def subject(&block)
  block.nil? ?
    explicit_subject || implicit_subject : @explicit_subject_block = block
end