Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rspec/core/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def its(attribute, &block)
# @see ExampleMethods#subject
# @see ExampleMethods#should
def subject(name=nil, &block)
define_method(name) { subject } if name
block ? @explicit_subject_block = block : explicit_subject || implicit_subject
if name
let(name, &block)
subject { send name }
else
block ? @explicit_subject_block = block : explicit_subject || implicit_subject
end
end

attr_reader :explicit_subject_block
Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/core/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ module RSpec::Core
end
group.run.should be_true
end

it "is referred from inside subject by the name" do
group = ExampleGroup.describe do
subject(:list) { [1,2,3] }
describe 'first' do
subject(:first_element) { list.first }
it { should eq(1) }
end
end
group.run.should be_true
end
end
end

Expand Down