ruby – 如何更改RSpec描述块的模块上下文?
发布时间:2020-12-17 02:35:15 所属栏目:百科 来源:网络整理
导读:我有一个针对多个模块级别的对象的规范.像这样的东西: describe Foo::Bar::Baz::Quux::Widget do it "should == another Widget for the same Doohickey" do doohickey = stub Foo::Bar::Baz::Quux::Widget.new(doohickey).should == Foo::Bar::Baz::Quux::
我有一个针对多个模块级别的对象的规范.像这样的东西:
describe Foo::Bar::Baz::Quux::Widget do it "should == another Widget for the same Doohickey" do doohickey = stub Foo::Bar::Baz::Quux::Widget.new(doohickey).should == Foo::Bar::Baz::Quux::Widget.new(doohickey) end it "should != another Widget for a different Doohickey" do one_doohickey = stub another_doohickey = stub Foo::Bar::Baz::Quux::Widget.new(one_doohickey).should == Foo::Bar::Baz::Quux::Widget.new(another_doohickey) end end 这是很多重复,它使我看起来像是在使用一个对象 module Foo::Bar::Baz::Quux describe Widget do it "should == another Widget for the same Doohickey" do doohickey = stub Widget.new(doohickey).should == Widget.new(doohickey) end it "should != another Widget for a different Doohickey" do one_doohickey = stub another_doohickey = stub Widget.new(one_doohickey).should == Widget.new(another_doohickey) end end end 只有一个问题.因为我在Rails,我依赖 如何在不定义的情况下更改规范的常量查找上下文 解决方法
你可以使用describe_class助手……
describe Foo::Bar::Baz::Quux::Widget do it "has described_class helper" do described_class.should == Foo::Bar::Baz::Quux::Widget end end 或者,对于lol: describe Foo::Bar::Baz::Quux::Widget do def Widget described_class end it "has described_class helper" do Widget.should == Foo::Bar::Baz::Quux::Widget end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 优化foreach循环
- Oracle 11g中管理员用户sys,system密码不可用解决办法
- c – 将共享指针传递给非拥有函数时的最佳做法是什么?
- ruby-on-rails – 如何使用elasticsearch和索引对象之间的关
- Swift学习笔记(十八)——字符串String.Index和Range详解
- 发布一个高性能的Reactor模式的C++网络库:evpp
- c# – LINQ Where()单管或双管/&符号
- ruby-on-rails – Ruby String的[]方法
- 《AJAX学习心得分享-------(三)AJAX+JSON无刷新加载大量后
- webpack react 打出独立的css文件