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

Zhenning Guan lists at ruby-forum.com
Sat Sep 4 09:08:08 EDT 2010


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?
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list