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

spec tips(keep adding)

阅读更多

1.stub meet "one to many" relationship

 

Here is the code:

describe "original_content" do
    it "should generate page_group's original_content" do 
      page_group = PageGroup.create
      page1 = page_group.pages.create
      page1.stub!(:content).and_return("page1 content")
      page2 = page_group.pages.create
      page2.stub!(:content).and_return("page2 content")
      page3 = page_group.pages.create
      page3.stub!(:content).and_return("page3 content")
      page_group.stub!(:pages).and_return([page1, page2, page3])
      page_group.original_content.should == "page1 content\n\n===\n\npage2 content\n\n===\n\npage3 content\n\n"
    end
end

kind of ugly.

This page_group.stub!(:pages).and_return([page1, page2, page3]) is the way I found to solve stub when have "one to many" relationship.

Is there a better way to do this, and how to refator the duplication?

 

2. params in stub

PreparationPage.stub!(:create_from_content).with("part1").and_return(page1)
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics