iGE*_*GEL 1 rspec ruby-on-rails rspec2 ruby-on-rails-3
我写了一个类方法,它调用同一个类的其他类方法.
class Statistic
def self.do_something
#...
end
def self.update_statistic
Statistic.do_something
end
end
Run Code Online (Sandbox Code Playgroud)
我如何测试,update_statistic调用do_something?
我使用Rails 3和rspec 2.
您应该可以设置期望do_something然后update_statistic直接调用.
Statistic.should_receive(:do_something)
Statistic.update_statistic
Run Code Online (Sandbox Code Playgroud)