[rspec-users] how to wrtie this test?(test true but change when refactor)

David Chelimsky dchelimsky at gmail.com
Sat Sep 4 09:20:39 EDT 2010


On Sep 4, 2010, at 8:08 AM, Zhenning Guan wrote:

> def process!
>  #transaction block
>    bankbook = self.bankbooks.build
>    bankbook = user.bank.bankbooks.build
>    bankbook.withdraw
>  #end
> end
> 
>  it "should process the withdrawal request" do
>    #something here omit
>    withdrawal.process!
>    @ning.bankbooks.last.price.should == BigDecimal('1.00')
>    @ning.bankbooks.last.action.should == 'withdraw'
>  end
> 
> bank will withdraw money and bankbook create a record for this withdraw.
> after a while, I think bankbook should create withdraw item after bank
> withdraw.
> so I change the code like following code.
> def process!
>  #transaction block
>   bank.withdraw
>  #end
> end
> 
> # bank model
> def xxxx
>    bankbook = bankbooks.build
>    bankbook.withdraw
> end
> 
> the 'should process the withdrawal request' it's true. but after the
> change we got two bankbook items. so what's the correct way to create
> this test?

I'm having a hard time understanding what you're trying to do here. Can you please post the full before and after code and spec listing in a gist or pastie?

http://gist.github.com
http://pastie.org


More information about the rspec-users mailing list