Permalink
Browse files

Capture returns from formtastic and append them to the output_buffer …

…if running with rails3

This is an ugly hack that hopefully goes away once rspec 2.0 supports testing viewhelpers
  • Loading branch information...
1 parent aefd9c8 commit d7a729d0b1a19ff42563ddc5d0372897963b49f6 @mjonuschat mjonuschat committed Apr 13, 2010
View
@@ -13,26 +13,31 @@
describe 'with a block' do
describe 'when no options are provided' do
before do
- semantic_form_for(@new_post) do |builder|
- builder.buttons do
+ @form = semantic_form_for(@new_post) do |builder|
+ buttons = builder.buttons do
concat('hello')
end
+ concat(buttons)
end
end
it 'should render a fieldset inside the form, with a class of "inputs"' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons")
end
it 'should render an ol inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons ol")
end
it 'should render the contents of the block inside the ol' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset.buttons ol", /hello/)
end
it 'should not render a legend inside the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag("form fieldset.buttons legend")
end
end
@@ -41,12 +46,13 @@
before do
@legend_text = "Advanced options"
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
builder.buttons :name => @legend_text do
end
end
end
it 'should render a fieldset inside the form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
end
end
@@ -56,12 +62,13 @@
@id_option = 'advanced'
@class_option = 'wide'
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
builder.buttons :id => @id_option, :class => @class_option do
end
end
end
it 'should pass the options into the fieldset tag as attributes' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag("form fieldset##{@id_option}")
output_buffer.should have_tag("form fieldset.#{@class_option}")
end
@@ -74,32 +81,38 @@
describe 'with no args (default buttons)' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons)
end
end
it 'should render a form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form')
end
it 'should render a buttons fieldset inside the form' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons')
end
it 'should not render a legend in the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should_not have_tag('form fieldset.buttons legend')
end
it 'should render an ol in the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol')
end
it 'should render a list item in the ol for each default button' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol li', :count => 1)
end
it 'should render a commit list item for the commit button' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form fieldset.buttons ol li.commit')
end
@@ -108,12 +121,13 @@
describe 'with button names as args' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit))
end
end
it 'should render a form with a fieldset containing a list item for each button arg' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit')
end
@@ -123,21 +137,24 @@
describe 'with button names as args and an options hash' do
before do
- semantic_form_for(@new_post) do |builder|
+ @form = semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit, :name => "Now click a button", :id => "my-id"))
end
end
it 'should render a form with a fieldset containing a list item for each button arg' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset.buttons > ol > li', :count => 1)
output_buffer.should have_tag('form > fieldset.buttons > ol > li.commit', :count => 1)
end
it 'should pass the options down to the fieldset' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset#my-id.buttons')
end
it 'should use the special :name option as a text for the legend tag' do
+ output_buffer.concat(@form) if defined?(ActiveSupport::SafeBuffer)
output_buffer.should have_tag('form > fieldset#my-id.buttons > legend', /Now click a button/)
end
Oops, something went wrong.

0 comments on commit d7a729d

Please sign in to comment.