Noob needs help knowing where to test

33 views
Skip to first unread message

leam hall

unread,
Jun 2, 2015, 3:16:28 PM6/2/15
to rs...@googlegroups.com
I'm slowly learning OOP and testing. Trying to figure out where to put tests in a small program I'm writing and could use your advice.

https://github.com/LeamHall/CT_Character_Generator

For anyone familiar with the Traveller RPG, this generates NPCs for a variety of career types. I want to add more but would like to get some rspec and maybe cucumber in before it gets too big.

Thanks!

Leam

Carlos Figueiredo

unread,
Jun 3, 2015, 8:07:45 AM6/3/15
to rs...@googlegroups.com
You are doing a nice job on https://github.com/LeamHall/CT_Character_Generator/blob/master/spec/lib/character_spec.rb . The tests look like as telling a history about character.rb, and what to expect from that class. There are some mistakes on using RSpec and ruby at all, but in essence they are really nice.

Firstly mistake I noticed, are not related with RSpec, but how you are writing Ruby. And I think you must read more how attr_writter, attr_accessor, attr_reader works and when use them... 
A good start can be http://ruby-doc.com/docs/ProgrammingRuby/html/tut_classes.html#S2 and http://ruby-doc.com/docs/ProgrammingRuby/html/ref_c_module.html#Module.attr_accessor

On your test, the first thing I noticed, was that you need to use the RSpec expectations syntax to test. Actually, I noticed that some tests are using its syntax (at least its old syntax... 'should') but the beginning of your tests are using nothing but '=='.
 
or even the README on its source code here https://github.com/rspec/rspec-expectations

There are more issues, but I think that a good start would be invest a time reading more about how define attributes on your class, and about rspec-expectations. Then, I'm sure you can figure out more improvements, they are mostly related to ruby best practices.

Talking about best-practices... on http://betterspecs.org you can get a bunch of advices about best practices on testing with RSpec, and on https://github.com/bbatsov/ruby-style-guide or you can get some advices concerning about best practices on writing Ruby code.

I hope that these advices can help you!
Best wishes,

Carlos Figueiredo

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/d3c5d686-7045-42c9-9707-706716c5511f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

leam hall

unread,
Jun 4, 2015, 1:52:29 PM6/4/15
to rs...@googlegroups.com
Carlos, thanks!  I'm off to read....

Leam

leam hall

unread,
Jun 27, 2015, 11:20:59 AM6/27/15
to rs...@googlegroups.com
I've changed the 'should' phrases to "expect", and added tests for each class. Still working on better test coverage, though. Learning Rspec.

Is there a way to have the test run an action several times and test each one? For example, "run this context 100 times and ensure every time the random number is within bounds". That would let you test random things lots of times in the same test run, to see if your counting or whatever is off.

Reply all
Reply to author
Forward
0 new messages