Last active
May 4, 2018 02:29
-
-
Save dimroc/60b9f419f9bc23f8be4e650346b58f6e to your computer and use it in GitHub Desktop.
Easily use view helpers in specs with `h.number_to_currency`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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