2014-02-13 13 views
1

RSpec的測試有大禮包,調整延伸我如何寫state_machine過渡回調

Spree::Adjustment.class_eval do 
    state_machine do 
    after_transition :to => :closed, :do => :some_method 
    end 
    def some_method 
    end 
end 

我有RSpec的測試,它失敗。在實際的應用程序方法被調用,所有的東西都按預期工作。

describe Spree:Adjustment do 
    let(:adjustment) { create(:adjustment, state: 'open') } 
    it "call some_method after close" do 
     adjustment.should_receive(:some_method) 
     adjustment.state = "closed" 
    end 
end  

失敗,

1) Spree::Adjustment call some_method after close 
Failure/Error: adjustment.should_receive(:some_method) 
    (#<Spree::Adjustment:0x0000000751a340>).some_method(any args) 
     expected: 1 time with any arguments 
     received: 0 times with any arguments 
+0

您收到了什麼故障? –

+0

我對rspec消息添加了問題,即使使用事件,rspec仍然失敗,但它仍然正常「未通過測試」消息 – dpa

回答

1

狀態機的過渡,如果你設置狀態明確,像你一樣,用Adjustment#state=方法(在這種情況下)不工作。您應該使用事件代替,例如:

adjustment.close 
+0

。 –