RSpec cheatsheet

作者: 邹小创 | 来源:发表于2016-02-28 16:09 被阅读75次

    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

    相关文章

      网友评论

        本文标题:RSpec cheatsheet

        本文链接:https://www.haomeiwen.com/subject/xmzwkttx.html