Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Featured solution uses expect instead of allow as per what's suggested in the README #4

Open
boddhisattva opened this issue Dec 13, 2018 · 1 comment

Comments

@boddhisattva
Copy link

boddhisattva commented Dec 13, 2018

Dear Project Collaborators,

I see that the featured solution is using expect instead of allow for the simple stub based on the code present here and here. The README of this project recommends using allow for stubs so would really appreciate if you could clarify on what's the correct thing to use for this exercise so that one could have a clear differentiation between when to use allow and when to use expect.

From what I've learnt in general, we use expect when we mutate data or for command methods in general and we use allow for query methods. It would be great if you could share your thoughts on what's more appropriate here and why you think that either of expect or allow is the more appropriate one in the context of this exercise, Thank you.

@yagosansz
Copy link

yagosansz commented Aug 20, 2023

I think using expect feels weird because we have an expectation being defined in the setup phase of the test. I have used allow instead:

it "returns posts created today" do
  # setup
  posts = double("posts")
  dashboard = Dashboard.new(posts: posts)
  allow(posts).to receive(:today).and_return(posts)

 # exercise
  result = dashboard.todays_posts

  # verify
  expect(result).to eq(posts)
end

The only way to get dashboard.todays_posts to equal result is if #today is called on posts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants