Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Added its(attribute) method for implicit subjects
Browse files Browse the repository at this point in the history
[#883 state:resolved milestone:"Next Release"]
  • Loading branch information
stouset authored and dchelimsky committed Sep 6, 2009
1 parent 294c9ab commit 376645d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions features/subject/implicit_subject.feature
Expand Up @@ -29,3 +29,15 @@ Feature: implicit subject
"""
When I run "spec nested_subject_spec.rb"
Then the stdout should include "1 example, 0 failures"

Scenario: subject with getters
Given a file named "subject_with_getter_spec.rb" with:
"""
describe Array do
describe "when first created" do
its(:length) { should == 0 }
end
end
"""
When I run "spec subject_with_getter_spec.rb"
Then the stdout should include "1 example, 0 failures"
8 changes: 8 additions & 0 deletions lib/spec/example/subject.rb
Expand Up @@ -11,13 +11,21 @@ module ExampleGroupMethods
# 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.
def subject(&block)
block.nil? ?
explicit_subject || implicit_subject : @explicit_subject_block = block
end

def its(attribute, &block)
describe(attribute) do
define_method(:subject) { super().send(attribute) }
it(&block)
end
end

attr_reader :explicit_subject_block # :nodoc:

Expand Down

0 comments on commit 376645d

Please sign in to comment.