forme 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/erb_helper.rb CHANGED
@@ -128,58 +128,60 @@ END
128
128
  end
129
129
  end
130
130
 
131
- shared_examples_for "erb integration" do
131
+ module FormeErbSpecs
132
+ extend Minitest::Spec::DSL
133
+
132
134
  before do
133
135
  o = Object.new
134
136
  def o.puts(*) end
135
137
  @rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o, 'SCRIPT_NAME'=>''}
136
138
  end
137
139
 
138
- specify "#form should add start and end tags and yield Forme::Form instance" do
139
- sin_get('/').should == '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="Save"/> </form>'
140
+ it "#form should add start and end tags and yield Forme::Form instance" do
141
+ sin_get('/').must_equal '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="Save"/> </form>'
140
142
  end
141
143
 
142
- specify "#form should have inputs work with a block" do
143
- sin_get('/inputs_block').should == '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
144
+ it "#form should have inputs work with a block" do
145
+ sin_get('/inputs_block').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
144
146
  end
145
147
 
146
- specify "#form should have inputs with fieldset_ol wrapper work with block" do
147
- sin_get('/inputs_block_wrapper').should == '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
148
+ it "#form should have inputs with fieldset_ol wrapper work with block" do
149
+ sin_get('/inputs_block_wrapper').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
148
150
  end
149
151
 
150
- specify "#form should add start and end tags and yield Forme::Form instance" do
151
- sin_get('/nest').should == '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
152
+ it "#form should add start and end tags and yield Forme::Form instance" do
153
+ sin_get('/nest').must_equal '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
152
154
  end
153
155
 
154
- specify "#form should correctly handle situation where multiple templates are used with same form object" do
155
- sin_get('/nest_sep').should == "0 <form action=\"/baz\"> 1 <p>FBB</p> 2 n1 <div> n2 <input id=\"first\" name=\"first\" type=\"text\" value=\"foo\"/> <input id=\"last\" name=\"last\" type=\"text\" value=\"bar\"/> n3 </div> n4 <fieldset class=\"inputs\"><legend>Foo</legend><input id=\"first\" name=\"first\" type=\"text\" value=\"foo\"/><input id=\"last\" name=\"last\" type=\"text\" value=\"bar\"/></fieldset> n5 3 </form>4"
156
+ it "#form should correctly handle situation where multiple templates are used with same form object" do
157
+ sin_get('/nest_sep').must_equal "0 <form action=\"/baz\"> 1 <p>FBB</p> 2 n1 <div> n2 <input id=\"first\" name=\"first\" type=\"text\" value=\"foo\"/> <input id=\"last\" name=\"last\" type=\"text\" value=\"bar\"/> n3 </div> n4 <fieldset class=\"inputs\"><legend>Foo</legend><input id=\"first\" name=\"first\" type=\"text\" value=\"foo\"/><input id=\"last\" name=\"last\" type=\"text\" value=\"bar\"/></fieldset> n5 3 </form>4"
156
158
  end
157
159
 
158
- specify "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
159
- sin_get('/nest_seq').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").should == "0 <form action=\"/baz\" class=\"forme album\" method=\"post\"><input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/> 1 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Foo</legend><label>Name: <input id=\"album_artist_attributes_name\" name=\"album[artist_attributes][name]\" type=\"text\" value=\"A\"/></label></fieldset> 2 n1 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Artist</legend> n2 <label>Name2: <input id=\"album_artist_attributes_name2\" name=\"album[artist_attributes][name2]\" type=\"text\" value=\"A2\"/></label> n3 </fieldset> n4 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Bar</legend><label>Name3: <input id=\"album_artist_attributes_name3\" name=\"album[artist_attributes][name3]\" type=\"text\" value=\"A3\"/></label></fieldset> n5 3 </form>4"
160
+ it "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
161
+ sin_get('/nest_seq').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal "0 <form action=\"/baz\" class=\"forme album\" method=\"post\"><input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/> 1 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Foo</legend><label>Name: <input id=\"album_artist_attributes_name\" name=\"album[artist_attributes][name]\" type=\"text\" value=\"A\"/></label></fieldset> 2 n1 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Artist</legend> n2 <label>Name2: <input id=\"album_artist_attributes_name2\" name=\"album[artist_attributes][name2]\" type=\"text\" value=\"A2\"/></label> n3 </fieldset> n4 <input id=\"album_artist_attributes_id\" name=\"album[artist_attributes][id]\" type=\"hidden\" value=\"2\"/><fieldset class=\"inputs\"><legend>Bar</legend><label>Name3: <input id=\"album_artist_attributes_name3\" name=\"album[artist_attributes][name3]\" type=\"text\" value=\"A3\"/></label></fieldset> n5 3 </form>4"
160
162
  end
161
163
 
162
- specify "#form should accept two hashes instead of requiring obj as first argument" do
163
- sin_get('/hash').should == '<form action="/baz"> <input id="first" name="first" type="text" value="foo"/> </form>'
164
+ it "#form should accept two hashes instead of requiring obj as first argument" do
165
+ sin_get('/hash').must_equal '<form action="/baz"> <input id="first" name="first" type="text" value="foo"/> </form>'
164
166
  end
165
167
 
166
- specify "#form should deal with emitted code" do
167
- sin_get('/legend').should == '<form action="/baz"> <p>FBB</p> <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> <p>FBB2</p> </form>'
168
+ it "#form should deal with emitted code" do
169
+ sin_get('/legend').must_equal '<form action="/baz"> <p>FBB</p> <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> <p>FBB2</p> </form>'
168
170
  end
169
171
 
170
- specify "#form should work with :inputs, :button, and :legend options" do
171
- sin_get('/combined').should == '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
172
+ it "#form should work with :inputs, :button, and :legend options" do
173
+ sin_get('/combined').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
172
174
  end
173
175
 
174
- specify "#form should work without a block" do
175
- sin_get('/noblock').should == '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
176
+ it "#form should work without a block" do
177
+ sin_get('/noblock').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
176
178
  end
177
179
 
178
- specify "#form should work without a block and still have hidden tags emitted" do
179
- sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").should == '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
180
+ it "#form should work without a block and still have hidden tags emitted" do
181
+ sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
180
182
  end
181
183
 
182
- specify "#form with an empty form should work" do
183
- sin_get('/noblock_empty').should == '<form action="/baz"></form>'
184
+ it "#form with an empty form should work" do
185
+ sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
184
186
  end
185
187
  end
data/spec/forme_spec.rb CHANGED
@@ -9,151 +9,163 @@ describe "Forme plain forms" do
9
9
  @f = Forme::Form.new
10
10
  end
11
11
 
12
- specify "Forme.version should return version string" do
13
- Forme.version.should =~ /\A\d+\.\d+\.\d+\z/
12
+ it "Forme.version should return version string" do
13
+ Forme.version.must_match /\A\d+\.\d+\.\d+\z/
14
14
  end
15
15
 
16
- specify "should create a simple input tags" do
17
- @f.input(:text).to_s.should == '<input type="text"/>'
18
- @f.input(:radio).to_s.should == '<input type="radio"/>'
19
- @f.input(:password).to_s.should == '<input type="password"/>'
20
- @f.input(:checkbox).to_s.should == '<input type="checkbox"/>'
21
- @f.input(:submit).to_s.should == '<input type="submit"/>'
16
+ it "should create a simple input tags" do
17
+ @f.input(:text).to_s.must_equal '<input type="text"/>'
18
+ @f.input(:radio).to_s.must_equal '<input type="radio"/>'
19
+ @f.input(:password).to_s.must_equal '<input type="password"/>'
20
+ @f.input(:checkbox).to_s.must_equal '<input type="checkbox"/>'
21
+ @f.input(:submit).to_s.must_equal '<input type="submit"/>'
22
22
  end
23
23
 
24
- specify "should use :name option as attribute" do
25
- @f.input(:text, :name=>"foo").to_s.should == '<input name="foo" type="text"/>'
24
+ it "should use :html option if given" do
25
+ @f.input(:text, :html=>"<a>foo</a>").to_s.must_equal '<a>foo</a>'
26
26
  end
27
27
 
28
- specify "should use :id option as attribute" do
29
- @f.input(:text, :id=>"foo").to_s.should == '<input id="foo" type="text"/>'
28
+ it "should support a callable :html option" do
29
+ @f.input(:text, :html=>proc{|i| "<a>#{i.type}</a>"}).to_s.must_equal '<a>text</a>'
30
30
  end
31
31
 
32
- specify "should use :class option as attribute" do
33
- @f.input(:text, :class=>"foo").to_s.should == '<input class="foo" type="text"/>'
32
+ it "should still use labeler, wrapper, error_handler, and helper if :html option is given" do
33
+ @f.input(:text, :html=>"<a>foo</a>", :label=>'a', :error=>'b', :help=>'c', :wrapper=>:div).to_s.must_equal '<div><label>a: <a>foo</a></label><span class="error_message">b</span><span class="helper">c</span></div>'
34
34
  end
35
35
 
36
- specify "should use :value option as attribute" do
37
- @f.input(:text, :value=>"foo").to_s.should == '<input type="text" value="foo"/>'
36
+ it "should use :name option as attribute" do
37
+ @f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" type="text"/>'
38
38
  end
39
39
 
40
- specify "should use :placeholder option as attribute" do
41
- @f.input(:text, :placeholder=>"foo").to_s.should == '<input placeholder="foo" type="text"/>'
40
+ it "should use :id option as attribute" do
41
+ @f.input(:text, :id=>"foo").to_s.must_equal '<input id="foo" type="text"/>'
42
42
  end
43
43
 
44
- specify "should use :style option as attribute" do
45
- @f.input(:text, :style=>"foo").to_s.should == '<input style="foo" type="text"/>'
44
+ it "should use :class option as attribute" do
45
+ @f.input(:text, :class=>"foo").to_s.must_equal '<input class="foo" type="text"/>'
46
46
  end
47
47
 
48
- specify "should use :key option as name and id attributes" do
49
- @f.input(:text, :key=>"foo").to_s.should == '<input id="foo" name="foo" type="text"/>'
48
+ it "should use :value option as attribute" do
49
+ @f.input(:text, :value=>"foo").to_s.must_equal '<input type="text" value="foo"/>'
50
50
  end
51
51
 
52
- specify "should use :key_id option as suffix for :key option id attributes" do
53
- @f.input(:text, :key=>"foo", :key_id=>'bar').to_s.should == '<input id="foo_bar" name="foo" type="text"/>'
52
+ it "should use :placeholder option as attribute" do
53
+ @f.input(:text, :placeholder=>"foo").to_s.must_equal '<input placeholder="foo" type="text"/>'
54
54
  end
55
55
 
56
- specify "should have :key option respect :multiple option" do
57
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.should == '<input id="foo" name="foo[]" type="text"/>'
56
+ it "should use :style option as attribute" do
57
+ @f.input(:text, :style=>"foo").to_s.must_equal '<input style="foo" type="text"/>'
58
58
  end
59
59
 
60
- specify "should use :key option respect form's current namespace" do
60
+ it "should use :key option as name and id attributes" do
61
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text"/>'
62
+ end
63
+
64
+ it "should use :key_id option as suffix for :key option id attributes" do
65
+ @f.input(:text, :key=>"foo", :key_id=>'bar').to_s.must_equal '<input id="foo_bar" name="foo" type="text"/>'
66
+ end
67
+
68
+ it "should have :key option respect :multiple option" do
69
+ @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="foo" name="foo[]" type="text"/>'
70
+ end
71
+
72
+ it "should use :key option respect form's current namespace" do
61
73
  @f.with_opts(:namespace=>['bar']) do
62
- @f.input(:text, :key=>"foo").to_s.should == '<input id="bar_foo" name="bar[foo]" type="text"/>'
63
- @f.input(:text, :key=>"foo", :multiple=>true).to_s.should == '<input id="bar_foo" name="bar[foo][]" type="text"/>'
74
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
75
+ @f.input(:text, :key=>"foo", :multiple=>true).to_s.must_equal '<input id="bar_foo" name="bar[foo][]" type="text"/>'
64
76
  @f.with_opts(:namespace=>['bar', 'baz']) do
65
- @f.input(:text, :key=>"foo").to_s.should == '<input id="bar_baz_foo" name="bar[baz][foo]" type="text"/>'
77
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_baz_foo" name="bar[baz][foo]" type="text"/>'
66
78
  end
67
79
  end
68
80
  end
69
81
 
70
- specify "should consider form's :values hash for default values based on the :key option if :value is not present" do
82
+ it "should consider form's :values hash for default values based on the :key option if :value is not present" do
71
83
  @f.opts[:values] = {'foo'=>'baz'}
72
- @f.input(:text, :key=>"foo").to_s.should == '<input id="foo" name="foo" type="text" value="baz"/>'
73
- @f.input(:text, :key=>"foo", :value=>'x').to_s.should == '<input id="foo" name="foo" type="text" value="x"/>'
84
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
85
+ @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="foo" name="foo" type="text" value="x"/>'
74
86
 
75
- @f.input(:text, :key=>:foo).to_s.should == '<input id="foo" name="foo" type="text" value="baz"/>'
87
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
76
88
  @f.opts[:values] = {:foo=>'baz'}
77
- @f.input(:text, :key=>:foo).to_s.should == '<input id="foo" name="foo" type="text" value="baz"/>'
89
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="baz"/>'
78
90
  end
79
91
 
80
- specify "should consider form's :values hash for default values based on the :key option when using namespaces" do
92
+ it "should consider form's :values hash for default values based on the :key option when using namespaces" do
81
93
  @f.opts[:values] = {'bar'=>{'foo'=>'baz'}}
82
94
  @f.with_opts(:namespace=>['bar']) do
83
- @f.input(:text, :key=>"foo").to_s.should == '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
84
- @f.input(:text, :key=>"foo", :value=>'x').to_s.should == '<input id="bar_foo" name="bar[foo]" type="text" value="x"/>'
85
- @f.input(:text, :key=>:foo).to_s.should == '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
95
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
96
+ @f.input(:text, :key=>"foo", :value=>'x').to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="x"/>'
97
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
86
98
  end
87
99
 
88
100
  @f.with_opts(:namespace=>[:bar]) do
89
- @f.input(:text, :key=>:foo).to_s.should == '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
101
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
90
102
 
91
103
  @f.opts[:values] = {:bar=>{:foo=>'baz'}}
92
- @f.input(:text, :key=>:foo).to_s.should == '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
104
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text" value="baz"/>'
93
105
  @f.opts[:values] = {:bar=>{}}
94
- @f.input(:text, :key=>:foo).to_s.should == '<input id="bar_foo" name="bar[foo]" type="text"/>'
106
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
95
107
  @f.opts[:values] = {}
96
- @f.input(:text, :key=>:foo).to_s.should == '<input id="bar_foo" name="bar[foo]" type="text"/>'
108
+ @f.input(:text, :key=>:foo).to_s.must_equal '<input id="bar_foo" name="bar[foo]" type="text"/>'
97
109
 
98
110
  @f.opts[:values] = {'bar'=>{'quux'=>{'foo'=>'baz'}}}
99
111
  @f.with_opts(:namespace=>['bar', 'quux']) do
100
- @f.input(:text, :key=>"foo").to_s.should == '<input id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/>'
112
+ @f.input(:text, :key=>"foo").to_s.must_equal '<input id="bar_quux_foo" name="bar[quux][foo]" type="text" value="baz"/>'
101
113
  end
102
114
  end
103
115
  end
104
116
 
105
- specify "should support a with_obj method that changes the object and namespace for the given block" do
117
+ it "should support a with_obj method that changes the object and namespace for the given block" do
106
118
  @f.with_obj([:a, :c], 'bar') do
107
- @f.input(:first).to_s.should == '<input id="bar_first" name="bar[first]" type="text" value="a"/>'
119
+ @f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="a"/>'
108
120
  @f.with_obj([:b], 'baz') do
109
- @f.input(:first).to_s.should == '<input id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/>'
121
+ @f.input(:first).to_s.must_equal '<input id="bar_baz_first" name="bar[baz][first]" type="text" value="b"/>'
110
122
  end
111
123
  @f.with_obj([:b], %w'baz quux') do
112
- @f.input(:first).to_s.should == '<input id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/>'
124
+ @f.input(:first).to_s.must_equal '<input id="bar_baz_quux_first" name="bar[baz][quux][first]" type="text" value="b"/>'
113
125
  end
114
126
  @f.with_obj([:b]) do
115
- @f.input(:first).to_s.should == '<input id="bar_first" name="bar[first]" type="text" value="b"/>'
127
+ @f.input(:first).to_s.must_equal '<input id="bar_first" name="bar[first]" type="text" value="b"/>'
116
128
  end
117
- @f.input(:last).to_s.should == '<input id="bar_last" name="bar[last]" type="text" value="c"/>'
129
+ @f.input(:last).to_s.must_equal '<input id="bar_last" name="bar[last]" type="text" value="c"/>'
118
130
  end
119
131
  end
120
132
 
121
- specify "should support a each_obj method that changes the object and namespace for multiple objects for the given block" do
133
+ it "should support a each_obj method that changes the object and namespace for multiple objects for the given block" do
122
134
  @f.tag(:form) do
123
135
  @f.each_obj([[:a, :c], [:b, :d]], 'bar') do
124
136
  @f.input(:first)
125
137
  @f.input(:last)
126
138
  end
127
- end.to_s.should == '<form><input id="bar_0_first" name="bar[0][first]" type="text" value="a"/><input id="bar_0_last" name="bar[0][last]" type="text" value="c"/><input id="bar_1_first" name="bar[1][first]" type="text" value="b"/><input id="bar_1_last" name="bar[1][last]" type="text" value="d"/></form>'
139
+ end.to_s.must_equal '<form><input id="bar_0_first" name="bar[0][first]" type="text" value="a"/><input id="bar_0_last" name="bar[0][last]" type="text" value="c"/><input id="bar_1_first" name="bar[1][first]" type="text" value="b"/><input id="bar_1_last" name="bar[1][last]" type="text" value="d"/></form>'
128
140
 
129
141
  @f.tag(:form) do
130
142
  @f.each_obj([[:a, :c], [:b, :d]], %w'bar baz') do
131
143
  @f.input(:first)
132
144
  @f.input(:last)
133
145
  end
134
- end.to_s.should == '<form><input id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/><input id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/><input id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/><input id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></form>'
146
+ end.to_s.must_equal '<form><input id="bar_baz_0_first" name="bar[baz][0][first]" type="text" value="a"/><input id="bar_baz_0_last" name="bar[baz][0][last]" type="text" value="c"/><input id="bar_baz_1_first" name="bar[baz][1][first]" type="text" value="b"/><input id="bar_baz_1_last" name="bar[baz][1][last]" type="text" value="d"/></form>'
135
147
 
136
148
  @f.tag(:form) do
137
149
  @f.each_obj([[:a, :c], [:b, :d]]) do
138
150
  @f.input(:first)
139
151
  @f.input(:last)
140
152
  end
141
- end.to_s.should == '<form><input id="0_first" name="0[first]" type="text" value="a"/><input id="0_last" name="0[last]" type="text" value="c"/><input id="1_first" name="1[first]" type="text" value="b"/><input id="1_last" name="1[last]" type="text" value="d"/></form>'
153
+ end.to_s.must_equal '<form><input id="0_first" name="0[first]" type="text" value="a"/><input id="0_last" name="0[last]" type="text" value="c"/><input id="1_first" name="1[first]" type="text" value="b"/><input id="1_last" name="1[last]" type="text" value="d"/></form>'
142
154
  end
143
155
 
144
- specify "should allow overriding form inputs on a per-block basis" do
145
- @f.input(:text).to_s.should == '<input type="text"/>'
146
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.should == '<div><input type="text"/></div>'
147
- @f.with_opts(:wrapper=>:div){@f.input(:text).to_s.should == '<div><input type="text"/></div>'}
156
+ it "should allow overriding form inputs on a per-block basis" do
157
+ @f.input(:text).to_s.must_equal '<input type="text"/>'
158
+ @f.with_opts(:wrapper=>:div){@f.input(:text).to_s}.must_equal '<div><input type="text"/></div>'
159
+ @f.with_opts(:wrapper=>:div){@f.input(:text).to_s.must_equal '<div><input type="text"/></div>'}
148
160
  @f.with_opts(:wrapper=>:div) do
149
- @f.input(:text).to_s.should == '<div><input type="text"/></div>'
150
- @f.with_opts(:wrapper=>:li){@f.input(:text).to_s.should == '<li><input type="text"/></li>'}
151
- @f.input(:text).to_s.should == '<div><input type="text"/></div>'
161
+ @f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
162
+ @f.with_opts(:wrapper=>:li){@f.input(:text).to_s.must_equal '<li><input type="text"/></li>'}
163
+ @f.input(:text).to_s.must_equal '<div><input type="text"/></div>'
152
164
  end
153
- @f.input(:text).to_s.should == '<input type="text"/>'
165
+ @f.input(:text).to_s.must_equal '<input type="text"/>'
154
166
  end
155
167
 
156
- specify "should handle delayed formatting when overriding form inputs on a per-block basis" do
168
+ it "should handle delayed formatting when overriding form inputs on a per-block basis" do
157
169
  @f.form do
158
170
  @f.input(:text)
159
171
  @f.with_opts(:wrapper=>:div) do
@@ -162,534 +174,534 @@ describe "Forme plain forms" do
162
174
  @f.input(:text)
163
175
  end
164
176
  @f.input(:text)
165
- end.to_s.should == '<form><input type="text"/><div><input type="text"/></div><li><input type="text"/></li><div><input type="text"/></div><input type="text"/></form>'
177
+ end.to_s.must_equal '<form><input type="text"/><div><input type="text"/></div><li><input type="text"/></li><div><input type="text"/></div><input type="text"/></form>'
166
178
  end
167
179
 
168
- specify "should support :obj method to with_opts for changing the obj inside the block" do
180
+ it "should support :obj method to with_opts for changing the obj inside the block" do
169
181
  @f.form do
170
182
  @f.with_opts(:obj=>[:a, :c]) do
171
183
  @f.input(:first)
172
184
  @f.with_opts(:obj=>[:b]){@f.input(:first)}
173
185
  @f.input(:last)
174
186
  end
175
- end.to_s.should == '<form><input id="first" name="first" type="text" value="a"/><input id="first" name="first" type="text" value="b"/><input id="last" name="last" type="text" value="c"/></form>'
187
+ end.to_s.must_equal '<form><input id="first" name="first" type="text" value="a"/><input id="first" name="first" type="text" value="b"/><input id="last" name="last" type="text" value="c"/></form>'
176
188
  end
177
189
 
178
- specify "should allow arbitrary attributes using the :attr option" do
179
- @f.input(:text, :attr=>{:bar=>"foo"}).to_s.should == '<input bar="foo" type="text"/>'
190
+ it "should allow arbitrary attributes using the :attr option" do
191
+ @f.input(:text, :attr=>{:bar=>"foo"}).to_s.must_equal '<input bar="foo" type="text"/>'
180
192
  end
181
193
 
182
- specify "should convert the :data option into attributes" do
183
- @f.input(:text, :data=>{:bar=>"foo"}).to_s.should == '<input data-bar="foo" type="text"/>'
194
+ it "should convert the :data option into attributes" do
195
+ @f.input(:text, :data=>{:bar=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
184
196
  end
185
197
 
186
- specify "should not have standard options override the :attr option" do
187
- @f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.should == '<input name="foo" type="text"/>'
198
+ it "should not have standard options override the :attr option" do
199
+ @f.input(:text, :name=>:bar, :attr=>{:name=>"foo"}).to_s.must_equal '<input name="foo" type="text"/>'
188
200
  end
189
201
 
190
- specify "should combine :class standard option with :attr option" do
191
- @f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.should == '<input class="foo bar" type="text"/>'
202
+ it "should combine :class standard option with :attr option" do
203
+ @f.input(:text, :class=>:bar, :attr=>{:class=>"foo"}).to_s.must_equal '<input class="foo bar" type="text"/>'
192
204
  end
193
205
 
194
- specify "should not have :data options override the :attr option" do
195
- @f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.should == '<input data-bar="foo" type="text"/>'
206
+ it "should not have :data options override the :attr option" do
207
+ @f.input(:text, :data=>{:bar=>"baz"}, :attr=>{:"data-bar"=>"foo"}).to_s.must_equal '<input data-bar="foo" type="text"/>'
196
208
  end
197
209
 
198
- specify "should use :size and :maxlength options as attributes for text inputs" do
199
- @f.input(:text, :size=>5, :maxlength=>10).to_s.should == '<input maxlength="10" size="5" type="text"/>'
200
- @f.input(:textarea, :size=>5, :maxlength=>10).to_s.should == '<textarea></textarea>'
210
+ it "should use :size and :maxlength options as attributes for text inputs" do
211
+ @f.input(:text, :size=>5, :maxlength=>10).to_s.must_equal '<input maxlength="10" size="5" type="text"/>'
212
+ @f.input(:textarea, :size=>5, :maxlength=>10).to_s.must_equal '<textarea></textarea>'
201
213
  end
202
214
 
203
- specify "should create hidden input with value 0 for each checkbox with a name" do
204
- @f.input(:checkbox, :name=>"foo").to_s.should == '<input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/>'
215
+ it "should create hidden input with value 0 for each checkbox with a name" do
216
+ @f.input(:checkbox, :name=>"foo").to_s.must_equal '<input name="foo" type="hidden" value="0"/><input name="foo" type="checkbox"/>'
205
217
  end
206
218
 
207
- specify "should not create hidden input with value 0 for each checkbox with a name if :no_hidden option is used" do
208
- @f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.should == '<input name="foo" type="checkbox"/>'
219
+ it "should not create hidden input with value 0 for each checkbox with a name if :no_hidden option is used" do
220
+ @f.input(:checkbox, :name=>"foo", :no_hidden=>true).to_s.must_equal '<input name="foo" type="checkbox"/>'
209
221
  end
210
222
 
211
- specify "should create hidden input with _hidden appened to id for each checkbox with a name and id" do
212
- @f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.should == '<input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/>'
223
+ it "should create hidden input with _hidden appened to id for each checkbox with a name and id" do
224
+ @f.input(:checkbox, :name=>"foo", :id=>"bar").to_s.must_equal '<input id="bar_hidden" name="foo" type="hidden" value="0"/><input id="bar" name="foo" type="checkbox"/>'
213
225
  end
214
226
 
215
- specify "should create hidden input with value f for each checkbox with a name and value t" do
216
- @f.input(:checkbox, :name=>"foo", :value=>"t").to_s.should == '<input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/>'
227
+ it "should create hidden input with value f for each checkbox with a name and value t" do
228
+ @f.input(:checkbox, :name=>"foo", :value=>"t").to_s.must_equal '<input name="foo" type="hidden" value="f"/><input name="foo" type="checkbox" value="t"/>'
217
229
  end
218
230
 
219
- specify "should use :hidden_value option for value of hidden input for checkbox" do
220
- @f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.should == '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
231
+ it "should use :hidden_value option for value of hidden input for checkbox" do
232
+ @f.input(:checkbox, :name=>"foo", :hidden_value=>"no").to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
221
233
  end
222
234
 
223
- specify "should handle :checked option" do
224
- @f.input(:checkbox, :checked=>true).to_s.should == '<input checked="checked" type="checkbox"/>'
225
- @f.input(:checkbox, :checked=>false).to_s.should == '<input type="checkbox"/>'
235
+ it "should handle :checked option" do
236
+ @f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
237
+ @f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
226
238
  end
227
239
 
228
- specify "should create textarea tag" do
229
- @f.input(:textarea).to_s.should == '<textarea></textarea>'
230
- @f.input(:textarea, :value=>'a').to_s.should == '<textarea>a</textarea>'
240
+ it "should create textarea tag" do
241
+ @f.input(:textarea).to_s.must_equal '<textarea></textarea>'
242
+ @f.input(:textarea, :value=>'a').to_s.must_equal '<textarea>a</textarea>'
231
243
  end
232
244
 
233
- specify "should use :cols and :rows options as attributes for textarea inputs" do
234
- @f.input(:text, :cols=>5, :rows=>10).to_s.should == '<input type="text"/>'
235
- @f.input(:textarea, :cols=>5, :rows=>10).to_s.should == '<textarea cols="5" rows="10"></textarea>'
245
+ it "should use :cols and :rows options as attributes for textarea inputs" do
246
+ @f.input(:text, :cols=>5, :rows=>10).to_s.must_equal '<input type="text"/>'
247
+ @f.input(:textarea, :cols=>5, :rows=>10).to_s.must_equal '<textarea cols="5" rows="10"></textarea>'
236
248
  end
237
249
 
238
- specify "should create select tag" do
239
- @f.input(:select).to_s.should == '<select></select>'
250
+ it "should create select tag" do
251
+ @f.input(:select).to_s.must_equal '<select></select>'
240
252
  end
241
253
 
242
- specify "should respect multiple and size options in select tag" do
243
- @f.input(:select, :multiple=>true, :size=>10).to_s.should == '<select multiple="multiple" size="10"></select>'
254
+ it "should respect multiple and size options in select tag" do
255
+ @f.input(:select, :multiple=>true, :size=>10).to_s.must_equal '<select multiple="multiple" size="10"></select>'
244
256
  end
245
257
 
246
- specify "should create date tag" do
247
- @f.input(:date).to_s.should == '<input type="date"/>'
258
+ it "should create date tag" do
259
+ @f.input(:date).to_s.must_equal '<input type="date"/>'
248
260
  end
249
261
 
250
- specify "should create datetime-local tag" do
251
- @f.input(:datetime).to_s.should == '<input type="datetime-local"/>'
262
+ it "should create datetime-local tag" do
263
+ @f.input(:datetime).to_s.must_equal '<input type="datetime-local"/>'
252
264
  end
253
265
 
254
- specify "should not error for input type :input" do
255
- @f.input(:input).to_s.should == '<input type="input"/>'
266
+ it "should not error for input type :input" do
267
+ @f.input(:input).to_s.must_equal '<input type="input"/>'
256
268
  end
257
269
 
258
- specify "should use multiple select boxes for dates if the :as=>:select option is given" do
259
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.should == %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
270
+ it "should use multiple select boxes for dates if the :as=>:select option is given" do
271
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
260
272
  end
261
273
 
262
- specify "should allow ordering date select boxes via :order" do
263
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.should == %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
274
+ it "should allow ordering date select boxes via :order" do
275
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, '/', :day, '/', :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select>/<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
264
276
  end
265
277
 
266
- specify "should allow only using specific date select boxes via :order" do
267
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.should == %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
278
+ it "should allow only using specific date select boxes via :order" do
279
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :order=>[:month, :year]).to_s.must_equal %{<select id="bar" name="foo[month]">#{sel(1..12, 6)}</select><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>}
268
280
  end
269
281
 
270
- specify "should support :select_options for dates when :as=>:select is given" do
271
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.should == %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
282
+ it "should support :select_options for dates when :as=>:select is given" do
283
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
272
284
  end
273
285
 
274
- specify "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
275
- @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.should == %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
286
+ it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
287
+ @f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.must_equal %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
276
288
  end
277
289
 
278
- specify "should use multiple select boxes for datetimes if the :as=>:select option is given" do
279
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.should == %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
290
+ it "should use multiple select boxes for datetimes if the :as=>:select option is given" do
291
+ @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
280
292
  end
281
293
 
282
- specify "should allow ordering select boxes for datetimes via :order" do
283
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2), :order=>[:day, '/', :month, 'T', :hour, ':', :minute]).to_s.should == %{<select id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>}
294
+ it "should allow ordering select boxes for datetimes via :order" do
295
+ @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 4, 3, 2), :order=>[:day, '/', :month, 'T', :hour, ':', :minute]).to_s.must_equal %{<select id="bar" name="foo[day]">#{sel(1..31, 5)}</select>/<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>T<select id="bar_hour" name="foo[hour]">#{sel(0..23, 4)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>}
284
296
  end
285
297
 
286
- specify "should support :select_options for datetimes when :as=>:select option is given" do
287
- @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 10, 3, 2), :select_options=>{:year=>1970..2020, :hour=>9..17}).to_s.should == %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
298
+ it "should support :select_options for datetimes when :as=>:select option is given" do
299
+ @f.input(:datetime, :name=>"foo", :id=>"bar", :as=>:select, :value=>DateTime.new(2011, 6, 5, 10, 3, 2), :select_options=>{:year=>1970..2020, :hour=>9..17}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select> <select id="bar_hour" name="foo[hour]">#{sel(9..17, 10)}</select>:<select id="bar_minute" name="foo[minute]">#{sel(0..59, 3)}</select>:<select id="bar_second" name="foo[second]">#{sel(0..59, 2)}</select>}
288
300
  end
289
301
 
290
- specify "should create select tag with options" do
291
- @f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.should == '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
292
- @f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.should == '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
302
+ it "should create select tag with options" do
303
+ @f.input(:select, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
304
+ @f.input(:select, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
293
305
  end
294
306
 
295
- specify "should create select tag with options and values" do
296
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.should == '<select><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
307
+ it "should create select tag with options and values" do
308
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<select><option value="1">a</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
297
309
  end
298
310
 
299
- specify "should create select tag with option groups" do
300
- @f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.should == '<select><optgroup label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup label="e"><option value="3">c</option></optgroup></select>'
311
+ it "should create select tag with option groups" do
312
+ @f.input(:select, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup label="e"><option value="3">c</option></optgroup></select>'
301
313
  end
302
314
 
303
- specify "should create select tag with option groups with attributes" do
304
- @f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.should == '<select><optgroup class="f" label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup class="g" label="e"><option value="3">c</option></optgroup></select>'
315
+ it "should create select tag with option groups with attributes" do
316
+ @f.input(:select, :optgroups=>[[{:label=>'d', :class=>'f'}, [[:a, 1], [:b, 2]]], [{:label=>'e', :class=>'g'}, [[:c, 3]]]], :selected=>2).to_s.must_equal '<select><optgroup class="f" label="d"><option value="1">a</option><option selected="selected" value="2">b</option></optgroup><optgroup class="g" label="e"><option value="3">c</option></optgroup></select>'
305
317
  end
306
318
 
307
- specify "should create select tag with options and values with hashes" do
308
- @f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.should == '<select><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select>'
319
+ it "should create select tag with options and values with hashes" do
320
+ @f.input(:select, :options=>[[:a, {:foo=>1}], [:b, {:bar=>4, :value=>2}], [:c, {:baz=>3}]], :selected=>2).to_s.must_equal '<select><option foo="1">a</option><option bar="4" selected="selected" value="2">b</option><option baz="3">c</option></select>'
309
321
  end
310
322
 
311
- specify "should create select tag with options and values using given method" do
312
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.should == '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
313
- @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.should == '<select><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select>'
323
+ it "should create select tag with options and values using given method" do
324
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<select><option>1</option><option selected="selected">2</option><option>3</option></select>'
325
+ @f.input(:select, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<select><option value="a">1</option><option selected="selected" value="b">2</option><option value="c">3</option></select>'
314
326
  end
315
327
 
316
- specify "should use html attributes specified in options" do
317
- @f.input(:text, :value=>'foo', :name=>'bar').to_s.should == '<input name="bar" type="text" value="foo"/>'
318
- @f.input(:textarea, :value=>'foo', :name=>'bar').to_s.should == '<textarea name="bar">foo</textarea>'
319
- @f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.should == '<select name="bar"><option>1</option><option>2</option><option>3</option></select>'
328
+ it "should use html attributes specified in options" do
329
+ @f.input(:text, :value=>'foo', :name=>'bar').to_s.must_equal '<input name="bar" type="text" value="foo"/>'
330
+ @f.input(:textarea, :value=>'foo', :name=>'bar').to_s.must_equal '<textarea name="bar">foo</textarea>'
331
+ @f.input(:select, :name=>'bar', :options=>[1, 2, 3]).to_s.must_equal '<select name="bar"><option>1</option><option>2</option><option>3</option></select>'
320
332
  end
321
333
 
322
- specify "should support :add_blank option for select inputs" do
323
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.should == '<select><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
334
+ it "should support :add_blank option for select inputs" do
335
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
324
336
  end
325
337
 
326
- specify "should use Forme.default_add_blank_prompt value if :add_blank option is true" do
338
+ it "should use Forme.default_add_blank_prompt value if :add_blank option is true" do
327
339
  begin
328
340
  Forme.default_add_blank_prompt = 'foo'
329
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.should == '<select><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
341
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<select><option value="">foo</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
330
342
  ensure
331
343
  Forme.default_add_blank_prompt = nil
332
344
  end
333
345
  end
334
346
 
335
- specify "should use :add_blank option value as prompt if it is a String" do
336
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.should == '<select><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
347
+ it "should use :add_blank option value as prompt if it is a String" do
348
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<select><option value="">Prompt Here</option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
337
349
  end
338
350
 
339
- specify "should support :add_blank option with :blank_position :after for select inputs" do
340
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.should == '<select><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select>'
351
+ it "should support :add_blank option with :blank_position :after for select inputs" do
352
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_position=>:after, :value=>2).to_s.must_equal '<select><option selected="selected" value="2">b</option><option value="3">c</option><option value=""></option></select>'
341
353
  end
342
354
 
343
- specify "should support :add_blank option with :blank_attr option for select inputs" do
344
- @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.should == '<select><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
355
+ it "should support :add_blank option with :blank_attr option for select inputs" do
356
+ @f.input(:select, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :blank_attr=>{:foo=>:bar}, :value=>2).to_s.must_equal '<select><option foo="bar" value=""></option><option selected="selected" value="2">b</option><option value="3">c</option></select>'
345
357
  end
346
358
 
347
- specify "should create set of radio buttons" do
348
- @f.input(:radioset, :options=>[1, 2, 3], :selected=>2).to_s.should == '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
349
- @f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.should == '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
359
+ it "should create set of radio buttons" do
360
+ @f.input(:radioset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
361
+ @f.input(:radioset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
350
362
  end
351
363
 
352
- specify "should create set of radio buttons with options and values" do
353
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.should == '<label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
364
+ it "should create set of radio buttons with options and values" do
365
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
354
366
  end
355
367
 
356
- specify "should create set of radio buttons with options and values with hashes" do
357
- @f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.should == '<label class="option"><input foo="1" type="radio" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label><label class="option"><input id="baz" type="radio" value="c"/> c</label>'
368
+ it "should create set of radio buttons with options and values with hashes" do
369
+ @f.input(:radioset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="radio" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="radio" value="2"/> b</label><label class="option"><input id="baz" type="radio" value="c"/> c</label>'
358
370
  end
359
371
 
360
- specify "should create set of radio buttons with options and values using given method" do
361
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.should == '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
362
- @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.should == '<label class="option"><input type="radio" value="a"/> 1</label><label class="option"><input checked="checked" type="radio" value="b"/> 2</label><label class="option"><input type="radio" value="c"/> 3</label>'
372
+ it "should create set of radio buttons with options and values using given method" do
373
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input type="radio" value="3"/> 3</label>'
374
+ @f.input(:radioset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="radio" value="a"/> 1</label><label class="option"><input checked="checked" type="radio" value="b"/> 2</label><label class="option"><input type="radio" value="c"/> 3</label>'
363
375
  end
364
376
 
365
- specify "should support :add_blank option for radioset inputs" do
366
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.should == '<label class="option"><input type="radio" value=""/> </label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
377
+ it "should support :add_blank option for radioset inputs" do
378
+ @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> </label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
367
379
  end
368
380
 
369
- specify "should use :add_blank option value as prompt if it is a String" do
370
- @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.should == '<label class="option"><input type="radio" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
381
+ it "should use :add_blank option value as prompt if it is a String" do
382
+ @f.input(:radioset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="radio" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label><label class="option"><input type="radio" value="3"/> c</label>'
371
383
  end
372
384
 
373
- specify "should respect the :key option for radio sets" do
374
- @f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.should == '<label class="option"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label>'
385
+ it "should respect the :key option for radio sets" do
386
+ @f.input(:radioset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo" type="radio" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo" type="radio" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo" type="radio" value="3"/> 3</label>'
375
387
  end
376
388
 
377
- specify "should create set of radio buttons with fieldsets and legends for :optgroups" do
378
- @f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.should == '<fieldset><legend>d</legend><label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="radio" value="3"/> c</label></fieldset>'
389
+ it "should create set of radio buttons with fieldsets and legends for :optgroups" do
390
+ @f.input(:radioset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="radio" value="1"/> a</label><label class="option"><input checked="checked" type="radio" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="radio" value="3"/> c</label></fieldset>'
379
391
  end
380
392
 
381
- specify "should create set of checkbox buttons" do
382
- @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.should == '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
383
- @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.should == '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
393
+ it "should create set of checkbox buttons" do
394
+ @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
395
+ @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
384
396
  end
385
397
 
386
- specify "should create set of checkbox buttons with options and values" do
387
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.should == '<label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
398
+ it "should create set of checkbox buttons with options and values" do
399
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
388
400
  end
389
401
 
390
- specify "should create set of checkbox buttons with options and values with hashes" do
391
- @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.should == '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
402
+ it "should create set of checkbox buttons with options and values with hashes" do
403
+ @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
392
404
  end
393
405
 
394
- specify "should create set of checkbox buttons with options and values using given method" do
395
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.should == '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
396
- @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.should == '<label class="option"><input type="checkbox" value="a"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label><label class="option"><input type="checkbox" value="c"/> 3</label>'
406
+ it "should create set of checkbox buttons with options and values using given method" do
407
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
408
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :text_method=>:last, :value_method=>:first, :selected=>:b).to_s.must_equal '<label class="option"><input type="checkbox" value="a"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="b"/> 2</label><label class="option"><input type="checkbox" value="c"/> 3</label>'
397
409
  end
398
410
 
399
- specify "should support :add_blank option for checkboxset inputs" do
400
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.should == '<label class="option"><input type="checkbox" value=""/> </label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
411
+ it "should support :add_blank option for checkboxset inputs" do
412
+ @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>true, :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> </label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
401
413
  end
402
414
 
403
- specify "should use :add_blank option value as prompt if it is a String" do
404
- @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.should == '<label class="option"><input type="checkbox" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
415
+ it "should use :add_blank option value as prompt if it is a String" do
416
+ @f.input(:checkboxset, :options=>[[:b, 2], [:c, 3]], :add_blank=>"Prompt Here", :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value=""/> Prompt Here</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
405
417
  end
406
418
 
407
- specify "should respect the :key option for checkbox sets" do
408
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.should == '<label class="option"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label>'
419
+ it "should respect the :key option for checkbox sets" do
420
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="foo[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="foo[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="foo[]" type="checkbox" value="3"/> 3</label>'
409
421
  end
410
422
 
411
- specify "should prefer the :name option to :key option for checkbox sets" do
412
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.should == '<label class="option"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
423
+ it "should prefer the :name option to :key option for checkbox sets" do
424
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :value=>2).to_s.must_equal '<label class="option"><input id="foo_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="foo_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="foo_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
413
425
  end
414
426
 
415
- specify "should prefer the :name and :id option to :key option for checkbox sets" do
416
- @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.should == '<label class="option"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
427
+ it "should prefer the :name and :id option to :key option for checkbox sets" do
428
+ @f.input(:checkboxset, :options=>[1, 2, 3], :key=>:foo, :name=>'bar[]', :id=>:baz, :value=>2).to_s.must_equal '<label class="option"><input id="baz_1" name="bar[]" type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" id="baz_2" name="bar[]" type="checkbox" value="2"/> 2</label><label class="option"><input id="baz_3" name="bar[]" type="checkbox" value="3"/> 3</label>'
417
429
  end
418
430
 
419
- specify "should respect the :error option for checkbox sets" do
420
- @f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.should == '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
431
+ it "should respect the :error option for checkbox sets" do
432
+ @f.input(:checkboxset, :options=>[1, 2, 3], :error=>'foo', :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input class="error" type="checkbox" value="3"/> 3</label><span class="error_message">foo</span>'
421
433
  end
422
434
 
423
- specify "should create set of checkbox buttons with fieldsets and legends for optgroups" do
424
- @f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.should == '<fieldset><legend>d</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
435
+ it "should create set of checkbox buttons with fieldsets and legends for optgroups" do
436
+ @f.input(:checkboxset, :optgroups=>[['d', [[:a, 1], [:b, 2]]], ['e', [[:c, 3]]]], :selected=>2).to_s.must_equal '<fieldset><legend>d</legend><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label></fieldset><fieldset><legend>e</legend><label class="option"><input type="checkbox" value="3"/> c</label></fieldset>'
425
437
  end
426
438
 
427
- specify "should raise an Error for empty checkbox sets" do
428
- @f.input(:checkboxset, :options=>[], :error=>'foo', :value=>2).to_s.should == '<span class="error_message">foo</span>'
439
+ it "should raise an Error for empty checkbox sets" do
440
+ @f.input(:checkboxset, :options=>[], :error=>'foo', :value=>2).to_s.must_equal '<span class="error_message">foo</span>'
429
441
  end
430
442
 
431
- specify "radio and checkbox inputs should handle :checked option" do
432
- @f.input(:radio, :checked=>true).to_s.should == '<input checked="checked" type="radio"/>'
433
- @f.input(:radio, :checked=>false).to_s.should == '<input type="radio"/>'
434
- @f.input(:checkbox, :checked=>true).to_s.should == '<input checked="checked" type="checkbox"/>'
435
- @f.input(:checkbox, :checked=>false).to_s.should == '<input type="checkbox"/>'
443
+ it "radio and checkbox inputs should handle :checked option" do
444
+ @f.input(:radio, :checked=>true).to_s.must_equal '<input checked="checked" type="radio"/>'
445
+ @f.input(:radio, :checked=>false).to_s.must_equal '<input type="radio"/>'
446
+ @f.input(:checkbox, :checked=>true).to_s.must_equal '<input checked="checked" type="checkbox"/>'
447
+ @f.input(:checkbox, :checked=>false).to_s.must_equal '<input type="checkbox"/>'
436
448
  end
437
449
 
438
- specify "inputs should handle :autofocus option" do
439
- @f.input(:text, :autofocus=>true).to_s.should == '<input autofocus="autofocus" type="text"/>'
440
- @f.input(:text, :autofocus=>false).to_s.should == '<input type="text"/>'
450
+ it "inputs should handle :autofocus option" do
451
+ @f.input(:text, :autofocus=>true).to_s.must_equal '<input autofocus="autofocus" type="text"/>'
452
+ @f.input(:text, :autofocus=>false).to_s.must_equal '<input type="text"/>'
441
453
  end
442
454
 
443
- specify "inputs should handle :required option" do
444
- @f.input(:text, :required=>true).to_s.should == '<input required="required" type="text"/>'
445
- @f.input(:text, :required=>false).to_s.should == '<input type="text"/>'
455
+ it "inputs should handle :required option" do
456
+ @f.input(:text, :required=>true).to_s.must_equal '<input required="required" type="text"/>'
457
+ @f.input(:text, :required=>false).to_s.must_equal '<input type="text"/>'
446
458
  end
447
459
 
448
- specify "inputs should handle :disabled option" do
449
- @f.input(:text, :disabled=>true).to_s.should == '<input disabled="disabled" type="text"/>'
450
- @f.input(:text, :disabled=>false).to_s.should == '<input type="text"/>'
460
+ it "inputs should handle :disabled option" do
461
+ @f.input(:text, :disabled=>true).to_s.must_equal '<input disabled="disabled" type="text"/>'
462
+ @f.input(:text, :disabled=>false).to_s.must_equal '<input type="text"/>'
451
463
  end
452
464
 
453
- specify "inputs should not include options with nil values" do
454
- @f.input(:text, :name=>nil).to_s.should == '<input type="text"/>'
455
- @f.input(:textarea, :name=>nil).to_s.should == '<textarea></textarea>'
465
+ it "inputs should not include options with nil values" do
466
+ @f.input(:text, :name=>nil).to_s.must_equal '<input type="text"/>'
467
+ @f.input(:textarea, :name=>nil).to_s.must_equal '<textarea></textarea>'
456
468
  end
457
469
 
458
- specify "inputs should include options with false values" do
459
- @f.input(:text, :name=>false).to_s.should == '<input name="false" type="text"/>'
470
+ it "inputs should include options with false values" do
471
+ @f.input(:text, :name=>false).to_s.must_equal '<input name="false" type="text"/>'
460
472
  end
461
473
 
462
- specify "should automatically create a label if a :label option is used" do
463
- @f.input(:text, :label=>'Foo', :value=>'foo').to_s.should == '<label>Foo: <input type="text" value="foo"/></label>'
474
+ it "should automatically create a label if a :label option is used" do
475
+ @f.input(:text, :label=>'Foo', :value=>'foo').to_s.must_equal '<label>Foo: <input type="text" value="foo"/></label>'
464
476
  end
465
477
 
466
- specify "should set label attributes with :label_attr option" do
467
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.should == '<label class="bar">Foo: <input type="text" value="foo"/></label>'
478
+ it "should set label attributes with :label_attr option" do
479
+ @f.input(:text, :label=>'Foo', :value=>'foo', :label_attr=>{:class=>'bar'}).to_s.must_equal '<label class="bar">Foo: <input type="text" value="foo"/></label>'
468
480
  end
469
481
 
470
- specify "should handle implicit labels with checkboxes" do
471
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.should == '<input name="a" type="hidden" value="0"/><label><input name="a" type="checkbox" value="foo"/> Foo</label>'
482
+ it "should handle implicit labels with checkboxes" do
483
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a').to_s.must_equal '<input name="a" type="hidden" value="0"/><label><input name="a" type="checkbox" value="foo"/> Foo</label>'
472
484
  end
473
485
 
474
- specify "should handle implicit labels with :label_position=>:after" do
475
- @f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.should == '<label><input type="text" value="foo"/> Foo</label>'
486
+ it "should handle implicit labels with :label_position=>:after" do
487
+ @f.input(:text, :label=>'Foo', :value=>'foo', :label_position=>:after).to_s.must_equal '<label><input type="text" value="foo"/> Foo</label>'
476
488
  end
477
489
 
478
- specify "should handle implicit labels with checkboxes with :label_position=>:before" do
479
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.should == '<input name="a" type="hidden" value="0"/><label>Foo <input name="a" type="checkbox" value="foo"/></label>'
490
+ it "should handle implicit labels with checkboxes with :label_position=>:before" do
491
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :label_position=>:before).to_s.must_equal '<input name="a" type="hidden" value="0"/><label>Foo <input name="a" type="checkbox" value="foo"/></label>'
480
492
  end
481
493
 
482
- specify "should automatically note the input has errors if :error option is used" do
483
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.should == '<input class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
494
+ it "should automatically note the input has errors if :error option is used" do
495
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo').to_s.must_equal '<input class="error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
484
496
  end
485
497
 
486
- specify "should add an error message after the label" do
487
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.should == '<label>Foo: <input class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
498
+ it "should add an error message after the label" do
499
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :label=>"Foo").to_s.must_equal '<label>Foo: <input class="error" type="text" value="foo"/></label><span class="error_message">Bad Stuff!</span>'
488
500
  end
489
501
 
490
- specify "should add to existing :class option if :error option is used" do
491
- @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.should == '<input class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
502
+ it "should add to existing :class option if :error option is used" do
503
+ @f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.must_equal '<input class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
492
504
  end
493
505
 
494
- specify "should respect :error_attr option for setting the attributes for the error message span" do
495
- @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.should == '<input class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
506
+ it "should respect :error_attr option for setting the attributes for the error message span" do
507
+ @f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.must_equal '<input class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
496
508
  end
497
509
 
498
- specify "#open should return an opening tag" do
499
- @f.open(:action=>'foo', :method=>'post').to_s.should == '<form action="foo" method="post">'
510
+ it "#open should return an opening tag" do
511
+ @f.open(:action=>'foo', :method=>'post').to_s.must_equal '<form action="foo" method="post">'
500
512
  end
501
513
 
502
- specify "#close should return a closing tag" do
503
- @f.close.to_s.should == '</form>'
514
+ it "#close should return a closing tag" do
515
+ @f.close.to_s.must_equal '</form>'
504
516
  end
505
517
 
506
- specify "#button should return a submit tag" do
507
- @f.button.to_s.should == '<input type="submit"/>'
518
+ it "#button should return a submit tag" do
519
+ @f.button.to_s.must_equal '<input type="submit"/>'
508
520
  end
509
521
 
510
- specify "#button should accept an options hash" do
511
- @f.button(:name=>'foo', :value=>'bar').to_s.should == '<input name="foo" type="submit" value="bar"/>'
522
+ it "#button should accept an options hash" do
523
+ @f.button(:name=>'foo', :value=>'bar').to_s.must_equal '<input name="foo" type="submit" value="bar"/>'
512
524
  end
513
525
 
514
- specify "#button should accept a string to use as a value" do
515
- @f.button('foo').to_s.should == '<input type="submit" value="foo"/>'
526
+ it "#button should accept a string to use as a value" do
527
+ @f.button('foo').to_s.must_equal '<input type="submit" value="foo"/>'
516
528
  end
517
529
 
518
- specify "#tag should return a serialized_tag" do
519
- @f.tag(:textarea).to_s.should == '<textarea></textarea>'
520
- @f.tag(:textarea, :name=>:foo).to_s.should == '<textarea name="foo"></textarea>'
521
- @f.tag(:textarea, {:name=>:foo}, :bar).to_s.should == '<textarea name="foo">bar</textarea>'
530
+ it "#tag should return a serialized_tag" do
531
+ @f.tag(:textarea).to_s.must_equal '<textarea></textarea>'
532
+ @f.tag(:textarea, :name=>:foo).to_s.must_equal '<textarea name="foo"></textarea>'
533
+ @f.tag(:textarea, {:name=>:foo}, :bar).to_s.must_equal '<textarea name="foo">bar</textarea>'
522
534
  end
523
535
 
524
- specify "#tag should accept children as procs" do
525
- @f.tag(:div, {:class=>"foo"}, lambda{|t| t.form.tag(:input, :class=>t.attr[:class])}).to_s.should == '<div class="foo"><input class="foo"/></div>'
536
+ it "#tag should accept children as procs" do
537
+ @f.tag(:div, {:class=>"foo"}, lambda{|t| t.form.tag(:input, :class=>t.attr[:class])}).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
526
538
  end
527
539
 
528
- specify "#tag should accept children as methods" do
540
+ it "#tag should accept children as methods" do
529
541
  o = Object.new
530
542
  def o.foo(t) t.form.tag(:input, :class=>t.attr[:class]) end
531
- @f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.should == '<div class="foo"><input class="foo"/></div>'
543
+ @f.tag(:div, {:class=>"foo"}, o.method(:foo)).to_s.must_equal '<div class="foo"><input class="foo"/></div>'
532
544
  end
533
545
 
534
- specify "should have an #inputs method for multiple inputs wrapped in a fieldset" do
535
- @f.inputs([:textarea, :text]).to_s.should == '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
546
+ it "should have an #inputs method for multiple inputs wrapped in a fieldset" do
547
+ @f.inputs([:textarea, :text]).to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
536
548
  end
537
549
 
538
- specify "should have default #inputs method accept an :attr option" do
539
- @f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.should == '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
550
+ it "should have default #inputs method accept an :attr option" do
551
+ @f.inputs([:textarea, :text], :legend=>'Inputs', :attr=>{:class=>'foo', :bar=>'baz'}).to_s.must_equal '<fieldset bar="baz" class="foo inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
540
552
  end
541
553
 
542
- specify "should have default #inputs method accept a :legend option" do
543
- @f.inputs([:textarea, :text], :legend=>'Inputs').to_s.should == '<fieldset class="inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
554
+ it "should have default #inputs method accept a :legend option" do
555
+ @f.inputs([:textarea, :text], :legend=>'Inputs').to_s.must_equal '<fieldset class="inputs"><legend>Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
544
556
  end
545
557
 
546
- specify "should have default #inputs method accept a :legend_attr option" do
547
- @f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.should == '<fieldset class="inputs"><legend class="foo">Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
558
+ it "should have default #inputs method accept a :legend_attr option" do
559
+ @f.inputs([:textarea, :text], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<fieldset class="inputs"><legend class="foo">Inputs</legend><textarea></textarea><input type="text"/></fieldset>'
548
560
  end
549
561
 
550
- specify "should have an #inputs method take a block and yield to it" do
551
- @f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.should == '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
562
+ it "should have an #inputs method take a block and yield to it" do
563
+ @f.inputs{@f.input(:textarea); @f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
552
564
  end
553
565
 
554
- specify "should have an #inputs method work with both args and block" do
555
- @f.inputs([:textarea]){@f.input(:text)}.to_s.should == '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
566
+ it "should have an #inputs method work with both args and block" do
567
+ @f.inputs([:textarea]){@f.input(:text)}.to_s.must_equal '<fieldset class="inputs"><textarea></textarea><input type="text"/></fieldset>'
556
568
  end
557
569
 
558
- specify "should have an #inputs method support array arguments and creating inputs with the array as argument list" do
559
- @f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.should == '<fieldset class="inputs"><textarea name="foo"></textarea><input id="bar" type="text"/></fieldset>'
570
+ it "should have an #inputs method support array arguments and creating inputs with the array as argument list" do
571
+ @f.inputs([[:textarea, {:name=>'foo'}], [:text, {:id=>'bar'}]]).to_s.must_equal '<fieldset class="inputs"><textarea name="foo"></textarea><input id="bar" type="text"/></fieldset>'
560
572
  end
561
573
 
562
- specify "should have #inputs accept transformer options to modify the options inside the inputs" do
563
- @f.inputs([:textarea, :text], :wrapper=>:div).to_s.should == '<fieldset class="inputs"><div><textarea></textarea></div><div><input type="text"/></div></fieldset>'
574
+ it "should have #inputs accept transformer options to modify the options inside the inputs" do
575
+ @f.inputs([:textarea, :text], :wrapper=>:div).to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea></div><div><input type="text"/></div></fieldset>'
564
576
  end
565
577
 
566
- specify "should have #inputs accept :nested_inputs_wrapper options to modify the :input_wrapper option inside the inputs" do
567
- @f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.should == '<fieldset class="inputs"><div><textarea></textarea><input type="text"/></div></fieldset>'
578
+ it "should have #inputs accept :nested_inputs_wrapper options to modify the :input_wrapper option inside the inputs" do
579
+ @f.inputs(:nested_inputs_wrapper=>:div){@f.inputs([:textarea, :text])}.to_s.must_equal '<fieldset class="inputs"><div><textarea></textarea><input type="text"/></div></fieldset>'
568
580
  end
569
581
 
570
- specify "should escape tag content" do
571
- @f.tag(:div, {}, ['<p></p>']).to_s.should == '<div>&lt;p&gt;&lt;/p&gt;</div>'
582
+ it "should escape tag content" do
583
+ @f.tag(:div, {}, ['<p></p>']).to_s.must_equal '<div>&lt;p&gt;&lt;/p&gt;</div>'
572
584
  end
573
585
 
574
- specify "should not escape raw tag content using Forme::Raw" do
575
- @f.tag(:div, {}, ['<p></p>'.extend(Forme::Raw)]).to_s.should == '<div><p></p></div>'
586
+ it "should not escape raw tag content using Forme::Raw" do
587
+ @f.tag(:div, {}, ['<p></p>'.dup.extend(Forme::Raw)]).to_s.must_equal '<div><p></p></div>'
576
588
  end
577
589
 
578
- specify "should not escape raw tag content using Forme.raw" do
579
- @f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.should == '<div><p></p></div>'
590
+ it "should not escape raw tag content using Forme.raw" do
591
+ @f.tag(:div, {}, [Forme.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
580
592
  end
581
593
 
582
- specify "should not escape raw tag content using Form#raw" do
583
- @f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.should == '<div><p></p></div>'
594
+ it "should not escape raw tag content using Form#raw" do
595
+ @f.tag(:div, {}, [@f.raw('<p></p>')]).to_s.must_equal '<div><p></p></div>'
584
596
  end
585
597
 
586
- specify "should escape tag content in attribute values" do
587
- @f.tag(:div, :foo=>'<p></p>').to_s.should == '<div foo="&lt;p&gt;&lt;/p&gt;"></div>'
598
+ it "should escape tag content in attribute values" do
599
+ @f.tag(:div, :foo=>'<p></p>').to_s.must_equal '<div foo="&lt;p&gt;&lt;/p&gt;"></div>'
588
600
  end
589
601
 
590
- specify "should not escape raw tag content in attribute values" do
591
- @f.tag(:div, :foo=>'<p></p>'.extend(Forme::Raw)).to_s.should == '<div foo="<p></p>"></div>'
602
+ it "should not escape raw tag content in attribute values" do
603
+ @f.tag(:div, :foo=>Forme.raw('<p></p>')).to_s.must_equal '<div foo="<p></p>"></div>'
592
604
  end
593
605
 
594
- specify "should format dates, times, and datetimes in ISO format" do
595
- @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.should == '<div foo="2011-06-05"></div>'
596
- @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.should == '<div foo="2011-06-05T04:03:02.000000"></div>'
597
- @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.should =~ /<div foo="2011-06-05T04:03:02.000000"><\/div>/
606
+ it "should format dates, times, and datetimes in ISO format" do
607
+ @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
608
+ @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
609
+ @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_match /<div foo="2011-06-05T04:03:02.000000"><\/div>/
598
610
  end
599
611
 
600
- specify "should format bigdecimals in standard notation" do
601
- @f.tag(:div, :foo=>BigDecimal.new('10000.010')).to_s.should == '<div foo="10000.01"></div>'
612
+ it "should format bigdecimals in standard notation" do
613
+ @f.tag(:div, :foo=>BigDecimal.new('10000.010')).to_s.must_equal '<div foo="10000.01"></div>'
602
614
  end
603
615
 
604
- specify "inputs should accept a :wrapper option to use a custom wrapper" do
605
- @f.input(:text, :wrapper=>:li).to_s.should == '<li><input type="text"/></li>'
616
+ it "inputs should accept a :wrapper option to use a custom wrapper" do
617
+ @f.input(:text, :wrapper=>:li).to_s.must_equal '<li><input type="text"/></li>'
606
618
  end
607
619
 
608
- specify "inputs should accept a :wrapper_attr option to use custom wrapper attributes" do
609
- @f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.should == '<li class="foo"><input type="text"/></li>'
620
+ it "inputs should accept a :wrapper_attr option to use custom wrapper attributes" do
621
+ @f.input(:text, :wrapper=>:li, :wrapper_attr=>{:class=>"foo"}).to_s.must_equal '<li class="foo"><input type="text"/></li>'
610
622
  end
611
623
 
612
- specify "inputs should accept a :help option to use custom helper text" do
613
- @f.input(:text, :help=>"List type of foo").to_s.should == '<input type="text"/><span class="helper">List type of foo</span>'
624
+ it "inputs should accept a :help option to use custom helper text" do
625
+ @f.input(:text, :help=>"List type of foo").to_s.must_equal '<input type="text"/><span class="helper">List type of foo</span>'
614
626
  end
615
627
 
616
- specify "inputs should accept a :helper_attr option for custom helper attributes" do
617
- @f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.should == '<input type="text"/><span class="foo helper">List type of foo</span>'
628
+ it "inputs should accept a :helper_attr option for custom helper attributes" do
629
+ @f.input(:text, :help=>"List type of foo", :helper_attr=>{:class=>'foo'}).to_s.must_equal '<input type="text"/><span class="foo helper">List type of foo</span>'
618
630
  end
619
631
 
620
- specify "inputs should have helper displayed inside wrapper, after error" do
621
- @f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.should == '<li><input class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
632
+ it "inputs should have helper displayed inside wrapper, after error" do
633
+ @f.input(:text, :help=>"List type of foo", :error=>'bad', :wrapper=>:li).to_s.must_equal '<li><input class="error" type="text"/><span class="error_message">bad</span><span class="helper">List type of foo</span></li>'
622
634
  end
623
635
 
624
- specify "inputs should accept a :formatter option to use a custom formatter" do
625
- @f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.should == '<label>Foo: <span>1</span></label>'
626
- @f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.should == '<label>Foo: <input type="text" value="1"/></label>'
636
+ it "inputs should accept a :formatter option to use a custom formatter" do
637
+ @f.input(:text, :formatter=>:readonly, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <span>1</span></label>'
638
+ @f.input(:text, :formatter=>:default, :value=>'1', :label=>'Foo').to_s.must_equal '<label>Foo: <input type="text" value="1"/></label>'
627
639
  end
628
640
 
629
- specify "inputs should accept a :labeler option to use a custom labeler" do
630
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.should == '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
641
+ it "inputs should accept a :labeler option to use a custom labeler" do
642
+ @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
631
643
  end
632
644
 
633
- specify "inputs handle explicit labels with :label_position=>:after" do
634
- @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.should == '<textarea id="foo"></textarea><label class="label-after" for="foo">bar</label>'
645
+ it "inputs handle explicit labels with :label_position=>:after" do
646
+ @f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.must_equal '<textarea id="foo"></textarea><label class="label-after" for="foo">bar</label>'
635
647
  end
636
648
 
637
- specify "should handle explicit labels with checkboxes" do
638
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.should == '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label class="label-after" for="bar">Foo</label>'
649
+ it "should handle explicit labels with checkboxes" do
650
+ @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.must_equal '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label class="label-after" for="bar">Foo</label>'
639
651
  end
640
652
 
641
- specify "should handle explicit labels with checkboxes with :label_position=>:before" do
642
- @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.should == '<label class="label-before" for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
653
+ it "should handle explicit labels with checkboxes with :label_position=>:before" do
654
+ @f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.must_equal '<label class="label-before" for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
643
655
  end
644
656
 
645
- specify "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
646
- @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.should == '<label>Foo <input id="bar" name="a" type="checkbox" value="foo"/></label>'
657
+ it "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
658
+ @f.input(:checkbox, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before, :no_hidden=>true).to_s.must_equal '<label>Foo <input id="bar" name="a" type="checkbox" value="foo"/></label>'
647
659
  end
648
660
 
649
- specify "inputs should accept a :error_handler option to use a custom error_handler" do
650
- @f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.should == '<textarea class="error" id="foo"></textarea>!!! bar'
661
+ it "inputs should accept a :error_handler option to use a custom error_handler" do
662
+ @f.input(:textarea, :error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>!!! bar'
651
663
  end
652
664
 
653
- specify "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
654
- @f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.should == '<ol><textarea></textarea></ol>'
665
+ it "#inputs should accept a :inputs_wrapper option to use a custom inputs_wrapper" do
666
+ @f.inputs([:textarea], :inputs_wrapper=>:ol).to_s.must_equal '<ol><textarea></textarea></ol>'
655
667
  end
656
668
 
657
- specify "inputs should accept a :wrapper=>nil option to not use a wrapper" do
658
- Forme::Form.new(:wrapper=>:li).input(:text, :wrapper=>nil).to_s.should == '<input type="text"/>'
669
+ it "inputs should accept a :wrapper=>nil option to not use a wrapper" do
670
+ Forme::Form.new(:wrapper=>:li).input(:text, :wrapper=>nil).to_s.must_equal '<input type="text"/>'
659
671
  end
660
672
 
661
- specify "inputs should accept a :labeler=>nil option to not use a labeler" do
662
- @f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.should == '<textarea id="foo"></textarea>'
673
+ it "inputs should accept a :labeler=>nil option to not use a labeler" do
674
+ @f.input(:textarea, :labeler=>nil, :label=>'bar', :id=>:foo).to_s.must_equal '<textarea id="foo"></textarea>'
663
675
  end
664
676
 
665
- specify "inputs should accept a :error_handler=>nil option to not use an error_handler" do
666
- @f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.should == '<textarea class="error" id="foo"></textarea>'
677
+ it "inputs should accept a :error_handler=>nil option to not use an error_handler" do
678
+ @f.input(:textarea, :error_handler=>nil, :error=>'bar', :id=>:foo).to_s.must_equal '<textarea class="error" id="foo"></textarea>'
667
679
  end
668
680
 
669
- specify "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
670
- @f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.should == '<form><textarea></textarea></form>'
681
+ it "#inputs should accept a :inputs_wrapper=>nil option to not use an inputs_wrapper" do
682
+ @f.form{|f| f.inputs([:textarea], :inputs_wrapper=>nil)}.to_s.must_equal '<form><textarea></textarea></form>'
671
683
  end
672
684
 
673
- specify "#inputs should treat a single hash argument as an options hash with no default inputs" do
674
- @f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.should == '<ol><textarea></textarea></ol>'
685
+ it "#inputs should treat a single hash argument as an options hash with no default inputs" do
686
+ @f.inputs(:inputs_wrapper=>:ol){@f.input(:textarea)}.to_s.must_equal '<ol><textarea></textarea></ol>'
675
687
  end
676
688
 
677
- specify "should support setting defaults for inputs at the form level" do
689
+ it "should support setting defaults for inputs at the form level" do
678
690
  f = Forme::Form.new(:input_defaults=>{'text'=>{:size=>20}, 'textarea'=>{:cols=>80, :rows=>6}})
679
- f.input(:text, :name=>"foo").to_s.should == '<input name="foo" size="20" type="text"/>'
680
- f.input(:textarea, :name=>"foo").to_s.should == '<textarea cols="80" name="foo" rows="6"></textarea>'
691
+ f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
692
+ f.input(:textarea, :name=>"foo").to_s.must_equal '<textarea cols="80" name="foo" rows="6"></textarea>'
681
693
  end
682
694
 
683
- specify "should work with input_defaults with symbol keys using using inputs with symbol keys" do
695
+ it "should work with input_defaults with symbol keys using using inputs with symbol keys" do
684
696
  f = Forme::Form.new(:input_defaults=>{:text=>{:size=>20}, 'text'=>{:size=>30}})
685
- f.input(:text, :name=>"foo").to_s.should == '<input name="foo" size="20" type="text"/>'
686
- f.input('text', :name=>"foo").to_s.should == '<input name="foo" size="30" type="text"/>'
697
+ f.input(:text, :name=>"foo").to_s.must_equal '<input name="foo" size="20" type="text"/>'
698
+ f.input('text', :name=>"foo").to_s.must_equal '<input name="foo" size="30" type="text"/>'
687
699
  end
688
700
 
689
- specify "invalid custom transformers should raise an Error" do
690
- proc{Forme::Form.new(:wrapper=>Object.new).input(:text).to_s}.should raise_error(Forme::Error)
691
- proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.should raise_error(Forme::Error)
692
- proc{@f.input(:textarea, :formatter=>nil).to_s}.should raise_error(Forme::Error)
701
+ it "invalid custom transformers should raise an Error" do
702
+ proc{Forme::Form.new(:wrapper=>Object.new).input(:text).to_s}.must_raise(Forme::Error)
703
+ proc{@f.input(:textarea, :wrapper=>Object.new).to_s}.must_raise(Forme::Error)
704
+ proc{@f.input(:textarea, :formatter=>nil).to_s}.must_raise(Forme::Error)
693
705
  end
694
706
  end
695
707
 
@@ -698,251 +710,255 @@ describe "Forme::Form :hidden_tags option " do
698
710
  @f = Forme::Form.new
699
711
  end
700
712
 
701
- specify "should handle hash" do
702
- Forme.form({}, :hidden_tags=>[{:a=>'b'}]).to_s.should == '<form><input name="a" type="hidden" value="b"/></form>'
713
+ it "should handle hash" do
714
+ Forme.form({}, :hidden_tags=>[{:a=>'b'}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
703
715
  end
704
716
 
705
- specify "should handle array" do
706
- Forme.form({}, :hidden_tags=>[["a ", "b"]]).to_s.should == '<form>a b</form>'
717
+ it "should handle array" do
718
+ Forme.form({}, :hidden_tags=>[["a ", "b"]]).to_s.must_equal '<form>a b</form>'
707
719
  end
708
720
 
709
- specify "should handle string" do
710
- Forme.form({}, :hidden_tags=>["a "]).to_s.should == '<form>a </form>'
721
+ it "should handle string" do
722
+ Forme.form({}, :hidden_tags=>["a "]).to_s.must_equal '<form>a </form>'
711
723
  end
712
724
 
713
- specify "should handle proc return hash" do
714
- Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]).to_s.should == '<form><input name="a" type="hidden" value="b"/></form>'
725
+ it "should handle proc return hash" do
726
+ Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
715
727
  end
716
728
 
717
- specify "should handle proc return tag" do
718
- Forme.form({:method=>'post'}, :hidden_tags=>[lambda{|tag| tag.form._tag(tag.attr[:method])}]).to_s.should == '<form method="post"><post></post></form>'
729
+ it "should handle proc return tag" do
730
+ Forme.form({:method=>'post'}, :hidden_tags=>[lambda{|tag| tag.form._tag(tag.attr[:method])}]).to_s.must_equal '<form method="post"><post></post></form>'
719
731
  end
720
732
 
721
- specify "should raise error for unhandled object" do
722
- proc{Forme.form({}, :hidden_tags=>[Object.new])}.should raise_error
733
+ it "should raise error for unhandled object" do
734
+ proc{Forme.form({}, :hidden_tags=>[Object.new])}.must_raise Forme::Error
723
735
  end
724
736
  end
725
737
 
726
738
  describe "Forme custom" do
727
- specify "formatters can be specified as a proc" do
728
- Forme::Form.new(:formatter=>proc{|i| i.form._tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.should == '<textarea foo="name"></textarea>'
739
+ it "formatters can be specified as a proc" do
740
+ Forme::Form.new(:formatter=>proc{|i| i.form._tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.must_equal '<textarea foo="name"></textarea>'
729
741
  end
730
742
 
731
- specify "serializers can be specified as a proc" do
732
- Forme::Form.new(:serializer=>proc{|t| "#{t.type} = #{t.opts[:name]}"}).input(:textarea, :name=>'foo').to_s.should == 'textarea = foo'
743
+ it "serializers can be specified as a proc" do
744
+ Forme::Form.new(:serializer=>proc{|t| "#{t.type} = #{t.opts[:name]}"}).input(:textarea, :name=>'foo').to_s.must_equal 'textarea = foo'
733
745
  end
734
746
 
735
- specify "labelers can be specified as a proc" do
736
- Forme::Form.new(:labeler=>proc{|t, i| ["#{i.opts[:label]}: ", t]}).input(:textarea, :name=>'foo', :label=>'bar').to_s.should == 'bar: <textarea name="foo"></textarea>'
747
+ it "labelers can be specified as a proc" do
748
+ Forme::Form.new(:labeler=>proc{|t, i| ["#{i.opts[:label]}: ", t]}).input(:textarea, :name=>'foo', :label=>'bar').to_s.must_equal 'bar: <textarea name="foo"></textarea>'
737
749
  end
738
750
 
739
- specify "error_handlers can be specified as a proc" do
740
- Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.should == '<textarea class="error" name="foo"></textarea>!!! bar'
751
+ it "error_handlers can be specified as a proc" do
752
+ Forme::Form.new(:error_handler=>proc{|t, i| [t, "!!! #{i.opts[:error]}"]}).input(:textarea, :name=>'foo', :error=>'bar').to_s.must_equal '<textarea class="error" name="foo"></textarea>!!! bar'
741
753
  end
742
754
 
743
- specify "wrappers can be specified as a proc" do
744
- Forme::Form.new(:wrapper=>proc{|t, i| t.tag(:div, {:bar=>i.opts[:name]}, t)}).input(:textarea, :name=>'foo').to_s.should == '<div bar="foo"><textarea name="foo"></textarea></div>'
755
+ it "wrappers can be specified as a proc" do
756
+ Forme::Form.new(:wrapper=>proc{|t, i| t.tag(:div, {:bar=>i.opts[:name]}, t)}).input(:textarea, :name=>'foo').to_s.must_equal '<div bar="foo"><textarea name="foo"></textarea></div>'
745
757
  end
746
758
 
747
- specify "inputs_wrappers can be specified as a proc" do
748
- Forme::Form.new(:inputs_wrapper=>proc{|f, opts, &block| f.tag(:div, &block)}).inputs([:textarea]).to_s.should == '<div><textarea></textarea></div>'
759
+ it "inputs_wrappers can be specified as a proc" do
760
+ Forme::Form.new(:inputs_wrapper=>proc{|f, opts, &block| f.tag(:div, &block)}).inputs([:textarea]).to_s.must_equal '<div><textarea></textarea></div>'
749
761
  end
750
762
 
751
- specify "can use nil as value to disable default transformer" do
752
- Forme::Form.new(:labeler=>nil).input(:textarea, :label=>'foo').to_s.should == '<textarea></textarea>'
763
+ it "can use nil as value to disable default transformer" do
764
+ Forme::Form.new(:labeler=>nil).input(:textarea, :label=>'foo').to_s.must_equal '<textarea></textarea>'
753
765
  end
754
766
  end
755
767
 
756
768
  describe "Forme built-in custom" do
757
- specify "transformers should raise if the there is no matching transformer" do
758
- proc{Forme::Form.new(:formatter=>:foo).input(:text).to_s}.should raise_error(Forme::Error)
769
+ it "transformers should raise if the there is no matching transformer" do
770
+ proc{Forme::Form.new(:formatter=>:foo).input(:text).to_s}.must_raise(Forme::Error)
771
+ end
772
+
773
+ it "formatter: disabled disables all inputs unless :disabled=>false option" do
774
+ Forme::Form.new(:formatter=>:disabled).input(:textarea).to_s.must_equal '<textarea disabled="disabled"></textarea>'
775
+ Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.must_equal '<textarea></textarea>'
759
776
  end
760
777
 
761
- specify "formatter: disabled disables all inputs unless :disabled=>false option" do
762
- Forme::Form.new(:formatter=>:disabled).input(:textarea).to_s.should == '<textarea disabled="disabled"></textarea>'
763
- Forme::Form.new(:formatter=>:disabled).input(:textarea, :disabled=>false).to_s.should == '<textarea></textarea>'
778
+ it "formatter: readonly uses spans for most input fields and disables radio/checkbox fields" do
779
+ Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span>Bar</span></label>"
780
+ Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label>Foo: <span>Bar</span></label>"
781
+ Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
782
+ Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
783
+ Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "<label><input disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
784
+ Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "<label><input checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
785
+ Forme::Form.new(:formatter=>:readonly).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "<label>Foo: <span>2</span></label>"
764
786
  end
765
787
 
766
- specify "formatter: readonly uses spans for most input fields and disables radio/checkbox fields" do
767
- Forme::Form.new(:formatter=>:readonly).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.should == "<label>Foo: <span>Bar</span></label>"
768
- Forme::Form.new(:formatter=>:readonly).input(:text, :label=>"Foo", :value=>"Bar").to_s.should == "<label>Foo: <span>Bar</span></label>"
769
- Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar").to_s.should == "<label><input disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
770
- Forme::Form.new(:formatter=>:readonly).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "<label><input checked=\"checked\" disabled=\"disabled\" type=\"radio\" value=\"Bar\"/> Foo</label>"
771
- Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.should == "<label><input disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
772
- Forme::Form.new(:formatter=>:readonly).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "<label><input checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" value=\"Bar\"/> Foo</label>"
773
- Forme::Form.new(:formatter=>:readonly).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.should == "<label>Foo: <span>2</span></label>"
788
+ it "formatter: readonly should ignore submit buttons" do
789
+ Forme.form({}, :formatter=>:readonly, :button=>'a').to_s.must_equal '<form></form>'
774
790
  end
775
791
 
776
- specify "labeler: explicit uses an explicit label with for attribute" do
777
- Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
792
+ it "labeler: explicit uses an explicit label with for attribute" do
793
+ Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
778
794
  end
779
795
 
780
- specify "labeler: explicit handles the key option correctly" do
781
- Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
796
+ it "labeler: explicit handles the key option correctly" do
797
+ Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
782
798
  end
783
799
 
784
- specify "labeler: explicit should handle tags with errors" do
785
- Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
800
+ it "labeler: explicit should handle tags with errors" do
801
+ Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.must_equal '<label class="label-before" for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
786
802
  end
787
803
 
788
- specify "wrapper: li wraps tag in an li" do
789
- Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo').to_s.should == '<li><textarea id="foo"></textarea></li>'
790
- Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<li id="bar"><textarea id="foo"></textarea></li>'
804
+ it "wrapper: li wraps tag in an li" do
805
+ Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo').to_s.must_equal '<li><textarea id="foo"></textarea></li>'
806
+ Forme::Form.new(:wrapper=>:li).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<li id="bar"><textarea id="foo"></textarea></li>'
791
807
  end
792
808
 
793
- specify "wrapper: p wraps tag in an p" do
794
- Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo').to_s.should == '<p><textarea id="foo"></textarea></p>'
795
- Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<p id="bar"><textarea id="foo"></textarea></p>'
809
+ it "wrapper: p wraps tag in an p" do
810
+ Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo').to_s.must_equal '<p><textarea id="foo"></textarea></p>'
811
+ Forme::Form.new(:wrapper=>:p).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<p id="bar"><textarea id="foo"></textarea></p>'
796
812
  end
797
813
 
798
- specify "wrapper: div wraps tag in an div" do
799
- Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo').to_s.should == '<div><textarea id="foo"></textarea></div>'
800
- Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<div id="bar"><textarea id="foo"></textarea></div>'
814
+ it "wrapper: div wraps tag in an div" do
815
+ Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo').to_s.must_equal '<div><textarea id="foo"></textarea></div>'
816
+ Forme::Form.new(:wrapper=>:div).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<div id="bar"><textarea id="foo"></textarea></div>'
801
817
  end
802
818
 
803
- specify "wrapper: span wraps tag in an span" do
804
- Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo').to_s.should == '<span><textarea id="foo"></textarea></span>'
805
- Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<span id="bar"><textarea id="foo"></textarea></span>'
819
+ it "wrapper: span wraps tag in an span" do
820
+ Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo').to_s.must_equal '<span><textarea id="foo"></textarea></span>'
821
+ Forme::Form.new(:wrapper=>:span).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<span id="bar"><textarea id="foo"></textarea></span>'
806
822
  end
807
823
 
808
- specify "wrapper: td wraps tag in an td" do
809
- Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo').to_s.should == '<td><textarea id="foo"></textarea></td>'
810
- Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<td id="bar"><textarea id="foo"></textarea></td>'
824
+ it "wrapper: td wraps tag in an td" do
825
+ Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo').to_s.must_equal '<td><textarea id="foo"></textarea></td>'
826
+ Forme::Form.new(:wrapper=>:td).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<td id="bar"><textarea id="foo"></textarea></td>'
811
827
  end
812
828
 
813
- specify "wrapper: trtd wraps tag in an tr/td" do
814
- Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo').to_s.should == '<tr><td><textarea id="foo"></textarea></td><td></td></tr>'
815
- Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.should == '<tr id="bar"><td><textarea id="foo"></textarea></td><td></td></tr>'
829
+ it "wrapper: trtd wraps tag in an tr/td" do
830
+ Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo').to_s.must_equal '<tr><td><textarea id="foo"></textarea></td><td></td></tr>'
831
+ Forme::Form.new(:wrapper=>:trtd).input(:textarea, :id=>'foo', :wrapper_attr=>{:id=>'bar'}).to_s.must_equal '<tr id="bar"><td><textarea id="foo"></textarea></td><td></td></tr>'
816
832
  end
817
833
 
818
- specify "wrapper: trtd supports multiple tags in separate tds" do
819
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.should == '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
834
+ it "wrapper: trtd supports multiple tags in separate tds" do
835
+ Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
820
836
  end
821
837
 
822
- specify "wrapper: trtd should use at most 2 td tags" do
823
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.should == '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
838
+ it "wrapper: trtd should use at most 2 td tags" do
839
+ Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.must_equal '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
824
840
  end
825
841
 
826
- specify "wrapper: trtd should handle inputs with label after" do
827
- Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.should == '<tr><td><label class="label-after" for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
842
+ it "wrapper: trtd should handle inputs with label after" do
843
+ Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.must_equal '<tr><td><label class="label-after" for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
828
844
  end
829
845
 
830
- specify "wrapper: tr should use a td wrapper and tr inputs_wrapper" do
831
- Forme::Form.new(:wrapper=>:tr).inputs([:textarea]).to_s.should == '<tr><td><textarea></textarea></td></tr>'
846
+ it "wrapper: tr should use a td wrapper and tr inputs_wrapper" do
847
+ Forme::Form.new(:wrapper=>:tr).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
832
848
  f = Forme::Form.new
833
- f.with_opts(:wrapper=>:tr){f.inputs([:textarea])}.to_s.should == '<tr><td><textarea></textarea></td></tr>'
849
+ f.with_opts(:wrapper=>:tr){f.inputs([:textarea])}.to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
834
850
  end
835
851
 
836
- specify "wrapper: table should use a trtd wrapper and table inputs_wrapper" do
837
- Forme::Form.new(:wrapper=>:table).inputs([:textarea]).to_s.should == '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
852
+ it "wrapper: table should use a trtd wrapper and table inputs_wrapper" do
853
+ Forme::Form.new(:wrapper=>:table).inputs([:textarea]).to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
838
854
  f = Forme::Form.new
839
- f.with_opts(:wrapper=>:table){f.inputs([:textarea])}.to_s.should == '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
855
+ f.with_opts(:wrapper=>:table){f.inputs([:textarea])}.to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
840
856
  end
841
857
 
842
- specify "wrapper: ol should use an li wrapper and ol inputs_wrapper" do
843
- Forme::Form.new(:wrapper=>:ol).inputs([:textarea]).to_s.should == '<ol><li><textarea></textarea></li></ol>'
858
+ it "wrapper: ol should use an li wrapper and ol inputs_wrapper" do
859
+ Forme::Form.new(:wrapper=>:ol).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
844
860
  f = Forme::Form.new
845
- f.with_opts(:wrapper=>:ol){f.inputs([:textarea])}.to_s.should == '<ol><li><textarea></textarea></li></ol>'
861
+ f.with_opts(:wrapper=>:ol){f.inputs([:textarea])}.to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
846
862
  end
847
863
 
848
- specify "wrapper: fieldset_ol should use an li wrapper and fieldset_ol inputs_wrapper" do
849
- Forme::Form.new(:wrapper=>:fieldset_ol).inputs([:textarea]).to_s.should == '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
864
+ it "wrapper: fieldset_ol should use an li wrapper and fieldset_ol inputs_wrapper" do
865
+ Forme::Form.new(:wrapper=>:fieldset_ol).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
850
866
  f = Forme::Form.new
851
- f.with_opts(:wrapper=>:fieldset_ol){f.inputs([:textarea])}.to_s.should == '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
867
+ f.with_opts(:wrapper=>:fieldset_ol){f.inputs([:textarea])}.to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
852
868
  end
853
869
 
854
- specify "wrapper should not override inputs_wrapper if both given" do
855
- Forme::Form.new(:wrapper=>:tr, :inputs_wrapper=>:div).inputs([:textarea]).to_s.should == '<div><td><textarea></textarea></td></div>'
870
+ it "wrapper should not override inputs_wrapper if both given" do
871
+ Forme::Form.new(:wrapper=>:tr, :inputs_wrapper=>:div).inputs([:textarea]).to_s.must_equal '<div><td><textarea></textarea></td></div>'
856
872
  f = Forme::Form.new
857
- f.with_opts(:wrapper=>:tr, :inputs_wrapper=>:div){f.inputs([:textarea])}.to_s.should == '<div><td><textarea></textarea></td></div>'
873
+ f.with_opts(:wrapper=>:tr, :inputs_wrapper=>:div){f.inputs([:textarea])}.to_s.must_equal '<div><td><textarea></textarea></td></div>'
858
874
  end
859
875
 
860
- specify "inputs_wrapper: ol wraps tags in an ol" do
861
- Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea]).to_s.should == '<ol><li><textarea></textarea></li></ol>'
862
- Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.should == '<ol foo="1"><li><textarea></textarea></li></ol>'
876
+ it "inputs_wrapper: ol wraps tags in an ol" do
877
+ Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<ol><li><textarea></textarea></li></ol>'
878
+ Forme::Form.new(:inputs_wrapper=>:ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<ol foo="1"><li><textarea></textarea></li></ol>'
863
879
  end
864
880
 
865
- specify "inputs_wrapper: fieldset_ol wraps tags in a fieldset and an ol" do
866
- Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea]).to_s.should == '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
867
- Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.should == '<fieldset class="inputs" foo="1"><ol><li><textarea></textarea></li></ol></fieldset>'
881
+ it "inputs_wrapper: fieldset_ol wraps tags in a fieldset and an ol" do
882
+ Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea]).to_s.must_equal '<fieldset class="inputs"><ol><li><textarea></textarea></li></ol></fieldset>'
883
+ Forme::Form.new(:inputs_wrapper=>:fieldset_ol, :wrapper=>:li).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<fieldset class="inputs" foo="1"><ol><li><textarea></textarea></li></ol></fieldset>'
868
884
  end
869
885
 
870
- specify "inputs_wrapper: fieldset_ol supports a :legend option" do
871
- Forme.form({}, :inputs_wrapper=>:fieldset_ol, :wrapper=>:li, :legend=>'Foo', :inputs=>[:textarea]).to_s.should == '<form><fieldset class="inputs"><legend>Foo</legend><ol><li><textarea></textarea></li></ol></fieldset></form>'
886
+ it "inputs_wrapper: fieldset_ol supports a :legend option" do
887
+ Forme.form({}, :inputs_wrapper=>:fieldset_ol, :wrapper=>:li, :legend=>'Foo', :inputs=>[:textarea]).to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><ol><li><textarea></textarea></li></ol></fieldset></form>'
872
888
  end
873
889
 
874
- specify "inputs_wrapper: div wraps tags in a div" do
875
- Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea]).to_s.should == '<div><span><textarea></textarea></span></div>'
876
- Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea], :attr=>{:foo=>1}).to_s.should == '<div foo="1"><span><textarea></textarea></span></div>'
890
+ it "inputs_wrapper: div wraps tags in a div" do
891
+ Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea]).to_s.must_equal '<div><span><textarea></textarea></span></div>'
892
+ Forme::Form.new(:inputs_wrapper=>:div, :wrapper=>:span).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<div foo="1"><span><textarea></textarea></span></div>'
877
893
  end
878
894
 
879
- specify "inputs_wrapper: tr wraps tags in an tr" do
880
- Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea]).to_s.should == '<tr><td><textarea></textarea></td></tr>'
881
- Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea], :attr=>{:foo=>1}).to_s.should == '<tr foo="1"><td><textarea></textarea></td></tr>'
895
+ it "inputs_wrapper: tr wraps tags in an tr" do
896
+ Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea]).to_s.must_equal '<tr><td><textarea></textarea></td></tr>'
897
+ Forme::Form.new(:inputs_wrapper=>:tr, :wrapper=>:td).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<tr foo="1"><td><textarea></textarea></td></tr>'
882
898
  end
883
899
 
884
- specify "inputs_wrapper: table wraps tags in an table" do
885
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea]).to_s.should == '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
886
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :attr=>{:foo=>1}).to_s.should == '<table foo="1"><tr><td><textarea></textarea></td><td></td></tr></table>'
900
+ it "inputs_wrapper: table wraps tags in an table" do
901
+ Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea]).to_s.must_equal '<table><tr><td><textarea></textarea></td><td></td></tr></table>'
902
+ Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :attr=>{:foo=>1}).to_s.must_equal '<table foo="1"><tr><td><textarea></textarea></td><td></td></tr></table>'
887
903
  end
888
904
 
889
- specify "inputs_wrapper: table accepts a :legend option" do
890
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs').to_s.should == '<table><caption>Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
905
+ it "inputs_wrapper: table accepts a :legend option" do
906
+ Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs').to_s.must_equal '<table><caption>Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
891
907
  end
892
908
 
893
- specify "inputs_wrapper: table accepts a :legend_attr option" do
894
- Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.should == '<table><caption class="foo">Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
909
+ it "inputs_wrapper: table accepts a :legend_attr option" do
910
+ Forme::Form.new(:inputs_wrapper=>:table, :wrapper=>:trtd).inputs([:textarea], :legend=>'Inputs', :legend_attr=>{:class=>'foo'}).to_s.must_equal '<table><caption class="foo">Inputs</caption><tr><td><textarea></textarea></td><td></td></tr></table>'
895
911
  end
896
912
 
897
- specify "inputs_wrapper: table accepts a :labels option" do
898
- Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.should == '<table><tr><th>A</th><th>B</th><th>C</th></tr></table>'
913
+ it "inputs_wrapper: table accepts a :labels option" do
914
+ Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>%w'A B C').to_s.must_equal '<table><tr><th>A</th><th>B</th><th>C</th></tr></table>'
899
915
  end
900
916
 
901
- specify "inputs_wrapper: table doesn't add empty header row for :labels=>[]" do
902
- Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>[]).to_s.should == '<table></table>'
917
+ it "inputs_wrapper: table doesn't add empty header row for :labels=>[]" do
918
+ Forme::Form.new(:inputs_wrapper=>:table).inputs(:labels=>[]).to_s.must_equal '<table></table>'
903
919
  end
904
920
 
905
- specify "serializer: html_usa formats dates and datetimes in American format without timezones" do
906
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.should == '<div foo="06/05/2011"></div>'
907
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.should == '<div foo="06/05/2011 04:03:02PM"></div>'
908
- Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.should == '<div foo="06/05/2011 04:03:02AM"></div>'
921
+ it "serializer: html_usa formats dates and datetimes in American format without timezones" do
922
+ Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="06/05/2011"></div>'
923
+ Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02PM"></div>'
924
+ Forme::Form.new(:serializer=>:html_usa).tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="06/05/2011 04:03:02AM"></div>'
909
925
  end
910
926
 
911
- specify "serializer: html_usa should convert date and datetime inputs into text inputs" do
912
- Forme::Form.new(:serializer=>:html_usa).input(:date, :value=>Date.new(2011, 6, 5)).to_s.should == '<input type="text" value="06/05/2011"/>'
913
- Forme::Form.new(:serializer=>:html_usa).input(:datetime, :value=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.should == '<input type="text" value="06/05/2011 04:03:02PM"/>'
927
+ it "serializer: html_usa should convert date and datetime inputs into text inputs" do
928
+ Forme::Form.new(:serializer=>:html_usa).input(:date, :value=>Date.new(2011, 6, 5)).to_s.must_equal '<input type="text" value="06/05/2011"/>'
929
+ Forme::Form.new(:serializer=>:html_usa).input(:datetime, :value=>DateTime.new(2011, 6, 5, 16, 3, 2)).to_s.must_equal '<input type="text" value="06/05/2011 04:03:02PM"/>'
914
930
  end
915
931
 
916
- specify "serializer: text uses plain text output instead of html" do
917
- Forme::Form.new(:serializer=>:text).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.should == "Foo: Bar\n\n"
918
- Forme::Form.new(:serializer=>:text).input(:text, :label=>"Foo", :value=>"Bar").to_s.should == "Foo: Bar\n\n"
919
- Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar").to_s.should == "___ Foo\n"
920
- Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "_X_ Foo\n"
921
- Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.should == "___ Foo\n"
922
- Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.should == "_X_ Foo\n"
923
- Forme::Form.new(:serializer=>:text).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.should == "Foo: \n___ 1\n_X_ 2\n___ 3\n\n"
924
- Forme::Form.new(:serializer=>:text).input(:password, :label=>"Pass").to_s.should == "Pass: ********\n\n"
925
- Forme::Form.new(:serializer=>:text).button().to_s.should == ""
926
- Forme::Form.new(:serializer=>:text).inputs([[:textarea, {:label=>"Foo", :value=>"Bar"}]], :legend=>'Baz').to_s.should == "Baz\n---\nFoo: Bar\n\n"
927
- Forme::Form.new(:serializer=>:text).tag(:p){|f| f.input(:textarea, :label=>"Foo", :value=>"Bar")}.to_s.should == "Foo: Bar\n\n"
932
+ it "serializer: text uses plain text output instead of html" do
933
+ Forme::Form.new(:serializer=>:text).input(:textarea, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
934
+ Forme::Form.new(:serializer=>:text).input(:text, :label=>"Foo", :value=>"Bar").to_s.must_equal "Foo: Bar\n\n"
935
+ Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
936
+ Forme::Form.new(:serializer=>:text).input(:radio, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
937
+ Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar").to_s.must_equal "___ Foo\n"
938
+ Forme::Form.new(:serializer=>:text).input(:checkbox, :label=>"Foo", :value=>"Bar", :checked=>true).to_s.must_equal "_X_ Foo\n"
939
+ Forme::Form.new(:serializer=>:text).input(:select, :label=>"Foo", :options=>[1, 2, 3], :value=>2).to_s.must_equal "Foo: \n___ 1\n_X_ 2\n___ 3\n\n"
940
+ Forme::Form.new(:serializer=>:text).input(:password, :label=>"Pass").to_s.must_equal "Pass: ********\n\n"
941
+ Forme::Form.new(:serializer=>:text).button().to_s.must_equal ""
942
+ Forme::Form.new(:serializer=>:text).inputs([[:textarea, {:label=>"Foo", :value=>"Bar"}]], :legend=>'Baz').to_s.must_equal "Baz\n---\nFoo: Bar\n\n"
943
+ Forme::Form.new(:serializer=>:text).tag(:p){|f| f.input(:textarea, :label=>"Foo", :value=>"Bar")}.to_s.must_equal "Foo: Bar\n\n"
928
944
  end
929
945
  end
930
946
 
931
947
  describe "Forme registering custom transformers" do
932
- specify "should have #register_transformer register a transformer object for later use" do
948
+ it "should have #register_transformer register a transformer object for later use" do
933
949
  Forme.register_transformer(:wrapper, :div2, proc{|t, i| i.tag(:div2, {}, [t])})
934
- Forme::Form.new(:wrapper=>:div2).input(:textarea).to_s.should == '<div2><textarea></textarea></div2>'
950
+ Forme::Form.new(:wrapper=>:div2).input(:textarea).to_s.must_equal '<div2><textarea></textarea></div2>'
935
951
  end
936
952
 
937
- specify "should have #register_transformer register a transformer block for later use" do
953
+ it "should have #register_transformer register a transformer block for later use" do
938
954
  Forme.register_transformer(:wrapper, :div1){|t, i| i.tag(:div1, {}, [t])}
939
- Forme::Form.new(:wrapper=>:div1).input(:textarea).to_s.should == '<div1><textarea></textarea></div1>'
955
+ Forme::Form.new(:wrapper=>:div1).input(:textarea).to_s.must_equal '<div1><textarea></textarea></div1>'
940
956
  end
941
957
 
942
- specify "should have #register_transformer raise an error if given a block and an object" do
958
+ it "should have #register_transformer raise an error if given a block and an object" do
943
959
  proc do
944
960
  Forme.register_transformer(:wrapper, :div1, proc{|t, i| t}){|t, i| i.tag(:div1, {}, [t])}
945
- end.should raise_error(Forme::Error)
961
+ end.must_raise(Forme::Error)
946
962
  end
947
963
  end
948
964
 
@@ -951,34 +967,34 @@ describe "Forme configurations" do
951
967
  Forme.default_config = :default
952
968
  end
953
969
 
954
- specify "config: :formastic uses fieldset_ol inputs_wrapper and li wrapper, and explicit labeler" do
955
- Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
970
+ it "config: :formastic uses fieldset_ol inputs_wrapper and li wrapper, and explicit labeler" do
971
+ Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
956
972
  end
957
973
 
958
- specify "should be able to set a default configuration with Forme.default_config=" do
974
+ it "should be able to set a default configuration with Forme.default_config=" do
959
975
  Forme.default_config = :formtastic
960
- Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
976
+ Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
961
977
  end
962
978
 
963
- specify "should have #register_config register a configuration for later use" do
979
+ it "should have #register_config register a configuration for later use" do
964
980
  Forme.register_config(:foo, :wrapper=>:li, :labeler=>:explicit)
965
- Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.should == '<li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li>'
981
+ Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.must_equal '<li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li>'
966
982
  end
967
983
 
968
- specify "should have #register_config support a :base option to base it on an existing config" do
984
+ it "should have #register_config support a :base option to base it on an existing config" do
969
985
  Forme.register_config(:foo2, :labeler=>:default, :base=>:formtastic)
970
- Forme::Form.new(:config=>:foo2).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label>Foo: <textarea id="foo"></textarea></label></li></ol></fieldset>'
986
+ Forme::Form.new(:config=>:foo2).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.must_equal '<fieldset class="inputs"><ol><li><label>Foo: <textarea id="foo"></textarea></label></li></ol></fieldset>'
971
987
  end
972
988
 
973
989
  end
974
990
 
975
991
  describe "Forme object forms" do
976
- specify "should handle a simple case" do
992
+ it "should handle a simple case" do
977
993
  obj = Class.new{def forme_input(form, field, opts) form._input(:text, :name=>"obj[#{field}]", :id=>"obj_#{field}", :value=>"#{field}_foo") end}.new
978
- Forme::Form.new(obj).input(:field).to_s.should == '<input id="obj_field" name="obj[field]" type="text" value="field_foo"/>'
994
+ Forme::Form.new(obj).input(:field).to_s.must_equal '<input id="obj_field" name="obj[field]" type="text" value="field_foo"/>'
979
995
  end
980
996
 
981
- specify "should handle more complex case with multiple different types and opts" do
997
+ it "should handle more complex case with multiple different types and opts" do
982
998
  obj = Class.new do
983
999
  def self.name() "Foo" end
984
1000
 
@@ -995,93 +1011,93 @@ describe "Forme object forms" do
995
1011
  end
996
1012
  end.new('&foo', 3)
997
1013
  f = Forme::Form.new(obj)
998
- f.input(:x).to_s.should == '<label>X: <textarea id="foo_x" name="foo[x]">&amp;foo</textarea></label>'
999
- f.input(:y, :attr=>{:brain=>'no'}).to_s.should == '<label>Y: <input brain="no" id="foo_y" name="foo[y]" type="text" value="3"/></label>'
1014
+ f.input(:x).to_s.must_equal '<label>X: <textarea id="foo_x" name="foo[x]">&amp;foo</textarea></label>'
1015
+ f.input(:y, :attr=>{:brain=>'no'}).to_s.must_equal '<label>Y: <input brain="no" id="foo_y" name="foo[y]" type="text" value="3"/></label>'
1000
1016
  end
1001
1017
 
1002
- specify "should handle case where obj doesn't respond to forme_input" do
1003
- Forme::Form.new([:foo]).input(:first).to_s.should == '<input id="first" name="first" type="text" value="foo"/>'
1018
+ it "should handle case where obj doesn't respond to forme_input" do
1019
+ Forme::Form.new([:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
1004
1020
  obj = Class.new{attr_accessor :foo}.new
1005
1021
  obj.foo = 'bar'
1006
- Forme::Form.new(obj).input(:foo).to_s.should == '<input id="foo" name="foo" type="text" value="bar"/>'
1022
+ Forme::Form.new(obj).input(:foo).to_s.must_equal '<input id="foo" name="foo" type="text" value="bar"/>'
1007
1023
  end
1008
1024
 
1009
- specify "should respect opts hash when obj doesn't respond to forme_input" do
1010
- Forme::Form.new([:foo]).input(:first, :name=>'bar').to_s.should == '<input id="first" name="bar" type="text" value="foo"/>'
1011
- Forme::Form.new([:foo]).input(:first, :id=>'bar').to_s.should == '<input id="bar" name="first" type="text" value="foo"/>'
1012
- Forme::Form.new([:foo]).input(:first, :value=>'bar').to_s.should == '<input id="first" name="first" type="text" value="bar"/>'
1013
- Forme::Form.new([:foo]).input(:first, :attr=>{:x=>'bar'}).to_s.should == '<input id="first" name="first" type="text" value="foo" x="bar"/>'
1025
+ it "should respect opts hash when obj doesn't respond to forme_input" do
1026
+ Forme::Form.new([:foo]).input(:first, :name=>'bar').to_s.must_equal '<input id="first" name="bar" type="text" value="foo"/>'
1027
+ Forme::Form.new([:foo]).input(:first, :id=>'bar').to_s.must_equal '<input id="bar" name="first" type="text" value="foo"/>'
1028
+ Forme::Form.new([:foo]).input(:first, :value=>'bar').to_s.must_equal '<input id="first" name="first" type="text" value="bar"/>'
1029
+ Forme::Form.new([:foo]).input(:first, :attr=>{:x=>'bar'}).to_s.must_equal '<input id="first" name="first" type="text" value="foo" x="bar"/>'
1014
1030
  end
1015
1031
 
1016
- specify "should respect current namespace" do
1017
- Forme::Form.new([:foo], :namespace=>'a').input(:first).to_s.should == '<input id="a_first" name="a[first]" type="text" value="foo"/>'
1032
+ it "should respect current namespace" do
1033
+ Forme::Form.new([:foo], :namespace=>'a').input(:first).to_s.must_equal '<input id="a_first" name="a[first]" type="text" value="foo"/>'
1018
1034
  end
1019
1035
 
1020
- specify "should get values for hashes using #[]" do
1021
- Forme::Form.new(:obj=>{:bar=>:foo}, :namespace=>'a').input(:bar).to_s.should == '<input id="a_bar" name="a[bar]" type="text" value="foo"/>'
1036
+ it "should get values for hashes using #[]" do
1037
+ Forme::Form.new(:obj=>{:bar=>:foo}, :namespace=>'a').input(:bar).to_s.must_equal '<input id="a_bar" name="a[bar]" type="text" value="foo"/>'
1022
1038
  end
1023
1039
 
1024
- specify "should handle obj passed in via :obj hash key" do
1025
- Forme::Form.new(:obj=>[:foo]).input(:first).to_s.should == '<input id="first" name="first" type="text" value="foo"/>'
1040
+ it "should handle obj passed in via :obj hash key" do
1041
+ Forme::Form.new(:obj=>[:foo]).input(:first).to_s.must_equal '<input id="first" name="first" type="text" value="foo"/>'
1026
1042
  end
1027
1043
 
1028
- specify "should be able to turn off obj handling per input using :obj=>nil option" do
1029
- Forme::Form.new([:foo]).input(:checkbox, :name=>"foo", :hidden_value=>"no", :obj=>nil).to_s.should == '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
1044
+ it "should be able to turn off obj handling per input using :obj=>nil option" do
1045
+ Forme::Form.new([:foo]).input(:checkbox, :name=>"foo", :hidden_value=>"no", :obj=>nil).to_s.must_equal '<input name="foo" type="hidden" value="no"/><input name="foo" type="checkbox"/>'
1030
1046
  end
1031
1047
  end
1032
1048
 
1033
1049
  describe "Forme.form DSL" do
1034
- specify "should return a form tag" do
1035
- Forme.form.to_s.should == '<form></form>'
1050
+ it "should return a form tag" do
1051
+ Forme.form.to_s.must_equal '<form></form>'
1036
1052
  end
1037
1053
 
1038
- specify "should yield a Form object to the block" do
1039
- Forme.form{|f| f.should be_a_kind_of(Forme::Form)}
1054
+ it "should yield a Form object to the block" do
1055
+ Forme.form{|f| f.must_be_kind_of(Forme::Form)}
1040
1056
  end
1041
1057
 
1042
- specify "should respect an array of classes" do
1043
- Forme.form(:class=>[:foo, :bar]).to_s.should == '<form class="foo bar"></form>'
1044
- Forme.form(:class=>[:foo, [:bar, :baz]]).to_s.should == '<form class="foo bar baz"></form>'
1058
+ it "should respect an array of classes" do
1059
+ Forme.form(:class=>[:foo, :bar]).to_s.must_equal '<form class="foo bar"></form>'
1060
+ Forme.form(:class=>[:foo, [:bar, :baz]]).to_s.must_equal '<form class="foo bar baz"></form>'
1045
1061
  end
1046
1062
 
1047
- specify "should have inputs called instead the block be added to the existing form" do
1048
- Forme.form{|f| f.input(:text)}.to_s.should == '<form><input type="text"/></form>'
1063
+ it "should have inputs called instead the block be added to the existing form" do
1064
+ Forme.form{|f| f.input(:text)}.to_s.must_equal '<form><input type="text"/></form>'
1049
1065
  end
1050
1066
 
1051
- specify "should be able to nest inputs inside tags" do
1052
- Forme.form{|f| f.tag(:div){f.input(:text)}}.to_s.should == '<form><div><input type="text"/></div></form>'
1053
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text)}}}.to_s.should == '<form><div><fieldset><input type="text"/></fieldset></div></form>'
1054
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.tag(:span){f.input(:text)}}}}.to_s.should == '<form><div><fieldset><span><input type="text"/></span></fieldset></div></form>'
1055
- Forme.form{|f| f.tag(:div){f.input(:text)}; f.input(:radio)}.to_s.should == '<form><div><input type="text"/></div><input type="radio"/></form>'
1056
- Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text); f.input(:radio)}; f.input(:checkbox)}}.to_s.should == '<form><div><fieldset><input type="text"/><input type="radio"/></fieldset><input type="checkbox"/></div></form>'
1067
+ it "should be able to nest inputs inside tags" do
1068
+ Forme.form{|f| f.tag(:div){f.input(:text)}}.to_s.must_equal '<form><div><input type="text"/></div></form>'
1069
+ Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text)}}}.to_s.must_equal '<form><div><fieldset><input type="text"/></fieldset></div></form>'
1070
+ Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.tag(:span){f.input(:text)}}}}.to_s.must_equal '<form><div><fieldset><span><input type="text"/></span></fieldset></div></form>'
1071
+ Forme.form{|f| f.tag(:div){f.input(:text)}; f.input(:radio)}.to_s.must_equal '<form><div><input type="text"/></div><input type="radio"/></form>'
1072
+ Forme.form{|f| f.tag(:div){f.tag(:fieldset){f.input(:text); f.input(:radio)}; f.input(:checkbox)}}.to_s.must_equal '<form><div><fieldset><input type="text"/><input type="radio"/></fieldset><input type="checkbox"/></div></form>'
1057
1073
  end
1058
1074
 
1059
- specify "should handle an :inputs option to automatically create inputs" do
1060
- Forme.form({}, :inputs=>[:text, :textarea]).to_s.should == '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset></form>'
1075
+ it "should handle an :inputs option to automatically create inputs" do
1076
+ Forme.form({}, :inputs=>[:text, :textarea]).to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset></form>'
1061
1077
  end
1062
1078
 
1063
- specify "should handle a :legend option if inputs is used" do
1064
- Forme.form({}, :inputs=>[:text, :textarea], :legend=>'Foo').to_s.should == '<form><fieldset class="inputs"><legend>Foo</legend><input type="text"/><textarea></textarea></fieldset></form>'
1079
+ it "should handle a :legend option if inputs is used" do
1080
+ Forme.form({}, :inputs=>[:text, :textarea], :legend=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><legend>Foo</legend><input type="text"/><textarea></textarea></fieldset></form>'
1065
1081
  end
1066
1082
 
1067
- specify "should still work with a block if :inputs is used" do
1068
- Forme.form({}, :inputs=>[:text]){|f| f.input(:textarea)}.to_s.should == '<form><fieldset class="inputs"><input type="text"/></fieldset><textarea></textarea></form>'
1083
+ it "should still work with a block if :inputs is used" do
1084
+ Forme.form({}, :inputs=>[:text]){|f| f.input(:textarea)}.to_s.must_equal '<form><fieldset class="inputs"><input type="text"/></fieldset><textarea></textarea></form>'
1069
1085
  end
1070
1086
 
1071
- specify "should handle an :button option to automatically create a button" do
1072
- Forme.form({}, :button=>'Foo').to_s.should == '<form><input type="submit" value="Foo"/></form>'
1087
+ it "should handle an :button option to automatically create a button" do
1088
+ Forme.form({}, :button=>'Foo').to_s.must_equal '<form><input type="submit" value="Foo"/></form>'
1073
1089
  end
1074
1090
 
1075
- specify "should allow :button option value to be a hash" do
1076
- Forme.form({}, :button=>{:value=>'Foo', :name=>'bar'}).to_s.should == '<form><input name="bar" type="submit" value="Foo"/></form>'
1091
+ it "should allow :button option value to be a hash" do
1092
+ Forme.form({}, :button=>{:value=>'Foo', :name=>'bar'}).to_s.must_equal '<form><input name="bar" type="submit" value="Foo"/></form>'
1077
1093
  end
1078
1094
 
1079
- specify "should handle an :button option work with a block" do
1080
- Forme.form({}, :button=>'Foo'){|f| f.input(:textarea)}.to_s.should == '<form><textarea></textarea><input type="submit" value="Foo"/></form>'
1095
+ it "should handle an :button option work with a block" do
1096
+ Forme.form({}, :button=>'Foo'){|f| f.input(:textarea)}.to_s.must_equal '<form><textarea></textarea><input type="submit" value="Foo"/></form>'
1081
1097
  end
1082
1098
 
1083
- specify "should have an :button and :inputs option work together" do
1084
- Forme.form({}, :inputs=>[:text, :textarea], :button=>'Foo').to_s.should == '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset><input type="submit" value="Foo"/></form>'
1099
+ it "should have an :button and :inputs option work together" do
1100
+ Forme.form({}, :inputs=>[:text, :textarea], :button=>'Foo').to_s.must_equal '<form><fieldset class="inputs"><input type="text"/><textarea></textarea></fieldset><input type="submit" value="Foo"/></form>'
1085
1101
  end
1086
1102
 
1087
1103
  end