[rspec-users] mock expectation in before block

Andrea Fazzi andrea.fazzi at alca.le.it
Tue Apr 29 07:59:40 EDT 2008

Hi all,

consider a class Foo that send, in its constructor, some message to an 
object of class Bar:

class Foo
  def initialize(bar)
    @bar = bar



Now, in order to test Foo, I'd like to decouple it from Bar mocking bar 
object, so:

describe Foo do

  before do
    @bar = mock('bar')
    @foo = Foo.new(bar)

  it 'should ...'
  it 'should ...'



The question is: is it appropriate to put a mock expectation inside a 
before block? Or mock expectations are relegated to example blocks?

Thanks in advance.

More information about the rspec-users mailing list