Use before instead of before_each (same for after)

This commit is contained in:
Michael Miller 2022-11-04 16:56:03 -06:00
parent 4906dfae0d
commit a6149b2671
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
8 changed files with 28 additions and 28 deletions

View file

@ -169,7 +169,7 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
end
context "with method calls" do
before_each do
before do
dbl.test_method
dbl.test_method(1, "wrong", :xyz, foo: "foobarbaz")
dbl.irrelevant("foo")
@ -289,7 +289,7 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
pre_condition { expect(match_data).to be_a(failed_match) }
before_each do
before do
dbl.test_method
dbl.test_method(1, "test", :xyz, foo: "foobarbaz")
dbl.irrelevant("foo")

View file

@ -52,7 +52,7 @@ Spectator.describe "Explicit Subject" do
describe Array(Int32) do # TODO: Multiple arguments to describe/context.
subject { [] of Int32 }
before_each { subject.push(1, 2, 3) }
before { subject.push(1, 2, 3) }
it "has the prescribed elements" do
expect(subject).to eq([1, 2, 3])

View file

@ -312,7 +312,7 @@ Spectator.describe "Double DSL", :smoke do
let(override) { :override }
let(dbl) { double(:context_double, override: override) }
before_each { allow(dbl).to receive(:memoize).and_return(memoize) }
before { allow(dbl).to receive(:memoize).and_return(memoize) }
it "doesn't change predefined values" do
expect(dbl.predefined).to eq(:predefined)

View file

@ -947,7 +947,7 @@ Spectator.describe "Mock DSL", :smoke do
let(override) { :override }
let(fake) { mock(Dummy, override: override) }
before_each { allow(fake).to receive(:memoize).and_return(memoize) }
before { allow(fake).to receive(:memoize).and_return(memoize) }
it "doesn't change predefined values" do
expect(fake.predefined).to eq(:predefined)

View file

@ -309,7 +309,7 @@ Spectator.describe Spectator::Double do
subject(dbl) { ClassDouble }
let(foo_stub) { Spectator::ValueStub.new(:foo, :override) }
after_each { dbl._spectator_clear_stubs }
after { dbl._spectator_clear_stubs }
it "overrides an existing method" do
expect { dbl._spectator_define_stub(foo_stub) }.to change { dbl.foo }.from(:stub).to(:override)
@ -357,7 +357,7 @@ Spectator.describe Spectator::Double do
end
describe "._spectator_clear_stubs" do
before_each { dbl._spectator_define_stub(foo_stub) }
before { dbl._spectator_define_stub(foo_stub) }
it "removes previously defined stubs" do
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(:override).to(:stub)
@ -365,7 +365,7 @@ Spectator.describe Spectator::Double do
end
describe "._spectator_calls" do
before_each { dbl._spectator_clear_calls }
before { dbl._spectator_clear_calls }
# Retrieves symbolic names of methods called on a double.
def called_method_names(dbl)
@ -440,7 +440,7 @@ Spectator.describe Spectator::Double do
subject(dbl) { FooBarDouble.new }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
it "removes previously defined stubs" do
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
@ -451,7 +451,7 @@ Spectator.describe Spectator::Double do
subject(dbl) { FooBarDouble.new }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
# Retrieves symbolic names of methods called on a double.
def called_method_names(dbl)

View file

@ -246,7 +246,7 @@ Spectator.describe Spectator::LazyDouble do
subject(dbl) { Spectator::LazyDouble.new(foo: 42, bar: "baz") }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
it "removes previously defined stubs" do
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
@ -257,7 +257,7 @@ Spectator.describe Spectator::LazyDouble do
subject(dbl) { Spectator::LazyDouble.new(foo: 42, bar: "baz") }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
# Retrieves symbolic names of methods called on a double.
def called_method_names(dbl)

View file

@ -312,7 +312,7 @@ Spectator.describe Spectator::Mock do
let(mock) { MockThing }
let(foo_stub) { Spectator::ValueStub.new(:foo, :override) }
after_each { mock._spectator_clear_stubs }
after { mock._spectator_clear_stubs }
it "overrides an existing method" do
expect { mock._spectator_define_stub(foo_stub) }.to change { mock.foo }.from(:stub).to(:override)
@ -368,7 +368,7 @@ Spectator.describe Spectator::Mock do
end
describe "._spectator_clear_stubs" do
before_each { mock._spectator_define_stub(foo_stub) }
before { mock._spectator_define_stub(foo_stub) }
it "removes previously defined stubs" do
expect { mock._spectator_clear_stubs }.to change { mock.foo }.from(:override).to(:stub)
@ -376,7 +376,7 @@ Spectator.describe Spectator::Mock do
end
describe "._spectator_calls" do
before_each { mock._spectator_clear_calls }
before { mock._spectator_clear_calls }
# Retrieves symbolic names of methods called on a mock.
def called_method_names(mock)
@ -410,7 +410,7 @@ Spectator.describe Spectator::Mock do
let(mock) { MockThing.new }
after_each { mock._spectator_clear_stubs }
after { mock._spectator_clear_stubs }
it "raises a TypeCastError when using a value-based stub" do
stub = Spectator::ValueStub.new(:oops, nil).as(Spectator::Stub)
@ -461,7 +461,7 @@ Spectator.describe Spectator::Mock do
let(mock) { MockedClass.new }
# Necessary to clear stubs to prevent leakages between tests.
after_each { mock._spectator_clear_stubs }
after { mock._spectator_clear_stubs }
it "overrides responses from methods with keyword arguments" do
expect(mock.method1).to eq(123)
@ -571,8 +571,8 @@ Spectator.describe Spectator::Mock do
let(mock) { MockedStruct.new }
# Necessary to clear stubs to prevent leakages between tests.
after_each { mock._spectator_clear_stubs }
after_each { MockedStruct._spectator_invocations.clear }
after { mock._spectator_clear_stubs }
after { MockedStruct._spectator_invocations.clear }
it "overrides responses from methods with keyword arguments" do
expect(mock.method1).to eq(123)
@ -656,7 +656,7 @@ Spectator.describe Spectator::Mock do
let(mock) { Thing }
let(foo_stub) { Spectator::ValueStub.new(:foo, :override) }
after_each { mock._spectator_clear_stubs }
after { mock._spectator_clear_stubs }
it "overrides an existing method" do
expect { mock._spectator_define_stub(foo_stub) }.to change { mock.foo }.from(:stub).to(:override)
@ -712,7 +712,7 @@ Spectator.describe Spectator::Mock do
end
describe "._spectator_clear_stubs" do
before_each { mock._spectator_define_stub(foo_stub) }
before { mock._spectator_define_stub(foo_stub) }
it "removes previously defined stubs" do
expect { mock._spectator_clear_stubs }.to change { mock.foo }.from(:override).to(:stub)
@ -720,7 +720,7 @@ Spectator.describe Spectator::Mock do
end
describe "._spectator_calls" do
before_each { mock._spectator_clear_calls }
before { mock._spectator_clear_calls }
# Retrieves symbolic names of methods called on a mock.
def called_method_names(mock)
@ -756,7 +756,7 @@ Spectator.describe Spectator::Mock do
let(mock) { NoReturnThing.new }
after_each { mock._spectator_clear_stubs }
after { mock._spectator_clear_stubs }
it "raises a TypeCastError when using a value-based stub" do
stub = Spectator::ValueStub.new(:oops, nil).as(Spectator::Stub)

View file

@ -270,7 +270,7 @@ Spectator.describe Spectator::NullDouble do
subject(dbl) { ClassDouble }
let(foo_stub) { Spectator::ValueStub.new(:foo, :override) }
after_each { dbl._spectator_clear_stubs }
after { dbl._spectator_clear_stubs }
it "overrides an existing method" do
expect { dbl._spectator_define_stub(foo_stub) }.to change { dbl.foo }.from(:stub).to(:override)
@ -318,7 +318,7 @@ Spectator.describe Spectator::NullDouble do
end
describe "._spectator_clear_stubs" do
before_each { dbl._spectator_define_stub(foo_stub) }
before { dbl._spectator_define_stub(foo_stub) }
it "removes previously defined stubs" do
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(:override).to(:stub)
@ -326,7 +326,7 @@ Spectator.describe Spectator::NullDouble do
end
describe "._spectator_calls" do
before_each { dbl._spectator_clear_calls }
before { dbl._spectator_clear_calls }
# Retrieves symbolic names of methods called on a double.
def called_method_names(dbl)
@ -401,7 +401,7 @@ Spectator.describe Spectator::NullDouble do
subject(dbl) { FooBarDouble.new }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
it "removes previously defined stubs" do
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
@ -412,7 +412,7 @@ Spectator.describe Spectator::NullDouble do
subject(dbl) { FooBarDouble.new }
let(stub) { Spectator::ValueStub.new(:foo, 5) }
before_each { dbl._spectator_define_stub(stub) }
before { dbl._spectator_define_stub(stub) }
# Retrieves symbolic names of methods called on a double.
def called_method_names(dbl)