Created
September 28, 2011 09:54
-
-
Save s6577t/1247517 to your computer and use it in GitHub Desktop.
Why I need an act method etc. in rspec spies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # new DSL: | |
| # 'act': specifies the action under test as a block | |
| # 'result': the return result from 'act' | |
| describe MyClass do | |
| subject { MyClass.new } | |
| describe '#method' do | |
| act { subject.method } | |
| before :each do | |
| subject.stub(:meow) | |
| # Can't put the MyClass#method call here because it will be executed before the inner before :each below | |
| end | |
| it 'should have called meow' do | |
| result.should == 123456 | |
| subject.should have_received(:meow) | |
| end | |
| context 'something global needs changing' do | |
| before :each do | |
| # this has to be executed *before* the *act* | |
| Something::GLOBAL = 'Something different for the purposes of this test' | |
| end | |
| it 'should not have called meow' do | |
| subject.should have_received(:meow) | |
| end | |
| end | |
| context 'when calling with false' do | |
| # this act statement takes precendence over the previous | |
| act { subject.method(false) } | |
| it 'should behave differently when call with false' do | |
| pending "etc." | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment