English 中文(简体)
RSpec - 如何利用回击来测试属性违约值
原标题:RSpec - how to test default value for attribute using callback

我在此检验:

require  spec_helper 

describe League do

    it  should default weekly to false  do
      league = Factory.create(:league, :weekly => nil)
      league.weekly.should == false
    end
  end

end

我的模式如下:

class League < ActiveRecord::Base

  validates :weekly, :inclusion => { :in => [true, false] }

  before_create :default_values

  protected

  def default_values
    self.weekly ||= false
  end

end

When I run my test, I get the following error message:

 Failure/Error: league = Factory.create(:league, :weekly => nil)
 ActiveRecord::RecordInvalid:
   Validation failed: Weekly is not included in the list

我尝试了两种不同的办法,试图制造一个模棱两可的记录,引发back击,但我有 t。 在使用RSpec进行测试时,我没有什么东西?

问题回答

我认为,你所说的话在制造之前是每周制造假,然后实际上每周制造 sets,掩盖假。

正义

require  spec_helper 

describe League do

    it  should default weekly to false  do
      league = Factory.create(:league)  # <= this line changed
      league.weekly.should == false
    end
  end

end

页: 1 无需明确规定。





相关问题
Calling a service from a callback method in Client

I have a scenario where, upon receiving a command on one of the callback methods in client, the client needs to call another service. For example: In OnNewCommand() callback method client receives a ...

ASP.NET UpdatePanel Javascript Callback

I came across this issue recently and thought it was really helpful. My question was, how would you call a piece of javascript after an updatepanel loads via AJAX in ASP.NET? I needed to reinitialize ...

WCF duplex channel gets closed when using callbacks

My WCF service uses netTcpBinding, and has a callback object. I need to service multiple concurrent clients, and mantain sessions, so the service is decorated with [ServiceBehavior(...

C++: static function wrapper that routes to member function?

I ve tried all sorts of design approaches to solve this problem, but I just can t seem to get it right. I need to expose some static functions to use as callback function to a C lib. However, I want ...

getJSON callback not happening

I have looked at similar queries here, but I can t seem to apply them to my problem. I am pretty new to jquery, so I may be doing something dumb. I have a simple getJSON test: $(document).ready(...

热门标签