`
zzhang
  • 浏览: 17329 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

example how to use 'stub' and 'mock' in sepc

阅读更多

Use sometime to learn stub and mock.

I think below is a good example:

 

code:

    def create_from_content(content)
      page_content = PageContent.new(content)
      templet = page_content.templet
      templet_id = page_content.templet_id
      page_title = page_content.page_title
      #OPTIMIZE
      Page.update_all("title = '#{escape_single_quotes(page_title)}', templet_id='#{templet_id}'", "id=#{self.id}" )
      self.page_parts.create_from_content(page_content.content_without_title, templet)
      self.reload
      return self
    end

 

test:

  describe "create_from_content" do 
    it "should create page's atrributes from content" do 
      page = Page.create
      page_content = mock(PageContent, :templet_id => 1, :page_title => "page_title", :content_without_title => "content_without_title", :templet => "templet")
      PageContent.stub!(:new).with("content").and_return(page_content)
      page.stub!(:escape_single_quotes).with("page_title").and_return("page_title")
      page.page_parts.stub!(:create_from_content).with("content_without_title", "templet").and_return(nil)
      page.create_from_content("content").should == page
      page.title.should == "page_title"
      page.templet_id.should == 1
    end
  end
 

 

0
0
分享到:
评论

相关推荐

    Mockito Essentials(PACKT,2014)

    this book will provide you with the skills you need to successfully build and maintain meaningful JUnit test cases and effectively mock external dependencies. At the beginning, this book deals with ...

    Jeek - stub and mock generator for .NET-开源

    Jeek是一个针对.NET平台的专业工具,它专注于生成类、存根(stub)和模拟(mock)代码,极大地简化了单元测试的过程。在软件开发中,尤其是采用敏捷开发方法时,单元测试是确保代码质量、可维护性和可靠性的重要环节...

    mocha, mocha 是用于 ruby的mock和stub库.zip

    mocha, mocha 是用于 ruby的mock和stub库 mocha 描述用于模拟和stub的ruby 库。完整的。简单的和可以读的语法,完全&部分模拟。内置支持MiniTest和 Test::Unit 。由许多其他测试框架支持。安装 gem使用以下

    Stub:灵活的Stub包装器,用于PHPUnit的Mock Builder

    可以使用Codeception\Stub静态调用来构造Codeception\Stub : <?php // create a stub with find method replaced $ userRepository = Stub :: make ( UserRepository ::class, [ 'find' => new User ]); $ ...

    cpp-stub 开源代码

    在这个特定的案例中,`cpp-stub` 存在一个在ARM平台上运行时的BUG,当尝试使用 `stub.h` 中的 `reset` 方法时,会触发段错误(Segmentation Fault),这是一个严重的问题,因为它会导致程序崩溃。 首先,我们来理解...

    cmd-comand,use command to debug your code in linux environment,it's a useful tool for linux programmer

    cmd-comand,use command to debug your code in linux environment,it's a useful tool for linux programmer.you can add stub in your code and run the cmd tool to debug it.

    cpp-stub 中文使用手册

    单元测试打桩开源库 cpp-stub 使用手册 中文版本,这是从git上直接下载的,git上下载的源代码在arm上调用Stub.reset方法会引发段错误,在资源cpp-stub开源代码(下载地址:...

    使用axis1生成stub客户端样例

    本示例将详细介绍如何使用Axis1生成Stub客户端,以便与Web服务进行交互。 首先,让我们理解什么是Stub客户端。Stub是模拟服务器行为的本地代理,它允许客户端代码在没有实际连接到服务器的情况下进行测试或调用服务...

    VclZip pro v3.10.1

    and ways to use VCLZip that you should always test VCLZip completely in your application before deploying. *** New Zip64 capabilities, properties, methods and events: - Uncompressed, Compressed, ...

    gtest stub 详细用法,附件用例,链接

    gtest stub 详细用法,附件用例,链接

    webmock, 在 ruby 中,对HTTP请求的stub和设置期望的库.zip

    webmock, 在 ruby 中,对HTTP请求的stub和设置期望的库 WebMock 在 ruby 中对HTTP请求进行存储和设置期望的库。特性在低HTTP客户机库级别的Stubbing请求( 在更改HTTP库时不需要更改测试)设置和验证HTTP请求的期望...

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    Along the way, it covers how to embed the WebKit Web browser in your application, how to have your application use data from other installed applications (and vice versa!) or off the Internet, and ...

    [PE变形]拓展STUB

    标题中的“[PE变形]拓展STUB”是指在PE(Portable Executable)文件格式中,对可执行文件的STUB部分进行变换的技术。PE文件格式是Windows操作系统中用于存放应用程序和动态链接库的主要格式。STUB,即Stub Section,...

    Android应用:StubView显示与隐藏

    在Android应用开发中,`StubView`是一种非常实用的组件,它允许我们在程序运行时动态地加载布局。在本文中,我们将深入探讨如何在Android应用中实现`StubView`的显示与隐藏,以及相关的源代码实践。 首先,`Stub...

    com.stub.StubApp.apk

    com.stub.StubApp.apk

    sip-4.15.5.zip

    This applies both to the development of new components so that they can be reused in the future in a different context, and to the reuse of existing components that were developed independently of ...

Global site tag (gtag.js) - Google Analytics