Hi Myron, thanks for your answer, I didn't know. So if it doesn't answer to that message, why it doesn't fail? Honestly I'm not sure I get it.
Here is another rspec that should cover a "real" call to a "real" method:
describe 'rivendell::get_account' do
let :run_rake_task do
Rake::Task["rivendell::get_account"].reenable
Rake.application.invoke_task "rivendell::get_account"
end
it 'should generate an api key' do
Rivendell::Models::Apikey.should_receive(:create)
run_rake_task
end
end
This is the rake task:
desc 'Setup a user account'
task get_account: :environment do
begin
if ENV['TOKEN'] && ENV['SECRET']
api_key = Rivendell::Models::Apikey.create(token: ENV['TOKEN'], secret: ENV['SECRET'])
else
api_key = Rivendell::Models::Apikey.create
end
puts "Account created: \n\tTOKEN: #{api_key.token} \n\tSECRET: #{api_key.secret}"
rescue => msg
puts "Something didn't work as expected: \n\t#{msg}"
end
end
If I change the call to Rivendell::Models::Apikey.should_receive(:sdhfkjshd) it still passes. Seems to me whatever I do
all my specs pass, which is great for my ego, not so much for my code ;)
TIA,
ngw