I created a following rspec mock which runs fine but i get the warning when i execute it.
Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. called from /file/path.rb:26:in `block (3 levels) in <top (required)>'.
Here is my unit test. Line 26 is user_health_condition.stub(:user_condition_flag) do |user_id|
in my unit test. Per warning i am using expect so why i am getting this warning?
describe '.user_condition_flag' do
let(:expected_result_with_diabetes) { 'Y' }
let(:expected_result_without_diabetes) { 'N' }
let(:user_id_1) { 38 }
let(:user_id_2) { 39 }
context 'with entries in table' do
it 'returns expected results' do
user_health_condition = double(user_health_condition)
allow(user_health_condition).to receive(:user_condition_flag).and_return(expected_result_with_diabetes)
user_health_condition.stub(:user_condition_flag) do |user_id|
if user_id == :user_id_1
'Y'
elsif user_id == :user_id_2
'N'
end
end
expect(user_health_condition.user_condition_flag(:user_id_1)).to eq(expected_result_with_diabetes)
expect(user_health_condition.user_condition_flag(:user_id_2)).to eq(expected_result_without_diabetes)
end
end
end
To elaborate on @Brad's answer with specifics in case the link dies at one point
allow(User).to receive(:find_by).and_return(user)
instead of this:
User.stub(:find_by).and_return(user)
Replace
user_health_condition.stub(:user_condition_flag) do
With
allow(user_health_condition).to receive(:user_condition_flag) do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With