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

Reference iterative_factorial rather than recursive_factorial in spec #30

Merged
merged 1 commit into from Dec 1, 2022
Merged

Reference iterative_factorial rather than recursive_factorial in spec #30

merged 1 commit into from Dec 1, 2022

Conversation

davidrunger
Copy link
Contributor

Also, fix the RSpec expectation for the number of #iterative_factorial method calls, since RSpec does not support specifying a certain number of method calls (in this case, a number of method calls greater than or equal to two) with negative message expectations.

Prior to this change, even after implementing #iterative_factorial correctly, the Ruby/spec/iterative_factorial_spec.rb specs would still fail with these error messages:

Failures:

  1) iterative_factorial
     Failure/Error: specify { expect(recursive_factorial(0)).to eq(1) }

     NoMethodError:
       undefined method `recursive_factorial' for #<RSpec::ExampleGroups::IterativeFactorial "example at ./spec/iterative_factorial_spec.rb:4">
     # ./spec/iterative_factorial_spec.rb:4:in `block (2 levels) in <top (required)>'

[...]

  5) iterative_factorial does not call itself
     Failure/Error:
       expect(self).to_not receive(:iterative_factorial)
         .at_least(:twice).and_call_original

     RuntimeError:
       `count` is not supported with negative message expectations
     # ./spec/iterative_factorial_spec.rb:10:in `block (2 levels) in <top (required)>'

Finished in 0.03218 seconds (files took 0.42977 seconds to load)
5 examples, 5 failures

With this change, the specs all pass when #iterative_factorial has been implemented correctly.

SPOILER: click to see an implementation of #iterative_factorial
def iterative_factorial(number)
  product = 1
  (2..number).each do |factor|
    product *= factor
  end
  product
end

Also, fix the RSpec expectation for the number of method calls.
Copy link
Owner

@jaysonvirissimo jaysonvirissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🍰

Hope all is well buddy, thanks for the contrib. 🙏🏼

@jaysonvirissimo jaysonvirissimo merged commit bd8fd1c into jaysonvirissimo:master Dec 1, 2022
@davidrunger davidrunger deleted the fix-iterative_factorial-spec branch December 1, 2022 06:15
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

Successfully merging this pull request may close these issues.

None yet

2 participants