Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clarify spec for use of `super` in a named subject.

If `super` is used in `subject(:name) { }`, it should
delegate to the parent context's `subject`, not to the
parent context's `name`.
  • Loading branch information...
commit cc46b552a4c1354345b529f981611629f745e838 1 parent f099ece
@myronmarston myronmarston authored
Showing with 14 additions and 10 deletions.
  1. +14 −10 spec/rspec/core/subject_spec.rb
View
24 spec/rspec/core/subject_spec.rb
@@ -158,18 +158,22 @@ def subject_value_for(describe_arg, &block)
expect(inner_subject_value).to eq(1)
end
- it 'can correctly use `super` in a nested context' do
- inner_subject_value = nil
+ context 'when `super` is used' do
+ it "delegates to the parent context's `subject`, not the named mehtod" do
+ inner_subject_value = nil
- ExampleGroup.describe do
- subject(:list) { [1, 2, 3] }
- describe 'first' do
- subject(:first_element) { super().first }
- example { inner_subject_value = subject }
- end
- end.run
+ ExampleGroup.describe do
+ let(:list) { ["a", "b", "c"] }
+ subject { [1, 2, 3] }
- expect(inner_subject_value).to eq(1)
+ describe 'first' do
+ subject(:list) { super().first(2) }
+ example { inner_subject_value = subject }
+ end
+ end.run
+
+ expect(inner_subject_value).to eq([1, 2])
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.