ruby on rails - Testing setters with RSpec, should_receive, and create? -


After

I am working on an e-commerce system and familiarize myself with RSpec.

An order is an affiliate payment when the order is completed. It starts processing payments through our payment gateway.

Below is the imagery, the proper method, and the failure message.

  'spec_helper' is a description of the command, can give "#process_payment"! (: User) {} create_user! (: CREDIT_CARD) {} new_credit_card do it! (: Command) {user.orders.create! Total: 200} do it! Credit_card.stub (Sales: Really) tax order.stub (CREDIT_CARD: CREDIT_CARD) order.payments.stub (make! Payment: {payment: {stub ('payment', start_processing!) Is true)) Payment.stub (: source = = & gt; true, process !: true) finally "makes payment" order.payments.should_receive (: create!). With (amount: 200, source: credit_card). And payment payment orders. Prose_pummant ends, "Sets the payment source to the credit card and it tells the process!" (: Source =). Order.process_payment, with payment.should_receive tax (CREDIT_CARD) .ordered payment.should_receive ..: Order ending (! Process) ordered   

Here is the order class

  class command & lt; ActiveRecord :: Base ... def process_payment payments.create! (Amount: total, source: credit_card). Tap | Payment | payment process! End of end ... end   

The second fantasy is failing, claiming that: Source = is not received, with the order, it just says that process! Is called out of order, without order, it says that it was expected: source = once, but never received it. I think why it should be ordered there, but just wanted to make it clear that it is claiming that: Source = is never being received.

Make it! Calling source = no? What is the proper way to test to make sure the source payment is being set properly? Text after "

I would say that your it "pays" is enough spacetime < Responsibility for Code> Behavior of Behavior should be specially written in a specialty.

If you really want to make sure that create! This is what is believed, try to save process_payment in the database, then call Payment.last to get a new record and on that Check properties. But I think it will be redundant.

Think about it, when you write controlling glasses, you do not again test all the behavior of your model; You just check how your controller interfaces with them. This is a similar situation.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -