On Aug 3, 2011, at 11:08 AM, Piter Fcbk wrote:

> I'm trying to have most of the important stuff tested and in order to do that 
> I run in front of some stuff I'm not quite sure which is the best way to test 
> them.
> At this time I am having question around how to test modules and the custom 
> validators (the typical email format validator for example).
> 
> To test a module the best I saw up to now was finded here: 
> http://stackoverflow.com/questions/512466/how-to-implement-an-abstract-class-in-ruby
> In the before he creates a new class and import the module to test, Then, 
> using the class created, he test the module methods.
> Is this the recommended way to go?
> 
> About testing validators I guess something like what was done with the models 
> could also work but again not sure if its the way to go or if its totally 
> wrong.
> 
> Some advices on this matters will be really appreciated,
> 
> Thanks in advance.

I usually like to do something like:

describe MyModule do
  let(:object) { Class.new { include MyModule } }

  it "does something" do
    object.method_from_my_module.should do_something
  end
end

HTH,
David



_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to