There are several cases, where my specs always return true, making the test superfluous...
Take this Achievement
model for instance:
class Achievement < ActiveRecord::Base
has_many :stages
def call_name_method
name
end
def name
key
end
end
# for simplicity sake, I'm just testing a method which simply calls another method.
achievement_specs.rb
require 'rails_helper'
describe Achievement do
describe '#call_name_method' do
subject { achievement.call_name_method }
let(:achievement) { create(:achievement) }
it 'calls #name' do
expect(achievement).to receive(:name)
subject
end
end
end
This test succeeds, but I can change it to expect(achievement).to receive(:foobar)
and it will still succeed, although I am not calling foobar
.
According to this answer, it is the correct syntax, but it somehow never fails. Is this a bug?
I also tried using .to have_received(:call_name_method)
, but that results in this error:
1) Achievement#call_name_method calls #name Failure/Error: expect(achievement).to have_received(:call_name_method) # expected to have received call_name_method, but that object is not a spy or method has not been stubbed.