RSpec cheatsheet
2016-02-28 本文已影响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 namedhuman?
, 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