Skip to content

Instantly share code, notes, and snippets.

@anlek
Created March 28, 2014 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anlek/9823321 to your computer and use it in GitHub Desktop.
Save anlek/9823321 to your computer and use it in GitHub Desktop.
How to run tests as if CanCan was loaded into the system.
before(:all) do
module CanCan; end
end
# ... test as if CanCan exists
after(:all) do
Object.send(:remove_const, :CanCan)
end
@anlek
Copy link
Author

anlek commented Mar 28, 2014

This might not be the best idea, seems the better idea would be:

module MyGem
  def self.using_cancan?
    Object.const_defined?(:CanCan)
  end
end

and in the test, just stub out MyGem.stub(:using_cancan?).and_return true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment