`
wangxin0072000
  • 浏览: 86841 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ruby rspec mock study

    博客分类:
  • ruby
阅读更多
describe "Mocker" do

  it "should be able to call mock()" do
    mock = mock("poke me")#创建一个mock对象
    mock.should_receive(:poke).once.with(1,2,3)#测试这个对象是否会接收一次poke方法
    mock.poke(1,2,3)
    #test the arg type
    mock.should_receive(:msg).with(an_instance_of(Fixnum))
    mock.msg(2)
  end
#测试mock对象接收方法的顺序
  it "should fail when messages are received out of order" do
    mock = mock("one two three")
    mock.should_receive(:one).ordered
    mock.should_receive(:two).ordered
    mock.should_receive(:three).ordered
    mock.one
    mock.two
    mock.three
  end
end

 之后运行

rspc file_name
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics