Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing nested modules with rspec and rails [duplicate]

Possible Duplicate:
Testing modules in rspec

Currently I am successfully testing my modules with rspec like so:

require 'spec_helper'

module Services
  module AppService
    describe AppService do
      describe "authenticate" do
        it "should authenticate the user" do
          pending "authenticate the user"
        end
      end
    end
  end
end

My modules live in app/services/services.rb app/services/app_service.rb

However is there a more elegant solution to testing my modules without having to declare the namespaces in the spec? I feel that it becomes tightly bound to my specs and making changes will cause a lot of headaches.

like image 237
Andre Dublin Avatar asked Oct 10 '12 18:10

Andre Dublin


1 Answers

Instead of duplicating AppServices, you can do:

module Services
  describe AppService do
  end
ene

Or:

describe Services::AppService do
end

I tend to prefer the former, because it allows me to not fully-qualify constant names in the spec (since everything is in the Services module, it'll look relative to that, first).

like image 151
Myron Marston Avatar answered Oct 07 '22 14:10

Myron Marston