spectator icon indicating copy to clipboard operation
spectator copied to clipboard

Stubs for mocked types should use the spec scope

Open icy-arctic-fox opened this issue 4 years ago • 0 comments

Currently, the scope of method stubs with a default scope is executed within the mocked type. This should be changed to execute in the scope of the spec.

struct MyStruct
  def stubbed_method
    answer
  end

  def answer
    1
  end
end

Spectator.describe MyStruct do
  let(answer) { 42 }

  mock MyStruct do
    stub stubbed_method { answer }
  end

  it "returns the answer" do
    expect(subject.stubbed_method).to eq(42) # Fails, reports 1
  end
end

Issue originally raised in #14

icy-arctic-fox avatar Nov 07 '20 18:11 icy-arctic-fox