RSpec - WrongScopeError: expect is not available on an example group

RSpec - WrongScopeError: expect is not available on an example group

我收到这个错误:

method_missing': expect is not available on an example group (e.g. a describe or context block). It is only available from within individual examples (e.g. it blocks) or from constructs that run in the scope of an example (e.g. before, let, etc). (RSpec::Core::ExampleGroup::WrongScopeError)

对于此规范:

describe 'canary test' do
    expect(true).to be true
end

您需要将测试包装在一个块中,例如你可以:

describe 'canary test' do
  it 'it true' do
    expect(true).to be true
  end
end