[rspec-users] Need help testing a module behavior with RSpec

Sean Schofield sean.schofield at gmail.com
Mon Jul 14 09:13:57 EDT 2008

I have a resource_security.rb file that includes instance and class
method definitions.  At the end of the file I mix these into

ActiveRecord::Base.class_eval { include ResourceSecurity::InstanceMethods }
ActiveRecord::Base.class_eval { extend ResourceSecurity::ClassMethods }

I've had limited success testing using the following approach

    @resource = mock("ActiveRecord::Base")
    @resource.class.class_eval { extend ResourceSecurity::ClassMethods }
    @resource.class.class_eval { include ResourceSecurity::InstanceMethods }

The problem is that I want to test the behavior of a security related
instance method using different assumptions about the value of
access_hash (a class method).   Any suggestions on how to best test

Its also possible that my actual code solution is less then ideal.
The basic concept is that you can have statements like this in your

allow :show, %w{admin team_lead}

Each model is in charge of evaluating whether or not the current user
has access (which is why I was thinking in terms of a class level
access hash.)

Anyways, any suggestions on how to test this would be greatly appreciated.



More information about the rspec-users mailing list