Наскоро научих за rspec тест в релси и след връзката https://relishapp.com/rspec/rspec-core/v/3-6/docs/subject/explicit-subject с кодът по-долу:
RSpec.describe Array do
# This uses a context local variable. As you can see from the
# specs, it can mutate across examples. Use with caution.
element_list = [1, 2, 3]
subject { element_list.pop }
it "is memoized across calls (i.e. the block is invoked once)" do
expect {
3.times { subject }
}.to change{ element_list }.from([1, 2, 3]).to([1, 2])
expect(subject).to eq(3)
end
it "is not memoized across examples" do
expect{ subject }.to change{ element_list }.from([1, 2]).to([1])
expect(subject).to eq(2)
end
end
Може ли някой да ми обясни:
- защо 3.times { subject } се изпълнява само веднъж element_list.pop
- изречението „това „не е запомнено в примери““ означаваше element_list все още [1, 2, 3], но в този пример е само [1, 2]?
Благодаря ти.