rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 356 forks source link

Is allow the best name? #1440

Closed maedi closed 2 years ago

maedi commented 3 years ago

I found allow hard to understand at first. Could an alias be alter?

pirj commented 3 years ago

Sure:

module Alter
  alias_method :alter, :allow
end

RSpec.configure do |c|
  c.include Alter
end

We keep GitHub issues for bugs and feature requests. Please consider using our mailing list (https://rspec.info/help/) and resources like StackOverflow. Thanks for understanding.

You shouldn't think of allow as altering. It does that underneath, but for the person reading the specs (yes, it is "specs", not "tests"), allow(user).to receive(:name).and_return('Bob') should sound exactly as it reads. With "alter" it doesn't read right.

maedi commented 2 years ago

I've been using allow a bit more and realised why it bugs me. It's because the word "allow" implies that the method will now do a new thing, but it will also continue doing the old thing too. But RSpec uses "allow" to limit/change/alter behaviour to just do the new thing. I still think it's just the wrong word for this. I don't follow the "alter doesn't read right" logic, can you give me more reasoning?

(I think this was just a template sentence, but RE "We keep GitHub issues for bugs and feature requests.".... this is a feature request)

JonRowe commented 2 years ago

(I think this was just a template sentence, but RE "We keep GitHub issues for bugs and feature requests.".... this is a feature request)

There was no concrete feature requested that could not be satisfied with plain Ruby (as Pirj demonstrated) and a philosophical debate about the meaning of words is best suited for the mailing list.