Hi,
I’m struggling with structuring my specs describing a large process in
my
app. There are multiple paths of execution through that process each of
which I’m trying to describe using a different rspec context, eg.
describe Violation do
context “, when nothing has changed since the last run”
context “, when new content has been created, but policies remain the
same”
context “, when new policies are activated, but content remains the
same”
end
Each of the three scenarios/context above have got a bunch of “it
should…”
blocks in it which in turn contain a whole bunch of should_receives and
should_not_receives on various mocked objects, thereby exercising the
functionality of the large process.
I would like the context to read as follows:
context “, when new policies are activated, but content remains the
same” do
it “should create the new policy” do
# a whole bunch of expectations testing the policy creation part
of
the process
end
it “should create a new violation and location” do
# a whole bunch of expectations testing the violation creation part
of
the process
end
it “should resolve previous violations” do
# a whole bunch of expections testing retrieval of previous
violations
and performing updates on them
end
…
end
The problem is: if I compartmentalize my expectations into the
individual
it-should-blocks then something will fail in the execution of the large
process, typically caused by a mock not being setup. If I lump all my
expectations in the before(:each)-block then the whole thing springs to
life, but I lose my compartmentalization of the specs and the whole
thing
becomes unreadable.
I guess I’m looking for help and advice on how best combat the lumping
of
expectations into the before-block. Should I separate my stubbing from
my
expectations ?
Many thanks for your advice.
(I’m using rspec 1.2.9 and Rails 2.2.2 on OSX)
Regards,
Ijonas.