Skip to content

Instantly share code, notes, and snippets.

@dimroc
Last active May 4, 2018 02:29
Show Gist options
  • Select an option

  • Save dimroc/60b9f419f9bc23f8be4e650346b58f6e to your computer and use it in GitHub Desktop.

Select an option

Save dimroc/60b9f419f9bc23f8be4e650346b58f6e to your computer and use it in GitHub Desktop.
Easily use view helpers in specs with `h.number_to_currency`
module ViewHelpers
def h
ViewHelper.instance
end
class ViewHelper
include Singleton
include ActionView::Helpers::NumberHelper
include ApplicationHelper
end
end
RSpec.configure do |config|
config.include ViewHelpers
end
require 'rails_helper'
feature 'some feature' do
scenario 'can see the percentage' do
savings = # Use rails view helpers freely in spec!
h.number_to_percentage(3.00, strip_insignificant_zeros: true)
expect(savings).to eq "3%"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment