Module: Spec::Example::Subject::ExampleGroupMethods

Included in:
ExampleGroupMethods
Defined in:
lib/spec/example/subject.rb

Instance Method Summary collapse

Instance Method Details

#subject(&block) ⇒ Object

Defines an explicit subject for an example group which can then be the implicit receiver (through delegation) of calls to should.

Examples

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

See ExampleMethods#should for more information about this approach.



17
18
19
20
21
22
23
# File 'lib/spec/example/subject.rb', line 17

def subject(&block)
  if block.nil?
    @_subject_block || (described_class ? lambda {described_class.new} : lambda {description_args.first})
  else
    @_subject_block = block
  end
end