describe,it和def in ruby​​,rspec之间的区别

时间:2015-11-12 14:10:45

标签: ruby rspec

我是rspec的新手。通过教程,我陷入困境。 当我使用WATIRcucumber框架时,我从未见过describeit

那么差异是什么?什么时候用?

1 个答案:

答案 0 :(得分:2)

描述用于解释正在进行的工作。通常,您将描述一个类,它将包围所有it个调用。 it是在describe块内执行的测试用例:

describe Foo do
  it "will return true" do
    expect(Foo.bar).to eq(true)
  end

  it "will return false" do
    expect(Foo.baz).to eq(false)
  end
end

# When run, rspec output is:
Foo
  will return true
  will return false

在上述情况中,it方法描述了barbazFoo类上的运作方式。 A good read is the rspec documentation on this.

相关问题