gpt4 book ai didi

ruby-on-rails - 如何测试示波器?

转载 作者:行者123 更新时间:2023-12-03 13:55:27 24 4
gpt4 key购买 nike

试图找到但没有成功。我只是想知道如何在Rails 3中测试示波器。

可以使用rspec,shoda或仅使用测试单元。

谢谢。

实际上,我尝试过这种方式,但是由于它仍然需要放置order()方法,因此它并不是完整的测试。

范围:

scope :recents_available, where(:available => true, :locked => false).order("created_at DESC")

describe Job, ":recents_available" do

it "should have the scope" do
Job.should respond_to(:recents_available)
end

it "should include recents jobs that are available and unlocked" do
@job = Factory(:job, :available => true, :locked => false )
Job.recents_available.should include(@job)
end


结束

最佳答案

David Chelimsky(Rspec的创建者)在Rspec Google Group中提供了以下示例:

describe User, ".admins" do 
it "includes users with admin flag" do
admin = User.create! :admin => true
User.admin.should include(admin)
end

it "excludes users without admin flag" do
non_admin = User.create! :admin => false
User.admin.should_not include(non_admin)
end
end

class User < ActiveRecord::Base
named_scope :admins, :conditions => {:admin => true}
end


显然这与您的示例不同,但是它应该使您知道如何执行此操作。上下文的相关线程在这里: http://groups.google.com/group/rspec/browse_thread/thread/6706c3f2cceef97f

关于ruby-on-rails - 如何测试示波器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com