如何解决Spec通过Rails 3.0.4,在3.1.0.rc4中失败
| 请帮助我调试Rails 3.1。它在3.0中通过。谢谢。 $ rspec规格/型号 更新:托管模型require \'transitions\'
class Escrow < ActiveRecord::Base
include ActiveRecord::Transitions
include Amendable
include ActsAsAsset
include Searchable
acts_as_taggable_on :tags
has_many :addresses,:as => :addressable
has_many :events,:as => :entity
has_many :phone_numbers,:as => :phoneable
belongs_to :property
validates :property,:presence => true
state_machine do
state :open
state :cancel
state :close
event :cancel do
transitions :to => :cancel,:from => [:open]
end
event :close do
transitions :to => :close,:from => [:open]
end
end
def self.open
where :state => \'open\'
end
def all_participants
(self.users + property.users).flatten.compact.uniq.sort +
(self.groups + property.groups).flatten.compact.uniq.sort
end
end
模型
require \'transitions\'
class Property < ActiveRecord::Base
include ActiveRecord::Transitions
include ActsAsAsset
include Amendable
include Searchable
acts_as_taggable_on :tags
has_many :addresses,:as => :addressable
has_many :escrows
has_many :events,:as => :phoneable
state_machine do
state :pending
state :active,:enter => :cancel_escrow
state :cancel,:enter => :cancel_escrow
state :close,:enter => :close_escrow
state :expire
state :escrow,:enter => :open_escrow
event :active do
transitions :to => :active,:from => [:escrow,:expire,:pending,:cancel]
end
event :cancel do
transitions :to => :cancel,:from => [:active,:escrow,:pending]
end
event :close do
transitions :to => :close,:from => [:escrow]
end
event :expire do
transitions :to => :expire,:from => [:active]
end
event :escrow do
transitions :to => :escrow,:from => [:active],:guard => :no_open_escrows
end
end
def current_escrow
self.escrows.open.first
end
private
def cancel_escrow
self.current_escrow.try(:cancel!)
end
def close_escrow
self.current_escrow.try(:close!)
end
def no_open_escrows
self.escrows.open.empty?
end
def open_escrow
self.escrows.create!
end
end
规格
require \'spec_helper\'
describe Property do
disconnect_sunspot
describe \'Associations\' do
it { should have_one :pivot }
it { should have_many :addresses }
it { should have_many :escrows }
it { should have_many(:events) }
it { should have_many(:groups).through(:pivot) }
it { should have_many :phone_numbers }
it { should have_many(:users).through(:pivot) }
end
describe \'Database Columns\' do
it { should have_db_column(:state).of_type(:string) }
end
describe \'Factory\' do
it { Factory.build(:property).valid?.should == true }
end
describe \'Methods\' do
describe \'#current_escrow\' do
it \'returns open escrow or none\' do
p = Factory :property,:state => \'active\'
p.escrow!
e = p.escrows.first
2.times { p.escrows.create :state => \'canceled\' }
p.current_escrow.should == e
end
end
end
describe \'Modules\' do
it { Property.included_modules.include?(ActsAsAsset).should == true }
it { Property.included_modules.include?(Amendable).should == true }
end
describe \'State Transitions\' do
describe \'active!\' do
%w(cancel escrow expire pending).each do |state|
it \"transitions to active from #{state}\" do
p = Factory :property,:state => state
lambda { p.active! }.should_not raise_error
end
end
%w(close).each do |state|
it \"cannot transition to active from #{state}\" do
p = Factory :property,:state => state
lambda { p.active! }.should raise_error
end
end
it \'marks escrow reconciled and canceled if escrow -> active\' do
p = Factory :property,:state => \'active\'
p.escrow!
p.active!
p.reload
p.send(:no_open_escrows).should == true
p.escrows.first.state.should == \'cancel\'
end
end
describe \'cancel!\' do
%w(active escrow pending).each do |state|
it \"transitions to cancel from #{state}\" do
p = Factory :property,:state => state
lambda { p.cancel! }.should_not raise_error
end
end
%w(close).each do |state|
it \"cannot transition to cancel from #{state}\" do
p = Factory :property,:state => state
lambda { p.active! }.should raise_error
end
end
end
describe \'close!\' do
%w(escrow).each do |state|
it \"transitions to close from #{state}\" do
p = Factory :property,:state => state
lambda { p.close! }.should_not raise_error
end
end
%w(expire cancel pending).each do |state|
it \"cannot transition to close from #{state}\" do
p = Factory :property,:state => state
lambda { p.close! }.should raise_error
end
end
end
describe \'escrow!\' do
%w(active).each do |state|
it \"transitions to escrow from #{state}\" do
p = Factory :property,:state => state
lambda { p.escrow! }.should_not raise_error
end
end
%w(escrow close cancel expire pending).each do |state|
it \"cannot transition to escrow from #{state}\" do
p = Factory :property,:state => state
lambda { p.escrow! }.should raise_error
end
end
it \'creates a new escrow object on escrow!\' do
p = Factory :property,:state => \'active\'
p.escrows.empty?.should == true
p.escrow!
p.reload
p.escrows.size.should == 1
end
it \'cannot go to escrow if another escrow is open\' do
p = Factory :property,:state => \'active\'
p.escrow!
lambda { p.escrow! }.should raise_error
end
it \'can go to escrow if prevIoUs escrows are canceled\' do
p = Factory :property,:state => \'active\'
p.escrows.create
p.reload
p.escrows.first.update_attribute :state,\'canceled\'
lambda { p.escrow! }.should_not raise_error
end
end
describe \'expire!\' do
%w(active).each do |state|
it \"transitions to expire from #{state}\" do
p = Factory :property,:state => state
lambda { p.expire! }.should_not raise_error
end
end
%w(escrow close cancel pending).each do |state|
it \"cannot transition to expire from #{state}\" do
p = Factory :property,:state => state
lambda { p.expire! }.should raise_error
end
end
end
describe \'pending\' do
it \'has initial state pending\' do
Factory(:property).state.should == \'pending\'
end
%w(active close escrow expire cancel).each do |state|
it \"cannot transition to pending from #{state}\" do
p = Factory :property,:state => state
lambda { p.pending! }.should raise_error
end
end
end
end
describe \'Tags\' do
it { Factory(:property).tags.should == [] }
end
describe \'Validations\' do
end
end
失败
Failures:
1) Property Methods#current_escrow returns open escrow or none
Failure/Error: p.escrow!
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/models/property.rb:60:in `no_open_escrows\'
# ./spec/models/property_spec.rb:28:in `block (4 levels) in <top (required)>\'
2) Property State Transitions active! transitions to active from cancel
Failure/Error: lambda { p.active! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>\'
3) Property State Transitions active! transitions to active from escrow
Failure/Error: lambda { p.active! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>\'
4) Property State Transitions active! transitions to active from expire
Failure/Error: lambda { p.active! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>\'
5) Property State Transitions active! transitions to active from pending
Failure/Error: lambda { p.active! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>\'
6) Property State Transitions active! marks escrow reconciled and canceled if escrow -> active
Failure/Error: p.escrow!
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/models/property.rb:60:in `no_open_escrows\'
# ./spec/models/property_spec.rb:59:in `block (4 levels) in <top (required)>\'
7) Property State Transitions cancel! transitions to cancel from active
Failure/Error: lambda { p.cancel! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>\'
8) Property State Transitions cancel! transitions to cancel from escrow
Failure/Error: lambda { p.cancel! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>\'
9) Property State Transitions cancel! transitions to cancel from pending
Failure/Error: lambda { p.cancel! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>\'
10) Property State Transitions close! transitions to close from escrow
Failure/Error: lambda { p.close! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:87:in `block (5 levels) in <top (required)>\'
11) Property State Transitions escrow! transitions to escrow from active
Failure/Error: lambda { p.escrow! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:103:in `block (5 levels) in <top (required)>\'
12) Property State Transitions escrow! creates a new escrow object on escrow!
Failure/Error: p.escrow!
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/models/property.rb:60:in `no_open_escrows\'
# ./spec/models/property_spec.rb:117:in `block (4 levels) in <top (required)>\'
13) Property State Transitions escrow! cannot go to escrow if another escrow is open
Failure/Error: p.escrow!
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/models/property.rb:60:in `no_open_escrows\'
# ./spec/models/property_spec.rb:124:in `block (4 levels) in <top (required)>\'
14) Property State Transitions escrow! can go to escrow if prevIoUs escrows are canceled
Failure/Error: lambda { p.escrow! }.should_not raise_error
expected no Exception,got #<ArgumentError: wrong number of arguments (0 for 1)>
# ./spec/models/property_spec.rb:133:in `block (4 levels) in <top (required)>\'
Finished in 35.44 seconds
297 examples,14 failures,1 pending
Failed examples:
rspec ./spec/models/property_spec.rb:26 # Property Methods#current_escrow returns open escrow or none
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from cancel
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from escrow
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from expire
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from pending
rspec ./spec/models/property_spec.rb:57 # Property State Transitions active! marks escrow reconciled and canceled if escrow -> active
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from active
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from escrow
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from pending
rspec ./spec/models/property_spec.rb:85 # Property State Transitions close! transitions to close from escrow
rspec ./spec/models/property_spec.rb:101 # Property State Transitions escrow! transitions to escrow from active
rspec ./spec/models/property_spec.rb:114 # Property State Transitions escrow! creates a new escrow object on escrow!
rspec ./spec/models/property_spec.rb:122 # Property State Transitions escrow! cannot go to escrow if another escrow is open
rspec ./spec/models/property_spec.rb:128 # Property State Transitions escrow! can go to escrow if prevIoUs escrows are canceled
解决方法
错误在此功能中,在
self.escrows.open.empty
中:
def no_open_escrows
self.escrows.open.empty?
end
错误说:wrong number of arguments (0 for 1)
所以我想您已经在代管上定义了一个范围称为“ 7”?从该错误看来,该作用域现在期望使用一个您不提供的参数。否则,由于ѭ7是一个非常通用的名称,它与新版本中rails中的其他内容冲突吗?
希望这可以帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。