This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/red-green-refactor-by-example
initialize misspelled in your exercise code.
Thanks for reporting! We updated it this morning, apologies for the typo.
I see now that the exercise system (feedback system) is not used here. So it’s safe to assume we post a repo link on the forum to get our code reviewed?
Hey @iamarmanjon, sorry for the confusion here. The exercise included in this video’s notes is intended to provide a structure for you to try out TDD easily, but it is not an exercise in the traditional sense where the solution is the focus.
Instead, the focus is on the process. We wanted to provide a first TDD problem for you to get comfortable with the TDD workflow, taking small steps, working on each failure one at a time, etc. That said, the end result (the final spec suite and implementation) are not expected to be very interesting or different between users. Again, the process is the focus here, not the solution.
As such, we chose to provide this as part of the notes, rather than using the exercise system. That said, step 4 in the trail is a full blown exercise using our Git system where you’re asked to refactor a spec file. In that case the solution is interesting, and thus we use the exercise system.
Sorry for the confusion here, but hopefully the above clears things up. Let us know if you have any more questions.
describe Calculator do
describe “#add” do
it “returns the sum of its two arguments” do
calc = Calculator.new
expect(calc.add(5, 10)).to eq(15) end
Unable to run the first test (3min 52) due to the following error
require': cannot load such file -- rspec/autorun (LoadError) from /Users/neilpatel/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire’
@neilp666 it sounds like you might not have the rspec gem installed. You can run the following at the command line to confirm:
gem search rspec --local
Sometimes I just need a simple example like this to get me back into focusing more on the process of TDD. More often than not I drift away from a strict TDD process to a process that sometimes has tests written after the fact.
This is my solution for the exercise
Here is my attempt. I’m still learning Ruby.
wrong number of arguments (given 3, expected 0) issue on line 17, which is the
initialize method. The initialiser itself, along with whole spec, was copied and pasted from the show notes:
def initialize(first_name:, middle_name: nil, last_name:) @first_name = first_name @middle_name = middle_name @last_name = last_name end
And actual failure happens when I am creating new
Person like so:
person = Person.new("Askhat", "Maratovich", "Bikmetov")
I’m pretty sure the elephant is in the room, but could anyone point me on it?
ruby -v 2.3.1
rspec -v 3.5.3
I believe the issue here is your
initialize expects keyword arguments, while your usage is passing positional arguments. So instead of the
Person.new as you have it, you’ll want to do:
# note: only breaking across lines for readability person = Person.new( first_name: "Askhat", middle_name: "Maratovich", last_name: "Bikmetov" )
Note: We have a Weekly Iteration on Ruby Keyword Arguments if you want to brush up.
You won’t believe how stupid I’m feeling right now, named arguments, obviously. Much obliged!
BTW ruby could be little more articulate on this, instead of
wrong number, don’t you think?
I’m always in favor of better error messages
Here’s my attempt to solving this: https://gist.github.com/boddhisattva/ea7194d749ad891dcc8b76e0d8549e3a . Happy to receive any feedback to improve this further.