[rspec-users] What should I test/specify?

Andrew Wagner wagner.andrew at gmail.com
Sat Oct 30 22:35:51 EDT 2010

On Sat, Oct 30, 2010 at 9:54 PM, Andrew Premdas <apremdas at gmail.com> wrote:

> On 30 October 2010 14:40, Andrew Wagner <wagner.andrew at gmail.com> wrote:
>> Ok, so here's the scenario. I have a top-level module, with a method
>> called load_file. It should take a file name, get the YAML module (Syck) to
>> parse it, and then send the result to a class, which should convert that
>> result into a series of objects.
>> I'm not sure what specs, if any, I should write for load_file. I can get
>> into the nitty gritty details of exactly what methods it should be calling,
>> but that seems brittle. I can skip all that and just make assertions about
>> the final series of objects, but I'd rather put those specs on the class
>> that's actually doing the conversion.
>> Suggestions? Here's the code that I (think I) want to drive out:
>> module BTree
>>   def self.load_file file_name
>>     raw = YAML::load_file file_name
>>     tree = BehaviorTreeCreator.new(raw).create
>>   end
>> end
> Its not obvious what specs to write for load_file because load_file is
> poorly named. It does far more than load a file. If you write your  specs
> for load file and read them, they won't make sense e.g.
> load_file should use YAML  (why should it use YAML, and what happens if the
> file isn't YAML
> load_file should create a behaviour tree (why should it create a TREE)
> Perhaps BTree only needs a yaml_to_tree, and you can pass the yaml into the
> method. If this was the case you might spec the following:
>   what happens if you pass invalid YAML
>   what happens if you pass valid YAML
>   what happens if you pass nothing
> Generally if a method is hard to spec, then its smelly, there is something
> wrong with it, it needs work
> Andrew
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

An interesting perspective. The purpose of the behavior tree module is to
provide a simple, standard way to represent behaviors in a plain-text
format. I'm borrowing YAML because it seems like a good, lightweight
approach. I'm using load_file (and load) to mirror YAML::load_file (and
YAML::load). I'll definitely take some of your ideas into consideration,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101030/87e79cb4/attachment-0001.html>

More information about the rspec-users mailing list