【发布时间】:2012-01-04 16:31:38
【问题描述】:
我写了以下课程:
# This class is responsible for getting the data to create the sitemap
class City
attr_accessor :country_version, :directory, :country_host, :locale
def initialize(country_version, directory, country_host,locale)
@country_version = country_version
@directory = directory
@country_host = country_host
@locale = locale
end
def get_data
::City.find_each(:conditions => {:country_version_id => @country_version.id}) do |city|
I18n.locale=(@locale)
yield entry(city)
end
end
private
def entry(city)
{
:loc => ActionController::Integration::Session.new.url_for(
:controller => 'cities',
:action => 'show',
:city_name => city.name,
:host => @country_host.value),
:changefreq => 0.8,
:priority => 'monthly',
:lastmod => city.updated_at
}
end
end
我正在使用 RSpec 为这个类编写规范。到目前为止,我的规范涵盖了访问器方法和构造器。然而,当涉及到更复杂的方法get_data 时,我迷失了方向。有人可以给我一些提示,我可以如何解决为该方法编写规范的问题吗?
【问题讨论】:
-
这个问题最好在codereview.stackexchange.com结束。
-
@gikian 他的意思是 codereview.stackexchange.com 上的问题会更好,这明确意味着编码风格/完整性的问题。
-
@Dave Newton:从他的最后一个问题(他删除并创建了这个新副本)看来,他似乎不想知道他的规范是否完整,而是他如何真正为
get_data方法。 -
@gikian 您能否添加您正在使用的 Ruby 和 Rspec(可能还有 Rails)的版本?无论问题如何,这类信息几乎总是相关的。
标签: ruby-on-rails ruby unit-testing testing rspec