我是测试Rails web应用程序和RSpec的新手.我使用遗留代码,需要添加测试.那么,用RSpec测试查找程序和命名作用域的最佳方法是什么呢?
我在谷歌找到了一些方法,但并不理想.
http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-rails
it "excludes users that are not active" do
@user = Fact或y(:user, :active => false)
User.active.should_not include(@user)
end
或
http://h1labs.com/notebook/2008/8/21/testing-named-scope-with-rspec
it "should have a published named scope that returns ..." do
Post.published.proxy_options.should == {:conditions => {:published => true}}
end
我在"铁路测试处方"中找到了最佳方法(IMHO):
should_match_find_method :active_only { :active == true }
其中should_match_find_method
个自定义助手方法