Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4610

Passing information from 'before' to 'after' block

$
0
0

(I'm using JRuby, but I think that my problem applies to MRI Ruby as well)

My RSpec definition has this overall structure:

RSpec.describe 'XXX' do  before(:all) do    # preparation common for each example  end  after(:all) do    # clean up after each example  end  context 'C1' do    it 'Ex1' do      ....    end    it 'Ex2' do      ....    end    .... end context 'C2' do    .... # more examples here end

end

The problem here is that the preparation work (before(:all)) involves calculating a value, say

some_value=MyMod.foo()

which I would need in the cleanup code (after(:all)), i.e.

MyMod.bar(some_value)

Of course, since some_value is a local variable, I can not do this. In theory, I could use a global variable,

 before(:all) do   $some_value=MyMod.foo() end after(:all) do   MyMod.bar($some_value)   end

but this is not only ugly, it would cause problems if I decide one day to parallelize my tests.

Can this be achieved? Or is my overall design flawed?


Viewing all articles
Browse latest Browse all 4610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>