[rspec-users] how to pass objects from spec to formatter from before :all block?

Jarmo Pertman jarmo.p at gmail.com
Sat Mar 6 12:09:32 EST 2010


I need to pass something from before :all to formatter. I know that i
could use options hash from spec and then get the value back in
formatter, but it doesn't work when i'm doing it from before :all.

So, this work:

# in spec
before :each do
  options[:something] = 1

# in formatter
def example_failed(example, counter, failure)
  puts example.options[:something] # outputs 1

But if i try to do the same thing from before :all, then it doesn't

So i looked into the source of RSpec and in example/example_methods.rb
in method set_instance_variables_from_hash there is a line which
ignores some instance variables among with others @_proxy, which has
this option hash initialized in before :all and that's why it's not
getting into the formatter - in other words it is just dropped.

Is this a bug or expected behaviour? If it's expected then what's the
reason and how could i get the desired results of passing something to
formatter from before :all?

Can't we just pass this options hash along?


More information about the rspec-users mailing list