I am pretty new to RSpec and I wonder if some code I have written is
leading me in the right direction. Any advice is greatly appreciated!
As a beginner exercise, this code looks perfectly functional to me.
But I believe you left out the interesting parts:
Which did you write first? The spec or the implementation?
Is the behavior description, “it should perform calculations,” clear
and precise? If I didn’t have access to the code, would I be able to
read that description and know something useful about the class’s
behavior?
Why did you choose the method name “equation”? If I simply knew
that name, would I be able to tell what that method does?
What is it you really want this class to do? Does the
specification help you verify that it acts according to your
intention?
Why do you want it to do that? (Okay, granted, this may be more of
a Cucumber question than an RSpec question.) >8->
I wrote the spec first and then the implementation. I think I could
have written a better behavior description. I don’t think the method
name is as good or specific as it could be. I just wanted the class to
be able to add two numbers… so maybe the specification could reflect
that more… and I want the class to add two numbers because I wanted
to practice using rspec and figured a simple program would be good to
start out with.
Calvin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.