I'm seeing different behavior between the two expect
syntax formats in Rspec:
expect(subject).to ...
versus
it { is_expected.to ... }
This works...
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
However this does not...
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
The error I am getting:
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)>'
What gives?
is_expected
will be introduced in RSpec 3.0.0.beta2. It's only available from github master at this point.