我在Rspec中看到两种expect
语法格式之间的不同行为:
expect(subject).to ...
与
it { is_expected.to ... }
这有效......
describe ApplicationController
controller do
def index() render nothing: true end
end
before { get :index }
describe "success flash message" do
subject { flash[:success] }
it "should be nil" do
expect(subject).to be_nil
end
end
end
然而,这不是......
describe ApplicationController
controller do
def index() render nothing: true end
end
before { get :index }
describe "success flash message" do
subject { flash[:success] }
it { is_expected.to be_nil }
end
end
我得到的错误:
1) ApplicationController handling flash messages
Failure/Error: it { is_expected.to be_nil }
NameError:
undefined local variable or method `is_expected' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x00>
# ./spec/some/file.rb:123:in `block (3 levels) in <top (required)>'
是什么给出了?
答案 0 :(得分:3)
is_expected
将在RSpec 3.0.0.beta2中引入。它只能从github master那里获得。
答案 1 :(得分:1)