Rails helper testing cheatsheetEdit

Created , updated

Tools

Mocking and stubbing

Although helper methods are mixed into the example group itself:

describe FooHelper do
  describe '#funky_method' do
    it 'returns true' do
      funky_method.should be_true
    end
  end
end

If you need to set up mock expectations you will need to use the explicit helper instance that is available inside example groups:

it 'delegates to #foo_method' do
  mock(helper).foo_method
  helper.funky_method
end

Related