RSpec cheatsheet

RSpec cheatsheet
�RSpec 是Ruby的一个测试框架,以下是它的一些常用法cheatsheet,留个备份,容易查找。

  • RSpec的基本结构:
RSpec.Describe "hello world" do
    it "should do something" do
        expect(something).to be true
    end
    
    context "a context to group together tests" do
        it "another test" do
            expect(dfkad).to be false
        end
    end
end
  • before:
before(:each) do
    #code that will be called once before each test
end
  • before all:
before(:all) do
    #code that will be called before all tests run
end
  • If some object obj has a method named human?, then you can use:
    expect(obj).to be_human

  • eq and equals: eq will compare value, equal will compare object identity
    eq: expect(a).to eq b
    equal: expect(a).to equal b

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容