Skip to content

Commit

Permalink
Extract shared test helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
koppen committed Jan 23, 2023
1 parent eeca1e8 commit f0b3864
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
25 changes: 0 additions & 25 deletions test/input_group/test_email_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,6 @@ def test_uses_configured_classes_for_wrapping_element

private

def build_form(model)
ActionView::Helpers::FormBuilder.new(
model.class.to_s.underscore,
model,
build_template,
{}
)
end

def build_template
ActionView::Base.new(
:this,
{}, # assigns?
:there
)
end

def do_render(form, **options)
component = Felt::InputGroup::EmailField.new(form: form, attribute: :email, **options)
render_inline(component).to_html
Expand All @@ -194,12 +177,4 @@ def render_component_to_html
)
render_inline(component).to_html
end

def with_translations(translations)
original_translations = I18n.backend.translations[I18n.locale]
I18n.backend.translations[I18n.locale] = translations
yield
ensure
I18n.backend.translations[I18n.locale] = original_translations
end
end
25 changes: 0 additions & 25 deletions test/input_group/test_text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,33 +187,8 @@ def test_uses_configured_classes_for_wrapping_element

private

def build_form(model)
ActionView::Helpers::FormBuilder.new(
model.class.to_s.underscore,
model,
build_template,
{}
)
end

def build_template
ActionView::Base.new(
:this,
{}, # assigns?
:there
)
end

def do_render(form, **options)
component = Felt::InputGroup::TextField.new(form: form, attribute: :title, **options)
render_inline(component).to_html
end

def with_translations(translations)
original_translations = I18n.backend.translations[I18n.locale]
I18n.backend.translations[I18n.locale] = translations
yield
ensure
I18n.backend.translations[I18n.locale] = original_translations
end
end
25 changes: 25 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@

require File.expand_path("../demo/config/environment.rb", __dir__)
require "felt"

def build_form(model)
ActionView::Helpers::FormBuilder.new(
model.class.to_s.underscore,
model,
build_template,
{}
)
end

def build_template
ActionView::Base.new(
:this,
{}, # assigns?
:there
)
end

def with_translations(translations)
original_translations = I18n.backend.translations[I18n.locale]
I18n.backend.translations[I18n.locale] = translations
yield
ensure
I18n.backend.translations[I18n.locale] = original_translations
end

0 comments on commit f0b3864

Please sign in to comment.