发布时间: 2012-03-09 14:05:00
gem 'rails', '3.2.0' gem "state_machine", "1.1.2" group :development, :test do gem 'rspec', '2.8.0' gem 'rspec-rails', '2.8.1' end
require 'spec_helper' describe Contract do # 之前的很多测试用例 describe "state machine" do it "should transit its state to ready_to_review" do contract = Contract.new contract.ready_to_review contract.state.should == Contract::STATE_READY_TO_REVIEW.to_s end end end
class Contract STATE_CREATED= :created STATE_READY_TO_REVIEW =:ready_to_review state_machine :state, :initial => STATE_CREATED do event :ready_to_review do transition STATE_CREATED => STATE_READY_TO_REVIEW end end end
require 'rubygems' require 'state_machine' require 'test/unit' class Contract STATE_CREATED= :created STATE_READY_TO_REVIEW =:ready_to_review state_machine :state, :initial => STATE_CREATED do event :ready_to_review do transition STATE_CREATED => STATE_READY_TO_REVIEW end end end class ContractTest < Test::Unit::TestCase def test_should_transition contract = Contract.new puts "contract.state: #{contract.state}" assert contract.state == Contract::STATE_CREATED.to_s assert contract.can_ready_to_review? == true result =contract.ready_to_review puts "result: #{result}" puts "contract.state: #{contract.state}" assert contract.state == Contract::STATE_READY_TO_REVIEW.to_s end end
describe "state machine" do这一行注释掉。 居然就好了! 我无语啊!
require 'spec_helper' describe Contract do # 注释掉了外层的 describe #describe "state machine" do it "should transit its state to ready_to_review" do contract = Contract.new contract.ready_to_review contract.state.should == Contract::STATE_READY_TO_REVIEW.to_s end #end end