我试过如下:Rspec中'let'的范围是什么?
describe "#check_recurring_and_send_message" do
let(:schedule) {ScheduleKaya.new('test-client-id')}
context "when it is 11AM and recurring event time is 10AM" do
schedule.create_recurring_event('test-keyword', 'slack', 'day', '10 AM')
it "sends an SMS" do
end
it "set the next_occurrence to be for 10AM tomorrow" do
tomorrow = Chronic.parse("tomorrow at 10AM")
expect(schedule.next_occurrence).to eq(tomorrow)
end
end
end
我周围范围的错误:
`method_missing': `schedule` 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)
不仅为这个例子,但是其他时间,我不完全明白什么是允许的scope
是让和在Rspec中创建实例。
let
这里的用例与我只用schedule = blah blah
创建的用例有什么区别?
我想我明白字面意图的错误:我不仅可以在it.
使用context
schedule
但是,什么是正确的做法,然后用这个例子来把东西下介绍,背景,或者用什么方式?
谢谢。我觉得这很有道理。所以我可以在上下文中使用let块吗?我不仅限于'它'块。 – Angela
只应该用于描述层面吗? – Angela
您不能在块前使用'let'。它位于示例之外的描述块或嵌套描述块中。 ''之前'块中的代码在与示例相同的上下文中运行。 – zetetic