Skip to content
This repository
Browse code

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
Myron Marston myronmarston authored

Showing 1 changed file with 14 additions and 10 deletions. Show diff stats Hide diff stats

  1. +14 10 spec/rspec/core/subject_spec.rb
24 spec/rspec/core/subject_spec.rb
@@ -158,18 +158,22 @@ def subject_value_for(describe_arg, &block)
158 158 expect(inner_subject_value).to eq(1)
159 159 end
160 160
161   - it 'can correctly use `super` in a nested context' do
162   - inner_subject_value = nil
  161 + context 'when `super` is used' do
  162 + it "delegates to the parent context's `subject`, not the named mehtod" do
  163 + inner_subject_value = nil
163 164
164   - ExampleGroup.describe do
165   - subject(:list) { [1, 2, 3] }
166   - describe 'first' do
167   - subject(:first_element) { super().first }
168   - example { inner_subject_value = subject }
169   - end
170   - end.run
  165 + ExampleGroup.describe do
  166 + let(:list) { ["a", "b", "c"] }
  167 + subject { [1, 2, 3] }
171 168
172   - expect(inner_subject_value).to eq(1)
  169 + describe 'first' do
  170 + subject(:list) { super().first(2) }
  171 + example { inner_subject_value = subject }
  172 + end
  173 + end.run
  174 +
  175 + expect(inner_subject_value).to eq([1, 2])
  176 + end
173 177 end
174 178 end
175 179 end

0 comments on commit cc46b55

Please sign in to comment.
Something went wrong with that request. Please try again.