Jumping into the code is the way of the Jedi :)
Here how I do it:
# Here my custom input
# File app/inputs/date_pair_input.rb
class DatePairInput < SimpleForm::Inputs::Base
def input
[...]
end
end
# My unit test for my custom input
# File test/unit/inputs/date_pair_input_test.rb
class MyInputTest < ActionView::TestCase
include SimpleForm::ActionViewExtensions::FormHelper
# Taken from simple_form/test/support/misc_helpers.rb
def with_concat_form_for(*args, &block)
concat simple_form_for(*args, &(block || proc {}))
end
# Taken from simple_form/test/support/misc_helpers.rb
def with_input_for(object, attribute_name, type, options={})
with_concat_form_for(object) do |f|
f.input(attribute_name, options.merge(:as => type))
end
end
test "MyInput" do
# This is my model
event = Event.new
event.title = 'My event title'
event.starts_at = Time.new(2012, 02, 15, 23, 21)
event.ends_at = event.starts_at + 1.hour
# Test the text input that comes built-in with simple_form
with_input_for event, :title, :text
assert_select 'textarea.text#event_title'
# Test my custom DatePairInput
html = with_input_for event, :starts_at, :date_pair
assert html.include? '2012-02-15'
assert html.include? '11:30pm'
end
end
If you know a better way...