Module: Spec::Example::Subject::ExampleGroupMethods
- Included in:
- ExampleGroupMethods
- Defined in:
- lib/spec/example/subject.rb
Instance Attribute Summary collapse
-
#explicit_subject_block ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #its(attribute, &block) ⇒ Object
-
#subject(&block) ⇒ Object
Defines an explicit subject for an example group which can then be the implicit receiver (through delegation) of calls to
should
.
Instance Attribute Details
#explicit_subject_block ⇒ Object (readonly)
:nodoc:
36 37 38 |
# File 'lib/spec/example/subject.rb', line 36 def explicit_subject_block @explicit_subject_block end |
Instance Method Details
#its(attribute, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spec/example/subject.rb', line 23 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 |
#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 }
its(:currency) { should == :USD }
end
See ExampleMethods#should for more information about this approach.
18 19 20 21 |
# File 'lib/spec/example/subject.rb', line 18 def subject(&block) block.nil? ? explicit_subject || implicit_subject : @explicit_subject_block = block end |