Friday, March 13, 2015

Rails test helper for stubbing a constant

When Googling for how to mock or stub a constant in your Rails test suite, I found out about RSpec's stub_const method. I don't use RSpec though, so I wrote this.

The way I use it is to include it in ActiveSupport::TestCase somewhere in test/test_helper.rb.

class ActiveSupport::TestCase
  include WithStubbedConst
  ...
end

No comments: