Skip to content

Instantly share code, notes, and snippets.

@bengm
Last active December 14, 2015 13:28
Show Gist options
  • Save bengm/5093104 to your computer and use it in GitHub Desktop.
Save bengm/5093104 to your computer and use it in GitHub Desktop.
This is how I got my first set of fast tests running. There are probably a dozen ways to do it better, but this worked for me. I wanted to test some rails helper methods that had simple interfaces and no dependency on rails. Here's how I finally got it working.
# spec/helpers/my_helper_spec.rb
# note: must replace references to my_helper/MyHelper to appropriate name
# require any dependencies - I needed date/time so just included all of active support
require 'active_support/all'
# require the specific helper module
require_relative "../../app/helpers/my_helper.rb"
class DummyClass
end
describe MyHelper do
before(:each) do
@helper = DummyClass.new
@helper.extend(MyHelper)
end
it "should return something" do
@helper.some_method.should eq "something"
end
# ... more tests
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment