-
Notifications
You must be signed in to change notification settings - Fork 630
/
custom_input_spec.rb
55 lines (42 loc) · 1.25 KB
/
custom_input_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# encoding: utf-8
require 'spec_helper'
# TODO extract out
module TestInputs
def input_args
@template = self
@object = ::Post.new
@object_name = 'post'
@method = :title
@options = {}
@proc = Proc.new {}
if Rails::VERSION::MAJOR == 4
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
else
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options, @proc)
end
[@builder, @template, @object, @object_name, @method, @options]
end
class ::UnimplementedInput
include Formtastic::Inputs::Base
end
class ::ImplementedInput < UnimplementedInput
def to_html
"some HTML output"
end
end
end
describe 'AnyCustomInput' do
include TestInputs
describe "#to_html" do
describe 'without an implementation' do
it "should raise a NotImplementedError exception" do
expect { ::UnimplementedInput.new(*input_args).to_html }.to raise_error(NotImplementedError)
end
end
describe 'with an implementation' do
it "should raise a NotImplementedError exception" do
expect { ::ImplementedInput.new(*input_args).to_html }.to_not raise_error(NotImplementedError)
end
end
end
end