非常奇怪的rails3 rspec (describe) 问题: 慎重使用嵌套describe
非常奇怪的问题。 也许是自己没有深入看过rspec 文档。 慎重使用 嵌套的describe
今天使用了 gem : state_machine ( https://github.com/pluginaweek/state_machine)
我的 Gemfile
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 endend
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 endend
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 endendclass 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 endend
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 #endend